16

Is there a way to print PDF from UWP application? Other than rendering it as png or BitmapImage.

I had look at Microsoft printing sample and pdf rendering sample to achieve printing pdf by rendering it into bitmapimage. But, it looses the quality of the pdf. Would like to know if any other efficient method available without using libraries .

Edit(31/12/2018)

I tried to find direct solutions from Microsoft without using libraries. But, there isn't any so i used PDfSharp to solve my problem with the help of AppServiceBridge by Microsoft. I have used AppService bridge because PdfSharp isn't directly available for WinRT.

Community
  • 1
  • 1
Vignesh
  • 1,824
  • 2
  • 10
  • 27
  • 2
    May be you can try [this](https://github.com/itext/itextsharp) library. It supports Winrt. – Dishant Aug 27 '18 at 22:05
  • 1
    Thank you. But, I am looking to solve this without libraries. I will update my question. – Vignesh Dec 04 '18 at 12:26
  • 1
    You lose quality when you make the bitmapimage too small. Printers have a very high resolution, an 11x8.5 inch piece of paper on a 600dpi printer requires a honking 6600x5100 bitmap, 128 megabyte. The kind of problem that PDF was designed to overcome :) Right now you probably have 1 pixel in the image map to a ~6x6 blob of ink on paper because you didn't adjust its dpi, it takes very long arms to not see that. – Hans Passant Dec 04 '18 at 12:40
  • You can call Adobe Reader to print PDF file. Without using any libraries, you have to use an external software. You can set paper size, quality ... with Adobe Reader. – emert117 Dec 26 '18 at 10:04
  • 5
    What do you mean by "solve this without libraries"? If the Microsoft-provided sample aren't good enough, I doubt you will solve this w/o any 3rd party library. – Simon Mourier Dec 31 '18 at 09:02
  • 1
    I tried well. There are no other methods provided by Microsoft to print PDF from UWP application. As suggested by @Dishant i tried ITextSharp it works well but its under AGPL license. So, I used PDFSharp(http://www.pdfsharp.net) to print pdf using Microsoft AppServiceBridge. https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/AppServiceBridgeSample#appservice-bridge-sample – Vignesh Dec 31 '18 at 10:08
  • Hey I am confused about your answer - I am about to start a project that needs to generate PDF reports and was initially looking for a PDF library - but prefer to use native platform capabilities if possible. I just looked at the Microsoft printing samples and it seems that using the Print to PDF output option does generate vector pdf files. The only thing I have not yet checked is whether it is possible to setup output queues such that no user interaction is required to generate the pdf files. Did I miss something here - there is no need to render to a bitmapimage. – Duncan Groenewald Jul 22 '19 at 00:51
  • 4
    I think that question is not about printing TO PDF (not clicking print and receiving pdf file), but to print PDF directly from UWP app (open pdf file with the app, click print and have the pdf file sent to printer). – RTDev Aug 24 '19 at 02:10
  • why the bounty now? what are you expecting exactly? – Simon Mourier Nov 15 '19 at 10:02
  • Using `AppServiceBridge` blocks the application capability to deploy in ARM processor's. So it is not running Surface Pro X. Still looking for native printing pdf without rendering into image. – Vignesh Nov 15 '19 at 10:13
  • I do not understand what is the ask here in the question. But did you already had look at PrintDocument class ? You can set printer to be "Microsoft Print to PDF" there. – Manoj Choudhari Nov 18 '19 at 15:18

1 Answers1

1

I used a virtual printer in C# using the Github project: Microsoft/Windows-driver-samples/print/XPSDrvSmpl.

https://github.com/Microsoft/Windows-driver-samples/tree/master/print/XPSDrvSmpl

Installer: http://wixtoolset.org/

Application: Listen to internal port

Flow: Install printer and application from a single installer. User prints something with your driver while the application listens to the internal port. When data is sent the application picks it up. This is for XPS, can be converted to PDF, but the flow is similar no matter what you are printing.

Original answer:

https://stackoverflow.com/a/40370083/3850405

Ogglas
  • 62,132
  • 37
  • 328
  • 418