This sample shows how to print a PDF file automatically using Adobe Reader or Adobe Acrobat.
PDFsharp cannot print PDF files, but you can use Adobe Reader with a command line switch to do the job.
Source Code
Note: This sample has hard-coded strings for printer name and path to Adobe Reader.
A real-world application must enumerate the printers to let the user choose one and must search the path to the application itself.
This is the whole source code needed to print a PDF file:
// Set Acrobat Reader EXE, e.g.:
//PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\Adobe Acrobat 7.0\Acrobat\Acrobat.exe";
// -or-
//PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\[...]\AcroRd32.exe";
// On my computer (running Windows Vista 64) it is here:
PdfFilePrinter.AdobeReaderPath = @"C:\Program Files (x86)\Adobe\Acrobat 8.0\Acrobat\Acrobat.exe";
// Set the file to print and the Windows name of the printer.
// At my home office I have an old Laserjet 6L under my desk.
PdfFilePrinter printer = new PdfFilePrinter(@"..\..\..\..\..\PDFS\HelloWorld.pdf", "HP LaserJet 6L");
try
{
printer.Print();
}
catch (Exception ex)
{
Console.WriteLine("Error: " + ex.Message);
}