使用PdfSharp在C#转换Windows构成对PDF [英] Converting windows form in C# to PDF using PdfSharp

查看:1064
本文介绍了使用PdfSharp在C#转换Windows构成对PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个C#windows窗体到PDF文档的当前内容进行转换。

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

我使用的DLL PDFSharp做转换,我不知道如何捕获Windows窗体,并将其转换为PDF。我收集我应该使用 XGraphics.DrawImage()方法复制Windows窗体的内容。

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!

推荐答案

您可以先的 C# - 活动窗口的截图捕获然后将图像传递到PDFSharp这样的:

You could first C# - 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();

这篇关于使用PdfSharp在C#转换Windows构成对PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆