We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Export as image issues.

I need to process many PDFs and export it as an image, the first PDF works fine, however and other PDF I load and export, the image is always of the first one. I do not get any errors. This is the code I'm using:

            SfPdfViewer pdfViewerControl = new SfPdfViewer();
      
            Stream stream2 = pdfViewerControl.ExportAsImage(0,2.0f);

            stream2.Position = 0;

            byte[] imageAsBytes = Converters.ToByteArray(stream2);

            PDFImage.Source = ImageSource.FromStream(() => new MemoryStream(imageAsBytes));

            filePath = Path.Combine(localFolder, "test.png");

            File.WriteAllBytes(filePath, imageAsBytes);

Again this works fine on the first PDF, but on any other PDF all I get is an image of the first PDF.

If I add this line:

     pdfViewerControl.Unload();

I get this error:

"Object reference not set to an instance of an object."

I also tried, instead of creating the PDFViewer in code, creating it in XAML, the UnLoad works, however in this scenario, the image doesn't get exported, it just creates a 0 byte file.

     


5 Replies

GR Gayathri Ramalingam Syncfusion Team September 27, 2019 11:38 AM UTC

Hi Eddy, 

We were able to reproduce the issues “ExportAsImage returns previous PDF page even after loading a new PDF when SfPdfViewer is instantiated in code and not added to UI" and “Null reference exception occurs while unloading the PDF Viewer” in our side and confirmed it is a defect. This fix will be included in our 2019 Vol 3 Main release which will be available in October 2019. 

With Regards, 
Gayathri R 



ED Eddy September 27, 2019 03:48 PM UTC

Great, glad it's a defect and I'm not loosing my mind then. I thought I was doing something wrong.


GR Gayathri Ramalingam Syncfusion Team September 30, 2019 05:38 AM UTC

Hi Eddy, 
 
Thank you for your update. 
 
As we mentioned earlier, the fix for the issues “ExportAsImage returns previous PDF page even after loading a new PDF when SfPdfViewer is instantiated in code and not added to UI" and “Null reference exception occurs while unloading the PDF Viewer will be included in our Essential Studio 2019 Volume 3 Main release which will be expected to rolled out  on 03rd October 2019. We will inform you once the release is rolled out.  
 
With Regards, 
Gayathri R 
.   




ED Eddy October 3, 2019 08:23 PM UTC

I updated to the current release and that seems to have resolved my current issues. Thanks for the quick turn around on the fix.


JP Jhansi Priya Ramesh Syncfusion Team October 5, 2019 04:43 AM UTC

Hi Eddy, 
 
Thank you for your update. Please get in touch with us if you would require any further assistance. 
 
Regards, 
Jhansi Priya R 


Loader.
Live Chat Icon For mobile
Up arrow icon