问题描述
似乎无法找到太多了那里这一点。我有一个PDF,上,我想覆盖电子签名的图像。如何实现任何建议,使用PDFSharp?
Can't seem to find much out there for this. I've a PDF, onto which I'd like to overlay an image of an electronic signature. Any suggestions on how to accomplish that using 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
构造器
This will generate a new PDF with the specified image near the top of the page. If you need to use an existing document change the PdfDocument
constructor to
PdfDocument document = new PdfDocument(filename);
其中,文件名
是文件的加载和修改 PdfPage
行的名称
where filename
is the name of the file to load and change the PdfPage
line to
PdfPage page = document.Pages[pageNum];
其中,页次
是您需要添加的图像的页面的数量。
where pageNum
is the number of the page on which you need to add the image.
在此之后,它只是一个问题,通过改变参数的DrawImage
,以适应越来越页面上的定位。
After that, it just a matter of getting the positioning on the page by altering the parameters for DrawImage
to suit.
DrawImage(gfx, imageLoc, 50, 50, 250, 250);
祝你好运!
这篇关于使用PDFSharp覆盖图像到PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!