gpt4 book ai didi

c# - 使用 PDFSharp 打印 PDF

转载 作者:太空狗 更新时间:2023-10-29 20:12:15 25 4
gpt4 key购买 nike

我有以下代码:

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

最佳答案

一个观察,在下面一行:

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"

关于c# - 使用 PDFSharp 打印 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/883456/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com