ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF Viewer - loading from a stream

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
mountaincoder Posted - Mar 18 2022 : 18:02:45
I am trying to get a PDF from the web and display it without having to save it to the local disk as a temp file.

This code works, getting the stream, saving it to a file and then loading the file:

Stream := TMemoryStream.Create;
try
  GetInternetToStream(AURL, '', '', nil, Stream);
  Stream.SaveToFile('temp.pdf');
  pdfView.IO.LoadFromFile('temp.pdf');
finally
  Stream.Free;
end;


My ultimate goal is to use a MemoryStream, but that wasn't working so I tried saving the stream to a file so that I could use your example code. But still this code errors on .ImportPages with EPDFException 'PDF document is not open'.

GetInternetToFile(AURL, 'temp.pdf', False);
fs := TFileStream.Create('temp.pdf', fmOpenRead);
try
  fs.Seek(0, soEnd);
  fs.Position := 0;
  pdfView.PdfViewer.ImportPages( fs, '', pdfView.PdfViewer.PageCount );
finally
  fs.Free;
end;


I based that second code on the example in help for loading a TFileStream. And I can confirm that the file temp.pdf does exist and is a valid pdf file.

There is clearly some aspect of loading from a stream that I am missing. Any help would be appreciated.
4   L A T E S T    R E P L I E S    (Newest First)
mountaincoder Posted - Mar 22 2022 : 09:19:02
That all works perfectly. Thank you.
xequte Posted - Mar 21 2022 : 20:54:18
Hi Tony

Yes, the code is correct, it's just that you are importing a PDF file into an empty document (i.e. without first creating/loading a PDF file).

Please see the example on this page to show an error if the PDFium plug-in cannot be registered:

https://www.imageen.com/help/TIEImageEnGlobalSettings.RegisterPlugIns.html




Nigel
Xequte Software
www.imageen.com
mountaincoder Posted - Mar 21 2022 : 18:14:53
That works, thank you.

I took my example from this page, it may need updating:
https://www.imageen.com/help/index.php?topic=TImageEnView.PdfViewer

Also, I would like to confirm that this is using the PDFium plugin if I have it registered?

Thanks,
Tony
xequte Posted - Mar 18 2022 : 18:51:17
Hi


Did you try:

Stream := TMemoryStream.Create;
try
  GetInternetToStream(AURL, '', '', nil, Stream);
  Stream.Position := 0;
  pdfView.IO.LoadFromStreamPDF( Stream );
finally
  Stream.Free;
end;


Nigel
Xequte Software
www.imageen.com