使用 PDFSharp 打印 PDF

发布于 2024-07-20 13:37:42 字数 1237 浏览 5 评论 0原文

我有以下代码:

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

叹倦 2024-07-27 13:37:42

在下面一行中观察到:

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"

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

吃素的狼 2024-07-27 13:37:42

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

C:\文档和
设置\mike.smith\桌面\Adobe
阅读器9.0.exe

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

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.

债姬 2024-07-27 13:37:42

您正在传递“\\ny-dc-03\\IT-01”

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

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文