简体   繁体   English

将 System.Drawing.Printing.PrintDocument 转换为 PDF c#

[英]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.我必须使用以System.Drawing.Printing.PrintDocument格式生成报告的 3rd 方 SDK。 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.由于我的项目不是 Windows 窗体项目(它是一个 Web 项目),我需要将此System.Drawing.Printing.PrintDocument转换为 PDF。 I have downloaded iTextSharp and SharpPDF but they seem to create a new PDF.我已经下载了 iTextSharp 和 SharpPDF,但它们似乎创建了一个新的 PDF。 I have also gone through the tutorial(s) here: http://sharppdf.sourceforge.net/Tutorials.html .我还浏览了此处的教程: http : //sharppdf.sourceforge.net/Tutorials.html My requirement is to convert the document that I already have into a PDF.我的要求是将我已有的文档转换为 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?如何安装虚拟 PDF 打印机并“打印”文档? For example - http://www.dopdf.com/ , or http://www.cutepdf.com/products/cutepdf/writer.asp ?例如 - http://www.dopdf.com/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可以在此处找到如何打印 PrintDocument 的代码示例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另一个可能的课程是从 PrintDocument ( http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage(v=vs.80).aspx 中获取图形,看看是什么在这里提出 - http://www.websupergoo.com/helppdfnet/source/4-examples/20-systemdrawing.htm

you can create document by print to file in .net您可以通过打印到 .net 文件来创建文档

exapmle : convert printDocument to XPS file , try code:示例:将 printDocument 转换为 XPS 文件,尝试代码:

 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 .将来我们会将 printDucment 转换为 pdf 文件。

thank you谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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