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.