Printing PDFs with PDFSharp

34,903

Solution 1

One observation, in the following line:

PdfFilePrinter.AdobeReaderPath 
      = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";

You are using the "@" to escape the string and also escaping the backslashes. Either remove the "@" or use a single backslash.

Also make sure that is the correct path to your EXE.

UPDATE: If you have confirmed that you have the correct path to your Acrobat Reader EXE, the next thing to look at is the "Printer Name" parameter that you are passing to the PdfFilePrinter constructor.

You are passing " \\ny-dc-03\\IT-01" as the printer name. This needs to match the name of printer exactly as it appears in the list of Printers in Windows, not just an arbitrary IP printer.

If this is correct, be sure to remove, the leading space: "\\ny-dc-03\\IT-01".

Solution 2

You are passing " \\ny-dc-03\\IT-01"

I think this should be "\\\\ny-dc-03\\IT-01" or @"\\ny-dc-03\IT-01"

Not sure if @"\\ny-dc-03\\IT-01" will work, but "\\ny-dc-03\\IT-01" cannot work as UNC names start with a double backslash.

Solution 3

This may be stating the obvious but is acrobat at:

C:\Documents and Settings\mike.smith\Desktop\Adobe Reader 9.0.exe

It's just your user name implies that your name isn't Mike smith.

Share:
34,903
yeahumok
Author by

yeahumok

Updated on November 14, 2020

Comments

  • yeahumok
    yeahumok over 3 years

    I have the following code:

    using System;
    using System.Diagnostics;
    using System.IO;
    using PdfSharp.Pdf.Printing;
    
    namespace PrintPdfFile
    {
    
      class Program
      {
        [STAThread]
        static void Main(string[] args)
        {
          // Set Acrobat Reader EXE, e.g.:
            PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";
          // -or-
            //PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\[...]\AcroRd32.exe";
    
          //// Ony my computer (running a German version of Windows XP) it is here:
            //PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.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(@"C:\Documents and Settings\mike.smith\Desktop\Stuff\ReleaseNotesAndFolderList.pdf", " \\ny-dc-03\\IT-01");
    
          try
          {
            printer.Print();
          }
          catch (Exception ex)
          {
            Console.WriteLine("Error: " + ex.Message);
          }
        }
      }
    }
    

    For the life of me i cannot get this to work and print out a single PDF. Anytime i go to print, i get the error "Cannot find the file specified". Does anybody have any idea if something is wrong with my code?? I'm using PDFSharp here...

  • yeahumok
    yeahumok almost 15 years
    oh no lol i just put in a dummy name since i didn't want to post my real name up here...but yes that is where it resides on my computer
  • Ricky
    Ricky over 6 years
    Registry.ClassesRoot.OpenSubKey(@"Software\Adobe\Acrobat\Exe‌​"), the default value is what holds the path to the currently installed version of Acrobat, whether reader or pro.