Print PDF directly to printer in .NET

I ran into a seemingly simple problem the other day, but it took me several attempts with various libraries to find a solution, so I figured I’d share.

I had a need to print a single-page PDF file (in this case, a mailing label, but your case may vary) directly to a printer from C# without prompting a user.

The code I was working on was intended to run inside of a scheduled task, so obviously prompts are no good. I ended up using the free Spire PDF library, which is good for up to 10 pages before a professional license is required. In my case, each label is a single page, so I’m good with the free license.

Also in my case, I had the PDF data in memory already, which is why my method takes it as a base64-encoded string. If you are looking to print from disk, there are examples on Spire’s site regarding how to accomplish this.

As always, I hope this helps, and leave me a comment if you have any questions or suggestions. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

+ eight = 14

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">