Generating PDF files from .NET by using standard .NET GDI printing classes

梦想与她 提交于 2019-11-30 07:38:00

The System.Drawing code for a PrintDocument can be reused to generate a PDF with ABCpdf.NET from webSupergoo. See the System.Drawing example for more details. The component doesn't use a printer driver - it creates PDF directly - so doesn't require a filename to be specified.

A product called Amyuni does this (I use it in a project) but I don't like the licencing, you may get on fine with it.

See Amyuni.com

Ryan

yms

Amyuni PDF Converter does what you need, it provides a Microsoft certified printer driver that you can fully manipulate using a COM interface or .net assembly, and you can use standard GDI (or Windows.Forms classes) to generate your PDF files (you probably checked on Amyuni PDF Creator, which is a custom API as you stated in your comments to this answer ).

Unless the printer drivers that you are using support this manually (of which none exist that I know of), you would have to write your own printer driver which you would be able to pass information to (such as the filename) during the print operation.

The drawbacks to this are the fact you would have to implement a printer driver, as well as the fact that it would have to be unmanaged code (you can't write drivers in .NET).

There are several companies who create document format conversion tools. Several of them use printer drivers to "print" the document into the format desired. Look around for tools that can convert from Word documents to PDF. One of these should have the kind of driver you need, and some will offer an API that allows you to control filenames and such.

Did some more research, and although I still didn't find a perfect solution, there are a few products that install a PDF printer driver and which allow you in some way to control the name of the file to be generated:

Bullzip and PDFCreator are free.

UPDATE: Found another one that looks very promising:

Dane-Prairie Systems http://www.win2pdf.com/ seems to capture the "print to file" string from the GDI calls and will create your PDF whereever you spec. Here's a quote from the manual:

Set the lpszOutput field of the DOCINFO structure to the fully qualified path name of the file, and then pass the DOCINFO structure to the Win32 StartDoc function.

Peter

The C1Pdf component does this. It has methods that mimic GDI plus (DrawString, DrawImage, etc) and generates PDFs. It does not install or require any printer drivers. Here's a link to the documentation in case you want more detail:

http://www.componentone.com/newimages/Products/Documentation/WinForms.PDF.pdf

Not sure if this is a solution you'd consider, but I've used iTextSharp to fill in PDF Forms and save them with a filename that's generated in code, not by the user. It also can generate complete PDFs from scratch, but I haven't delved that far into it.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!