7

我有以下代码:

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);
      }
    }
  }
}

对于我的一生,我无法让它工作并打印出一个 PDF。每当我去打印时,我都会收到错误“找不到指定的文件”。有人知道我的代码是否有问题吗?我在这里使用 PDFSharp ...

4

3 回答 3

9

一个观察,在以下行中:

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

您正在使用“@”转义字符串并转义反斜杠。删除“@”或使用单个反斜杠。

还要确保这是您的 EXE 的正确路径。

更新:如果您已确认 Acrobat Reader EXE 的路径正确,接下来要查看的是您传递给 PdfFilePrinter 构造函数的“打印机名称”参数。

" \\ny-dc-03\\IT-01"作为打印机名称传递。这需要与打印机的名称完全匹配,因为它出现在 Windows 的打印机列表中,而不仅仅是任意 IP 打印机。

如果这是正确的,请务必删除前导空格:"\\ny-dc-03\\IT-01".

于 2009-05-19T15:32:36.607 回答
1

这可能是显而易见的,但杂技演员在:

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

只是您的用户名暗示您的名字不是 Mike smith。

于 2009-05-19T15:31:58.213 回答
1

你正在路过" \\ny-dc-03\\IT-01"

我认为这应该是"\\\\ny-dc-03\\IT-01"@"\\ny-dc-03\IT-01"

不确定是否@"\\ny-dc-03\\IT-01"可以工作,但"\\ny-dc-03\\IT-01"不能工作,因为 UNC 名称以双反斜杠开头。

于 2009-08-25T11:17:23.263 回答