Articles in this section
Category / Section

How to display PDF document in Xamarin.Forms and draw the ink annotation over the PDF document?

3 mins read

At present we do not have support for displaying the PDF document in Xamarin. However, as a workaround we can export the PDF document to Images in Windows Azure Service and display the exported images of PDF document in Xamarin.Forms.

The following code snippet illustrates the conversion of PDF document to Images in Windows Azure service.

C#

public MemoryStream GetPage(int pageNum)
{
if (pdfDocumentView != null && pageNum >= 0 && pageNum < pdfDocumentView.PageCount)
{
//Export the PDF pages to image
Bitmap bmp = pdfDocumentView.ExportAsImage(pageNum);
MemoryStream stream = new MemoryStream();
//Save the exported PDF page as Image
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
return stream;
}
return null;
}

 

Please find the Windows Azure Service sample that converts PDF page to image in the following link.
https://www.syncfusion.com/downloads/support/directtrac/153866/ze/PdfViewerExportService-90689727

The following code snippet illustrates how to display the image of PDF page in Xamarin with the help of Windows Azure Service.

C#

//Initialize the Windows Azure Service which exports the PDF document to images
net.cloudapp.pdfviewerexportservice.Service1 service = new net.cloudapp.pdfviewerexportservice.Service1();
bool result;
//Load the Pdf Document into service
service.LoadDocument("Object C succinity.pdf", out m_totalPage, out result);
//Convert the specified page of the PDF document to Image
m_currentBitmap = Xamarin.Forms.DependencyService.Get<IPdfImage>().GetPage(0);
//Set the exported image to display on the viewport
this.SetImageBitmap(BitmapFactory.DecodeStream(m_currentBitmap));

 

This application can also be extended to add ink annotation to the PDF document and save the changes in PDF document in Xamarin platform. The following link contains the sample application which allows the user to add ink annotations to the PDF document.

https://www.syncfusion.com/downloads/support/directtrac/153866/ze/PDFViewer-789627111

The following screenshots illustrates the operations that can be performed in the above sample.

To navigate between pages

To add Ink annotation

To save the PDF document

To navigate between pages

To add Ink annotation

To save the PDF document

 

Note:

Starting with v16.2.0.x, if you reference Syncfusion® assemblies from the trial setup or the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering the Syncfusion® license key in your application to use the components without a trial message.

 

Conclusion:

I hope you enjoyed learning about how to display PDF document in Xamarin.Forms and draw the ink annotation over the PDF document.

 

You can refer to our Flutter PDF feature tour page to learn about its other groundbreaking features and documentation, and how to quickly get started with configuration specifications. You can also explore our Flutter PDF Flutter PDF examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to explore our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied