简体   繁体   English

.NET 库来打印 PDF 文件

[英].NET library to print PDF files

I am after a library which can accept an already created PDF file and send it directly to the printer.我正在寻找一个可以接受已经创建的 PDF 文件并将其直接发送到打印机的库。 I don't want the user to need Adobe Reader or anything else installed, the application will generate a PDF and I want to print it.我不希望用户需要安装 Adob​​e Reader 或其他任何东西,该应用程序将生成一个 PDF,我想打印它。

Sorry, my first answer (since deleted -- FGITW answer saying just use iTextSharp ) assumed it was PDF FAQ #1 when in fact it was PDF FAQ #~5, mea culpa...抱歉,我的第一个答案(自删除后 - FGITW 回答说只使用iTextSharp )假设它是 PDF FAQ #1,而实际上它是 PDF FAQ #~5,我的罪过...

There's no system-provided native PDF processing, so outside of using an app such as FoxIt or Acrobat -- which you shouldn't discount too quickly - people who use PDF will have one or the other and will be choosy about which one they prefer as they're not all equal, esp if you get into more advanced features and their associated licensing and monetisation schemes.没有系统提供的原生 PDF 处理,因此除了使用 FoxIt 或 Acrobat 等应用程序(您不应该打折太快)之外,使用 PDF 的人将拥有一个或另一个,并且会选择他们喜欢哪一个因为它们并不完全相同,尤其是如果您了解更高级的功能及其相关的许可和货币化方案。

Not aware of any specific libraries that address this requirement, though the other question I've linked to above should have a good answer.不知道有任何特定的库可以满足这一要求,尽管我上面链接的另一个问题应该有一个很好的答案。 ... researches; ... 研究; time passes... An answer on the other question says PDFSharp should suit, the sample looks straightforward.时间过去了...... 另一个问题的答案PDFSharp应该适合, 样本看起来很简单。

On reflection based on looking at Pdfsharp's FAQ wiki, iTextSharp has similar stuff for generating TIFFs/images as PDFSharp has.在基于查看 Pdfsharp 的 FAQ wiki 的反思中, iTextSharp具有与 PDFSharp 类似的用于生成 TIFF/图像的东西

An alternative which may or may not be in scope is to generate and/or convert to eg, an XPS file, which does have built in printing support (pretty sure .NET 3.5, and possibly earlier have it as a standard component in the Client Profile).可能在范围内或可能不在范围内的替代方法是生成和/或转换为例如 XPS 文件,该文件确实具有内置的打印支持(非常确定 .NET 3.5,并且可能更早将其作为客户端中的标准组件)简介)。

One point that shouldn't be missed in this all is that the Lowagie book (iText In Action) is excellent and if you're going to be doing anything in reading, writing or providing PDF forms, you should have it on your shelf.在这一切中不应错过的一点是, Lowagie 的书 (iText In Action)非常出色,如果您打算在阅读、写作或提供 PDF 表单方面做任何事情,您应该将其放在书架上。 Similarly, if you do go the FLOSS library route, iText has to be seriously considered.同样,如果您确实走 FLOSS 库路线,则必须认真考虑 iText。

I'm not aware of any free/open source libraries available to do this, but after evaluating a handful, I went with cete DynamicPDF Print Manager.NET .我不知道有任何免费/开源库可以做到这一点,但在评估了一些之后,我选择了cete DynamicPDF Print Manager.NET It was by far the most efficient in terms of system resources, namely RAM.就系统资源(即 RAM)而言,它是迄今为止效率最高的。 The other products I tried were from Tall Components, Gnostice , and BCL EasyPDF SDK .我尝试过的其他产品来自 Tall Components、 GnosticeBCL EasyPDF SDK All of these used large amounts of RAM compared to cete's product.与cete的产品相比,所有这些都使用了大量的RAM。 The Print Manger has good documentation is was easy to use. Print Manger 有很好的文档很容易使用。

You may also be able to call gsprint from .NET, part of gsview , which is FOSS GUI for GhostScript.您也可以从 .NET 调用gsprint ,它是gsview 的一部分,它是 GhostScript 的 FOSS GUI。 I did not go this route, but also noticed it seemed to use more system resources than Dynamic PDF.我没有走这条路,但也注意到它似乎比动态 PDF 使用更多的系统资源。 If you could probably have package it with your software so to the user it's more transparent.如果您可以将它与您的软件打包在一起,那么对用户来说它会更加透明。 I know it doesn't fit your criteria, but this seems to be the only possible free solution available.我知道它不符合您的标准,但这似乎是唯一可用的免费解决方案。

In case you come across PDFSharp, note that it uses Adobe Reader to print.如果您遇到 PDFSharp,请注意它使用 Adob​​e Reader 进行打印。

Apache's PDFBox has a command line PrintPDF utility that you may also be able to call from .NET. Apache 的 PDFBox有一个命令行 PrintPDF 实用程序,您也可以从 .NET 调用它。 I came across it after I purchased Print Manager, so I haven't tried it yet.我是在购买 Print Manager 后遇到的,所以我还没有尝试过。

Update: You can use Sumatra PDF to print silently from the command line .更新:您可以使用Sumatra PDF 从命令行静默打印。 I suspect it rasterizes the PDF before sending to the printer, but for smaller files that should work.我怀疑它会在发送到打印机之前对 PDF 进行光栅化,但对于应该可以工作的较小文件。

I hope this will help someone.我希望这会帮助某人。 After looking online I found this great open source library (C#) and it works perfect for me.在网上查看后,我发现了这个很棒的开源库 (C#),它非常适合我。

https://github.com/tonyedgecombe/RawPrint https://github.com/tonyedgecombe/RawPrint

    using RawPrint;

    Printer.PrintFile("Printer Name", @"C:\Path\To\Print\File.prn");

Best of luck,祝你好运,

I created a small .Net 4.0 library called PDFFilePrint, you can fetch this through the nuget package manager or you can call "install-package PDFFilePrint" in the nuget package manager console.我创建了一个名为 PDFFilePrint 的小型 .Net 4.0 库,您可以通过 nuget 包管理器获取它,也可以在 nuget 包管理器控制台中调用“install-package PDFFilePrint”。 Here is a link to the package .这是的链接。

There are a few commercial libraries out there.那里有一些商业图书馆。 I for example would recommend http://pdfprinting.net .例如,我会推荐http://pdfprinting.net

PS I work for the company offering that solution. PS 我为提供该解决方案的公司工作。

Free PDFiumViewer comes via Nuget and has print capabilities, see code sample here.免费的 PDFiumViewer 来自 Nuget 并具有打印功能,请参阅此处的代码示例。

Real easy to use - took me long time to find though - so I post it for people searching in the "wrong" question:真的很容易使用——不过我花了很长时间才找到——所以我把它发布给搜索“错误”问题的人:

https://stackoverflow.com/a/41751184/586754 https://stackoverflow.com/a/41751184/586754

You can try PDFView4NET .你可以试试PDFView4NET It supports printing of PDF files and conversion of PDF pages to images.它支持打印 PDF 文件和将 PDF 页面转换为图像。

Disclaimer: I work for the company that develops PDFView4NET.免责声明:我为开发 PDFView4NET 的公司工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM