Jino Shaji
Jino Shaji

Reputation: 1103

How to print the current UI of Xamarin form crossplatform application

I want to print the current UI of a Xamarin.Forms cross-platform application. Are there any plugins or libraries available which support both android ios and uwp projects to do this? I'd really appreciate being pointed in the right direction to get started on implementing this kind of feature in my application.

Upvotes: 0

Views: 1230

Answers (1)

JoeTomks
JoeTomks

Reputation: 3276

I would approach this in two steps. Firstly you need to convert the current visuals into a printable file type. So assuming we are working with primarily mobile devices then we should make use of the 'screenshot' mechanisms.

There is a very good answer to another stack overflow account HERE that guides you through setting up screenshots in xamarin forms using dependancy injection. The chaps answer is straight forward and easy to follow.

Once you have that screenshot as a png or jpeg etc. It's time to print it. There are a lot of threads on xamarins developer forums dedicated to the issues around printing from xamarin, a collection of these can be found HERE.

So to start with it's worth mentioning that every platform xamarin forms (XF)supports has it's own mechanism for printing. XF does not provide any abstractions for printing in a cross-platform manner. You will need to write printing logic for each layer and expose it to XF using DependencyServices.

Android Printing - this is a link to printing in android.

iOS Printing - this is a link to printing in iOS (Heres a sample app to help you as well.)

As I previously mentioned, because xamarin hasn't created a simple cross-platform mechanism for this in Forms, it's not quite as simple as you'd think and does require some work to implement. But none of the work is overly complicated, it uses standard dependancy patterns, it's really just the bulk of code required that can seem a bit daunting.

Upvotes: 1

Related Questions