简体   繁体   中英

Merging documents with itextsharp

I am not experienced with iTextSharp and have this need:

I have generated 2 PDFs:

  • 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). The pdf is generated to a memory stream.

  • a bigger one (ie size A3). I want to "copy" or embed the little pdf to the bigger in a fixed position.

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.

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 .

  • Open the document with the small page in a PdfReader readerA
  • Open the document with the big page in a PdfReader readerB
  • Create a PdfStamper stamperB for readerB
  • Import the page from readerA using stamperB.GetImportedPage
  • Add this imported page object to the exisiting target page using stamperB.OverContent.AddTemplate ; this method allows to supply positioning coordinates
  • close the stamperB , then the readers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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