简体   繁体   中英

Itextsharp pdfwriter copy page

I have a method that creates a pdf file from a database, each page having information from a record of database. I use a pdfWriter object to create the file.

Can I copy each page from pdfWriter after the page is created in my method and write the page in another separate pdf file? The result will be like splitting the pdf file.

Can I copy each page from pdfWriter after the page is created in my method and write the page in another separate pdf file? The result will be like splitting the pdf file.

No.

The PdfWriter is not accumulating everything you add to it, it writes out the data as early as possible to its output stream. So it quite likely does never even contain a whole page you want to get from it.

Furthermore, it does not have methods to allow such content retrievable. PdfWriter is designed as a data-sink only, not a data source.

But you can read the output of the writer using a new PdfReader instance and copy pages from there.

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