简体   繁体   中英

Convert System.Drawing.Printing.PrintDocument to PDF c#

I have to use a 3rd party SDK that generates reports in a System.Drawing.Printing.PrintDocument format. Since my project is not a Windows Form project(it is a Web project),I need to convert this System.Drawing.Printing.PrintDocument to a PDF. I have downloaded iTextSharp and SharpPDF but they seem to create a new PDF. I have also gone through the tutorial(s) here: http://sharppdf.sourceforge.net/Tutorials.html . My requirement is to convert the document that I already have into a PDF. Is there something that I'm missing in using these libraries? Can someone please provide a sample code to achieve this?

How about installing a virtual PDF printer and "print" the document? For example - http://www.dopdf.com/ , or http://www.cutepdf.com/products/cutepdf/writer.asp ?

A code sample of how to print a PrintDocument, can be found here http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx

Another possible course would be take the Graphics from the PrintDocument ( http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage(v=vs.80).aspx and look at what is proposed here - http://www.websupergoo.com/helppdfnet/source/4-examples/20-systemdrawing.htm

you can create document by print to file in .net

exapmle : convert printDocument to XPS file , try code:

 private void button8_Click(object sender, EventArgs e) { Addpage = 0; printDocument1.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"; printDocument1.DefaultPageSettings.PrinterSettings.PrintToFile = true; printDocument1.DefaultPageSettings.PrinterSettings.PrintFileName = "d:\\\\ddd11.xps"; printDocument1.PrintController = new StandardPrintController(); printDocument1.Print(); }​

in future time we will get convert printDucument to pdf file .

thank you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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