使用PDFSharp将图像叠加到PDF上
似乎没有找到很多这方面。 我有一张PDF,我想在其上覆盖电子签名的图像。 有关如何使用PDFSharp完成该任务的任何建议?
谢谢
请尝试以下方法
private void GeneratePDF(string filename, string imageLoc) { PdfDocument document = new PdfDocument(); // Create an empty page or load existing PdfPage page = document.AddPage(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); DrawImage(gfx, imageLoc, 50, 50, 250, 250); // Save and start View document.Save(filename); Process.Start(filename); } void DrawImage(XGraphics gfx, string jpegSamplePath, int x, int y, int width, int height) { XImage image = XImage.FromFile(jpegSamplePath); gfx.DrawImage(image, x, y, width, height); }
这将生成一个新的PDF,其中指定的图像靠近页面顶部。 如果需要使用现有文档, PdfDocument
构造函数更改为
PdfDocument document = new PdfDocument(filename);
其中filename
是要加载的文件的名称,并将PdfPage
行更改为
PdfPage page = document.Pages[pageNum];
其中pageNum
是您需要添加图像的页面编号。
在那之后,只需通过改变DrawImage
的参数来适应页面上的定位。
DrawImage(gfx, imageLoc, 50, 50, 250, 250);
祝好运!
这将有助于您:
PdfDocument document = pdf; // Create a new page PdfPage page = document.Pages[0]; page.Orientation = PageOrientation.Portrait; XGraphics gfx = XGraphics.FromPdfPage(page, XPageDirection.Downwards); // Draw background gfx.DrawImage(XImage.FromFile("pdf_overlay.png"), 0, 0);
只需添加所需图像的路径,然后指定图像的位置即可。
- 带有html属性的html.BeginForm asp.net mvc4
- 如何初始化我的entity framework查询以加快它们的速度?
- 如何将查询字符串参数转换为asp.net mvc 4中的路由
- Web Api不会使用jQuery Ajax和Basic Auth下载文件
- MVC脚手架不支持Entity Framework 6或更高版本
- 创建帮助程序以覆盖CheckboxFor
- Castle Windsor ASP.NET MVC 4和Web API相同的应用程序。 只有MVC控制器没有依赖关系?
- 用于将Windows应用程序连接到MVC 4的Web服务或Web API?
- 在视图中执行处理程序的子请求时出错