简体   繁体   English

如何使用 C# 将图像插入 pdf 文档?

[英]How to insert an image into a pdf document with C#?

I m searching for a way with a free dll library modify a pdf.我正在寻找一种使用免费 dll 库修改 pdf 的方法。 I want to insert an image to a certain position into a pdf document.我想将图像插入到 pdf 文档的某个位置。

I already found iTextSharp, but this only add a page before my document.我已经找到了 iTextSharp,但这只会在我的文档之前添加一个页面。

How do I insert an image to specific position?如何将图像插入到特定位置?

var reader = new PdfReader(inputPdfStream);
var stamper = new PdfStamper(reader, outputPdfStream);
var pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
iTextSharp.text.Rectangle r_01 = new iTextSharp.text.Rectangle(30,10);
PdfContentByte page1 = stamper.GetOverContent(1);
image.SetAbsolutePosition(0,0);
page1.AddImage(image);
stamper.Close();

ITextSharp is a good one, and you can actually add images to existing pages. ITextSharp 是一个不错的选择,您实际上可以将图像添加到现有页面。 We use it to auto-generate our product templates and add QR codes.我们使用它来自动生成我们的产品模板并添加二维码。

See Darin Dimitrov's answer here: How can I insert an image with iTextSharp in an existing PDF?请在此处查看 Darin Dimitrov 的回答: 如何在现有 PDF 中使用 iTextSharp 插入图像?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM