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

pdfViewer export as Image not working

hi please check the below code,it is not showing the image as expected. please help

  private async void SetImage()
        {
            byte[] bytes = new WebClient().DownloadData("http://www.africau.edu/images/default/sample.pdf");

            var pdfViewerControl = new SfPdfViewer();
            pdfViewerControl.LoadDocument(new MemoryStream(bytes));
            Stream stream = pdfViewerControl.ExportAsImage(0, 2.0f);
            var list = pdfViewerControl.ExportAsImage(0, 1);

            MyImage.Source = ImageSource.FromStream(() => stream);
        }

1 Reply

SS Sathish Sivakumar Syncfusion Team April 26, 2019 10:38 AM UTC

Hi Gurvinder, 

Greetings from Syncfusion. 

While exporting the PDF page to image using PdfViewerControl the stream position will seek to the end , so we need to set stream position to 0 to read the image from stream properly to display it in the Xamarin.Forms views. Please find the code changes to below to get the reported issue resolved. 

Please find the below code snippet 
private async void SetImage() 
        { 
            byte[] bytes = new WebClient().DownloadData("http://www.africau.edu/images/default/sample.pdf"); 
            var pdfViewerControl = new SfPdfViewer(); 
            pdfViewerControl.LoadDocument(new MemoryStream(bytes)); 
            Stream stream = pdfViewerControl.ExportAsImage(0, 2.0f); 
            var list = pdfViewerControl.ExportAsImage(0, 1); 
            stream.Position = 0; 
            MyImage.Source = ImageSource.FromStream(() => stream); 
        } 

Please find the sample from the below link, 

Regards,
Sathish 


Loader.
Live Chat Icon For mobile
Up arrow icon