views:

1737

answers:

3

Hello All--

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...

+1  A: 

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.

Omar Kooheji
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
+3  A: 

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 trailing space: "\\ny-dc-03\\IT-01".

ichiban
Good spot... there.
Omar Kooheji
already tried doing that--still not working
A: 

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", but "\\ny-dc-03\\IT-01" cannot work as UNC names start with a double backslash.

The best place to ask PDFsharp and MigraDoc Foundation related questions is the PDFsharp forum. The PDFsharp Team will not monitor stackoverflow.com on a regular basis.

PDFsharp Forum:
http://forum.pdfsharp.net/

PDFsharp Team