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

19.4k views Asked by At

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?

2

There are 2 answers

0
abdulaziz saeed On

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

4
Vadim On

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