Use the System.Drawing.Printing.PrintDocument file to create a PDF file in memory

Does anyone know if the following is possible, and if so, what is the best way to do this for free?

I create a PrintDocument in the project I am working on and show a print dialog so that the user can choose which printer they want to use, etc. This is currently an application for Windows forms, and if the user wants to print PDF they can choose to print on CutePDF or something like that.

However, now I am adding the ASP.Net web interface to the application and want to use the same code to create the PrintDocument, but you want to print it to PDF on the fly and submit it via the Response stream in PDF download format.

So my question is ... How can I use the current PrintDocument and generate a PDF file from memory?

thanks

+6
c # pdf
source share
6 answers

The System.Drawing code for PrintDocument can be reused to create a PDF document with ABCpdf.NET. See System.Drawing Example ...

+2
source share

You will need to use a third-party component to create the PDF file. The following article provides some links to some of these components: Creating PDF files from. Net

0
source share

You are in a world of resentment if you think you are going to run the "same code" that applies to printers in both the form application and the ASP.NET application.

You may be lucky as it seems that PDFsharp + MigraDoc can do this for you.

0
source share

I think you will find that there are no tools that take PrintDocument as input and produce PDF as output. The only way to do what you want is to "print" the PrintDocument to the "PDF printer driver" that will generate the PDF. Basically a virtual printer that will generate a PDF instead of printing the actual output. There are many products on the market for this. A pair that is cheap and widely used is as follows:

0
source share

You really should watch iTextSharp (this is mentioned on the iText.NET page recommended earlier)

http://itextsharp.sourceforge.net/

PrintDocument is for Windows Forms applications, but is located in SilverLight and appears in this video ... http://silverlight.net/learn/videos/all/printing-api-basics/

If you want to continue working with PrintDocument and the web application, I think that SilverLight 4 (which is now a beta version) is the only way to go or you will need to install the application for creating heavy-weight windows, installed locally for the end user. which can use web services.

iTextSharp is a great tool for creating .pdf files with .NET on the web. I highly recommend this; I have been using iText with Java ... and have been using iTextSharp for the past few years.

0
source share

There are several iText ports for .NET (a very popular open source PDF library for Java).

http://www.ujihara.jp/iTextdotNET/en/

-one
source share

All Articles