UWP PDF printing
Asked Answered
T

1

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.

Titanic answered 27/8, 2018 at 16:51 Comment(11)
May be you can try this library. It supports Winrt.Verso
Thank you. But, I am looking to solve this without libraries. I will update my question.Titanic
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.Semiquaver
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.Amphithecium
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.Brainpan
I tried well. There are no other methods provided by Microsoft to print PDF from UWP application. As suggested by @Verso i tried ITextSharp it works well but its under AGPL license. So, I used PDFSharp(pdfsharp.net) to print pdf using Microsoft AppServiceBridge. github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/…Titanic
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.Hadrian
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).Tarrant
why the bounty now? what are you expecting exactly?Brainpan
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.Titanic
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.Seismoscope
D
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://mcmap.net/q/444804/-writing-a-virtual-printer-in-net-closed

Destinydestitute answered 4/12, 2020 at 11:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.