简体   繁体   English

使用itextsharp合并文档

[英]Merging documents with itextsharp

I am not experienced with iTextSharp and have this need: 我没有iTextSharp经验,并且有以下需求:

I have generated 2 PDFs: 我生成了2个PDF:

  • a small PDF (ie size A6) of one page containing 1 background image and some text in various format (paragraph, chunks, etc), some barcode some rectancles... But nothing more (no forms etc). 一页的小PDF(即A6大小),包含1个背景图像和一些各种格式的文本(段落,大块等),一些条形码,一些矩形……但是仅此而已(没有表格等)。 The pdf is generated to a memory stream. pdf生成到内存流。

  • a bigger one (ie size A3). 更大的一个(即A3尺寸)。 I want to "copy" or embed the little pdf to the bigger in a fixed position. 我想“复制”或将小pdf嵌入到固定位置。

How can I merge them? 如何合并它们? All examples I found use PDFReader , but I am not able to use it on a memory stream and I dont' like to save intermediate PDF to disk. 我发现的所有示例都使用PDFReader ,但是我无法在内存流上使用它,并且我不喜欢将中间PDF保存到磁盘。

You essentially want to stamp a page from one document somewhere onto the bigger page of another one. 本质上,您希望将一个文档中的某个页面标记到另一个文档的较大页面上。

This is a task for a PdfStamper . 这是PdfStamper的任务。

  • Open the document with the small page in a PdfReader readerA PdfReader readerA打开带有小页面的文档
  • Open the document with the big page in a PdfReader readerB PdfReader readerB打开带有大页面的文档
  • Create a PdfStamper stamperB for readerB PdfStamper stamperB创建一个PdfStamper stamperB readerB
  • Import the page from readerA using stamperB.GetImportedPage 使用stamperB.GetImportedPagereaderA导入页面
  • Add this imported page object to the exisiting target page using stamperB.OverContent.AddTemplate ; 使用stamperB.OverContent.AddTemplate将导入的页面对象添加到现有目标页面; this method allows to supply positioning coordinates 该方法允许提供定位坐标
  • close the stamperB , then the readers 关闭stamperB ,然后读者

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

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