我正在使用下面提到的代码。由于某些原因,我无法将图像保存在输出PDF中。有什么我想念的吗?
string imageFileName = Path.Combine(Application.StartupPath, "a.jpg");
var inputpdf = Path.Combine(Application.StartupPath, "b.pdf");
var outputpdf = Path.Combine(Application.StartupPath, "output.pdf");
using (Stream inputPdfStream = new FileStream(inputpdf, FileMode.Open, FileAccess.Read,
FileShare.Read))
{
using (Stream inputImageStream = new FileStream(imageFileName, FileMode.Open,
FileAccess.Read, FileShare.Read))
{
var reader = new PdfReader(inputPdfStream);
var stamper = new PdfStamper(reader, new FileStream(outputpdf, FileMode.Create),
'\0', true);
var pdfContentByte = stamper.GetOverContent(1);
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(inputImageStream);
image.SetAbsolutePosition(10, 10);
pdfContentByte.AddImage(image);
stamper.Close();
}
}