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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 PDF Viewer - loading from a stream
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

mountaincoder

USA
12 Posts

Posted - Mar 18 2022 :  18:02:45  Show Profile  Reply
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.

xequte

38191 Posts

Posted - Mar 18 2022 :  18:51:17  Show Profile  Reply
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
Go to Top of Page

mountaincoder

USA
12 Posts

Posted - Mar 21 2022 :  18:14:53  Show Profile  Reply
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
Go to Top of Page

xequte

38191 Posts

Posted - Mar 21 2022 :  20:54:18  Show Profile  Reply
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
Go to Top of Page

mountaincoder

USA
12 Posts

Posted - Mar 22 2022 :  09:19:02  Show Profile  Reply
That all works perfectly. Thank you.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: