Create PDF files from .NET using standard .NET GDI print classes

I am looking for a way to create PDF files using the standard PrintDocument and Graphics (GDI) classes in .NET. As far as I know, the only way to do this is to print to a PDF printer.

The problem is that the PDF printer driver always asks for the file name, but I need to control the file name from my code. Using a PDF library such as PDFSharp or DynamicPDF is not an option, as they all provide their own API for creating PDF files.

I need this for an internal application, so dependencies are not a problem.

My question is simple: is there a way to control the printer driver (Adobe Acrobat, PDFCreator, ...) in such a way that the file name can be specified, but nothing was suggested to the user?

+4
printing pdf gdi
source share
9 answers

I did some more research, and although I still haven't found the perfect solution, there are several products that install the PDF printer driver and that allow you to somehow manage the name of the file you are creating:

Bullzip and PDFCreator are free.

UPDATE Found another one that looks very promising:

0
source share

The System.Drawing code for PrintDocument can be reused to create a PDF file with ABCpdf.NET from webSupergoo. See the System.Drawing example for more details. The component does not use a printer driver - it creates a PDF directly - so you do not need to specify a file name.

+4
source share

A product called Amyuni does this (I use it in the project), but I don't like licensing, you can handle it.

See Amyuni.com

Ryan

+2
source share

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

+1
source share

If the printer drivers that you use do not support this manually (of which there are none of which I know of), you will have to write your own printer driver that you can transfer (for example, the file name) during the print operation . A.

The disadvantages of this are the fact that you have to implement a printer driver, as well as the fact that it must be unmanaged code (you cannot write drivers in .NET).

0
source share

There are several companies that create document format conversion tools. Some of them use printer drivers to "print" the document in the desired format. Inspect tools that can convert from Word documents to PDF. One of them should have the necessary driver, and some will offer an API that allows you to manage file names, etc.

0
source share

Dane-Prairie Systems http://www.win2pdf.com/ seems to grab the print-to-file line from GDI calls and create your PDF spec file Here is a quote from the manual:

Set the lpszOutput field. The DOCINFO structure is the full path name of the file and then pass the DOCINFO structure to the Win32 StartDoc function.

Peter

0
source share

The C1Pdf component does this. It has methods that simulate GDI plus (DrawString, DrawImage, etc.) and generate PDF files. It does not install or require any printer drivers. Here is a link to the documentation if you want to get more detailed information:

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

0
source share

Not sure if this is the solution you would think, but I used iTextSharp to fill in the PDF forms and save them with the file name generated in the code, not the user. It can also generate full PDF files from scratch, but I did not realize what was far in it.

-one
source share

All Articles