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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

pdfViewer export as Image not working

Thread ID:

Created:

Updated:

Platform:

Replies:

144223 Apr 25,2019 10:28 AM UTC Apr 26,2019 10:38 AM UTC Xamarin.Forms 1
loading
Tags: PdfViewer
Gurvinder SIngh
Asked On April 25, 2019 10:28 AM UTC

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);
        }

Sathish Sivakumar [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon