Converting windows form in C# to PDF using PdfSharp

青春壹個敷衍的年華 提交于 2019-11-28 09:59:50

问题


I am trying to convert the current contents of a C# windows form to a pdf document.

I am using the PDFSharp dll to do the conversion, I am not sure of how to capture the windows form and convert it to a PDF. I gather I should use the XGraphics.DrawImage() method to copy the contents of the windows form.

Any help or suggestions would be appreciated!


回答1:


You could first Capture screenshot of active window? and then pass the image into PDFSharp like:

var doc = new PdfDocument();

var oPage = new PDFPage();

doc.Pages.Add(oPage);
var xgr = XGraphics.FromPdfPage(oPage);
var img = XImage.FromFile(PATH_TO_IAMGE_CAPTURED_HERE);

xgr.DrawImage(img, 0, 0);

doc.Save(YOUR_FILE_PATH_HERE);
doc.Close();


来源:https://stackoverflow.com/questions/10618036/converting-windows-form-in-c-sharp-to-pdf-using-pdfsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!