Print Pdf in C#

c# print pdf itextsharp
c# print pdf silently
c# print pdf to specific printer
c# print pdf without adobe
pdfsharp print pdf
c# print pdf to network printer
spire.pdf print
c# print file

I'm new to c#. I was looking all over the net for tutorials on how to print pdf, but couldn't find one.

Then I thought, is it possible to read it using itextpdf, like mentioned here

Reading PDF content with itextsharp dll in VB.NET or C#

then print it. If so, how?

A very straight forward approach is to use an installed Adobe Reader or any other PDF viewer capable of printing:

Process p = new Process( );
p.StartInfo = new ProcessStartInfo( )
{
    CreateNoWindow = true,
    Verb = "print",
    FileName = path //put the correct path here
};
p.Start( );

Another way is to use a third party component, e.g. PDFView4NET

How to print a PDF from your Winforms application in C#, The first way requires that you user has Adobe Acrobat installed. Usually every computer has a program to read PDF files namely Acrobat Reader  Complete and Convenient PDF Software. Limited Time Offer - Get it Now!

i wrote a very(!) little helper method around the adobereader to bulk-print pdf from c#...:

  public static bool Print(string file, string printer) {
     try {
        Process.Start(
           Registry.LocalMachine.OpenSubKey(
                @"SOFTWARE\Microsoft\Windows\CurrentVersion" +
                @"\App Paths\AcroRd32.exe").GetValue("").ToString(),
           string.Format("/h /t \"{0}\" \"{1}\"", file, printer));
        return true;
     } catch { }
     return false;
  }

one cannot rely on the return-value of the method btw...

How to print PDF files in C#, How to print PDF files in C#. PDF files can't be edited easily and for this reason, it is the most popular file format in business field. Printing PDF files becomes a  The best way to print pdf automatically from C# is using printer's "direct pdf". You just need to copy the pdf file to printer's network sharename. The rest will be taken care by printer itself. The speed is 10 times faster than any other methods.

Another approach, if you simply wish to print a PDF file programmatically, is to use the LPR command: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/lpr.mspx?mfr=true

LPR is available on newer versions of Windows too (e.g. Vista/7), but you need to enable it in the Optional Windows Components.

For example:

Process.Start("LPR -S printerdnsalias -P raw C:\files\file.pdf");

You can also use the printer IP address instead of the alias.

This assumes that your printer supports PDF Direct Printing otherwise this will only work for PostScript and ASCII files. Also, the printer needs to have a network interface installed and you need to know it's IP address or alias.

How to print PDF document in C#, From Spire.PDF v 3.9.360, you should use the new method offers in this article. This example shows how to print a PDF file using C# via the  To print the PDF from a file, you only need to use the PrintRawFile method from an instance of RawPrint. This method expects as first argument, the name of the Printer that you want to use to print the file, as second argument the absolute path to the PDF file (including the filename) that you want to print and as last argument the name of the same file.

I had the same problem on printing a PDF file. There's a nuget package called Spire.Pdf that's very simple to use. The free version has a limit of 10 pages although, however, in my case it was the best solution once I don't want to depend on Adobe Reader and I don't want to install any other components.

https://www.nuget.org/packages/Spire.PDF/

PdfDocument pdfdocument = new PdfDocument();
pdfdocument.LoadFromFile(pdfPathAndFileName);
pdfdocument.PrinterName = "My Printer";
pdfdocument.PrintDocument.PrinterSettings.Copies = 2;
pdfdocument.PrintDocument.Print();
pdfdocument.Dispose();

C# Print PDF. Send a PDF to a Printer in .Net, We can use C# / Visual Basic code to easily print a PDF in .net applications using IronPDF. WE can send a PDF directly to a printer silently (programatic printing)  How to print PDF files in C#. Step 1 : Create a new PDF document and load a PDF from file. Step 2 : Print the PDF file with the default printer to print all the pages. Step 3 : Set the Printer and select the pages you want to print in the PDF file.

You can create the PDF document using PdfSharp. It is an open source .NET library.

When trying to print the document it get worse. I have looked allover for a open source way of doing it. There are some ways do do it using AcroRd32.exe but it all depends on the version, and it cannot be done without acrobat reader staying open.

I finally ended up using VintaSoftImaging.NET SDK. It costs some money but is much cheaper than the alternative and it solves the problem really easy.

var doc = new Vintasoft.Imaging.Print.ImagePrintDocument { DocumentName = @"C:\Test.pdf" };
doc.Print();

That just prints to the default printer without showing. There are several alternatives and options.

Silently Printing PDF Documents in C#, This simple class below will print a PDF document, using Adobe silently. Get Printer Name. This gets the default printer name from the Printer  This simple class below will print a PDF document, using Adobe silently. Get Printer Name. This gets the default printer name from the Printer dialog: private static void getPrinterName() { PrintDialog pt = new PrintDialog(); printerName = pt.PrinterSettings.PrinterName; } Get Document Title

printing a pdf file using c#.net, Hi, Read this article : Print any Document File using a C# Code without Opening Documents. Printing PDF Document using C#. I am facing an issue while printing number of PDF having multiple pages. Using AcroRd32.exe to open the PDF and send print one by one. The issue is for a larger PDF document in a batch, for a 9 page document it does not print after 3 page or 5 page.

Print PDF files from C# / VB.NET applications, Shows how to print PDF documents in C# and VB.NET with GemBox.Pdf library. Achieve perfect printing results by fine-tuning the printing preferences. Thanks to the advanced rasterization engine, images will come out crystal clear while the fonts will be rendered by the built-in font rendering engine. C#.NET and VB.NET. PDF printing in C# is simple with our library. It is compatible with the .NET framework and all CLR

Printing PDF Document using C#, Hi, I am facing an issue while printing number of PDF having multiple pages. Using AcroRd32.exe to open the PDF and send print one by one. DynamicPDF PrintManager is an easy to use API that allows developers to automate PDF printing (sending a PDF to an actual printer device) from within any .NET application (C# or VB.NET). PrintManager allows you to manage multiple print jobs, verify printer settings and handles successful or unsuccessful prints all from within an API that is intuitive and quite easy to learn.

Comments
  • How do you specify the page size with this method? I need to be able to specify a specific paper size that the default printer supports.
  • You can't specify anything using that method. It will only print the pdf using the default printer and its default settings. So if your default paper size is a4, any larger pages will be cut off. It really sucks, but short of 3rd party tools I don't think that there is anything that can be done about this.
  • Great answer, but note that Process inherits from component which implements IDisposable, so it is of course recommended to dispose it or use a using statement, especially if one uses it many times
  • Nice, but... the example doesn't specify any arguments at all, so whatever app is being launched from path, I doubt it'll know what file to print.
  • Ohh, you're using shellexecute, with the "print" verb. Right. Do note Adobe Reader's latest versions don't seem to properly close the window after printing. Also, this will probably not be a silent print command; it'll show a popup for print options.
  • @Santa: This would only work in a Windows machine. If someone ran this from a Mac or Linux it would not work even if they have Adobe. Or am I missing something?
  • How would I find my printer for the "Printer" string variable?
  • @ColtonMilne afair it's the same name that shows up in the control panel... from code: give the system.drawing.printing.printersettings.installedprinters property a shot!
  • glad to be able to help :)
  • Any way of communicating with the printer to know if/when the job was finished?
  • PdfiumViewer enabled me printing pdfs. don't waste your time on spire.pdf (outdated examples/documentation and no valid license provided even after registering with email)
  • it's not a free tool, though.
  • But if you don´t mind a bit additional programming work (in Java) then you could replace RawFilePrinter.exe by a custom program using the open source Apache PDFBox link.