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.
Unfortunately, activation email could not send to your email. Please try again.

How to print PDF documents in Xamarin.Forms platform?

PDF documents can be printed in Xamarin Forms’ Android, iOS, and UWP platforms by obtaining the currently loaded PDF as stream and printing the stream using native printing functionalities available in the respective platforms using DependencyService of Xamarin Forms. These platform specific printing options can be used by defining an interface in the portable project and implementing the same in the platform projects using the specific code.

The following code snippets illustrate printing PDF documents in Xamarin Forms’ Android, iOS, and UWP platforms.

Portable

Define the following interface.

C#

 

Load the PDF to PdfViewer. Call the Print method with the stream obtained from PdfViewer and file name using DependencyService when the print button is clicked in the code behind. Give the name of the interface as the type parameter to the method DependencyService.Get<T>().

C#

 

Implement the interface in the platform projects with the available platform specific printing options.

Android

C#

 

Define a class derived from the PrintDocumentAdapter and write the contents of the input file to the print destination in the OnWrite method.

C#

 

iOS

C#

 

UWP

C#

 

Sample link:

http://www.syncfusion.com/downloads/support/directtrac/general/ze/PDFPrintingSample-1198012909

 

Article ID: Published Date: Last Revised Date: Platform: Control: .NET Framework:
8767 05/17/2018 07/03/2018 Xamarin.Forms PdfViewer 4.5.1
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.