2009-05-19 201 views
5

我有以下代码:打印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这里...

+0

其中是PDFSharp.PDF.Printing命名空间? – nuander 2016-03-16 23:20:12

+0

ahhh在当前版本的PDFSharp中,整个印刷类被注释掉 – nuander 2016-03-17 19:48:25

回答

7

一个观察,在下面一行:

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

您使用的是“@”,以逃避串并逃离反斜杠。删除“@”或使用单个反斜杠。

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

UPDATE:如果您确认您有正确的路径到你的Acrobat Reader软件EXE,看是要传递到PdfF​​ilePrinter构造函数中的“打印机名称”参数,接下来的事情。

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

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

1

这可能在以下说明明显,但杂技演员:

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

这只是你的用户名暗示你的名字不是迈克史密斯。

+0

哦,不,哈哈我只是放在一个虚拟的名字,因为我不想在这里发布我的真实姓名......但是,那是它驻留的地方我的电脑 – yeahumok 2009-05-19 16:34:59

0

你传入" \\ny-dc-03\\IT-01"

我想这应该是因为UNC名称以双反斜线开始"\\\\ny-dc-03\\IT-01"@"\\ny-dc-03\IT-01"

不知道是否@"\\ny-dc-03\\IT-01"会的工作,但"\\ny-dc-03\\IT-01"不能工作。