简体   繁体   中英

Converting windows form in C# to PDF using PdfSharp

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!

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();

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