如何将现有磁盘上PDF文件中的页面正确添加到当前生成的内存中PDF文档?
我们有一个使用iTextSharp生成PDF文档的类.这很好用.目前,我们在最后一页添加条款和条件作为图片:
this.nettPriceListDocument.NewPage();
this.currentPage++;
Image logo = Image.GetInstance("/inetpub/Applications/Trade/Reps/images/TermsAndConditions.gif");
logo.SetAbsolutePosition(0, 0);
logo.ScaleToFit(this.nettPriceListDocument.PageSize.Width, this.nettPriceListDocument.PageSize.Height);
this.nettPriceListDocument.Add(logo);
Run Code Online (Sandbox Code Playgroud)
我将此图像作为PDF文档,并希望附加它.如果我能解决这个问题,就可以将我们可能需要的其他PDF文档追加到我生成的内容中.
我试过了:
string tcfile = "/inetpub/Applications/Trade/Reps/images/TermsAndConditions.pdf";
PdfReader reader = new PdfReader(tcfile);
PdfWriter writer = PdfWriter.GetInstance(this.nettPriceListDocument, this.nettPriceListMemoryStream);
PdfContentByte content = writer.DirectContentUnder;
for (int pageno = 1; pageno < reader.NumberOfPages + 1; pageno++)
{
this.nettPriceListDocument.NewPage();
this.currentPage++;
PdfImportedPage newpage = writer.GetImportedPage(reader, pageno);
content.AddTemplate(newpage, 1f, 1f);
}
Run Code Online (Sandbox Code Playgroud)
这会导致"文档未打开"异常 writer.DirectContentUnder
我也尝试过:
string tcfile = "/inetpub/Applications/Trade/Reps/images/TermsAndConditions.pdf";
PdfReader reader = new PdfReader(tcfile);
PdfConcatenate concat = new PdfConcatenate(this.nettPriceListMemoryStream);
concat.AddPages(reader);
Run Code Online (Sandbox Code Playgroud)
这导致在文档的通常第一页上插入空白的,奇怪大小的页面.
我也尝试过:
string tcfile = "/inetpub/Applications/Trade/Reps/images/TermsAndConditions.pdf"; …
Run Code Online (Sandbox Code Playgroud)