打印PDF文件中PDFSharp [英] Printing PDFs with PDFSharp

查看:2591
本文介绍了打印PDF文件中PDFSharp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

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

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

推荐答案

一观察,以下行:

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.

另外,还要确保对您的EXE的正确路径。

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

更新:如果您确认您有正确的路径到你的Acrobat Reader软件EXE,看看接下来的事情是,你传递给PdfFilePrinter构造打印机名称参数。

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.

您逝去的\\\\
y-DC-03\\IT-01
作为打印机名称。这需要精确匹配的打印机的名称,因为它出现在打印机的Windows中的列表,而不仅仅是一个任意的IP打印机。

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.

如果这是正确的,一定要删除尾随空格:\\\\
y-DC-03\\IT -01

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

这篇关于打印PDF文件中PDFSharp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆