开发者

Return to the first page using iTextSharp

Question

Using iTextSharp, can I skip over the first page of the document, and then return back to it later.

Details

I am creating a report. I want to provide the 'details' of the report on pages 2, 3, etc. After building the details, I will then have the summary information. Now I need to return to page 1 and print the summary.

Note: I am using DirectConent to write to the pdf.

Thoughts

Do I have to create the pdf with details on page 1. Then save the pdf. Then create a summary pdf. Then merge the two p开发者_如何学Pythondfs together?

That sounds complicated. I would love to be able to just return back to page 1 while creating the document.


You have to build the summary and details and merge them together. Maybe.

If you're using a Document and a PdfWriter, as soon as you call document.newPage() everything for that page is flushed to the output stream (file memory, whatever), and can't be changed unless you re-parse & modify it with another Reader & Writer

OTOH, if you use a stamper and create empty pages, you're free to process them in any order, but you need a "seed" pdf to start with. I'm pretty sure stampers can delete pages too, so the initial page size is irrelevant. The only downside to this is the metadata's "creation date" will show the date from the seed pdf.

And you can trivially whip up a seed pdf in iText.

Document doc = new Document();
PdfWriter writer = new PdfWriter(doc, outputStream);
doc.setPageEmpty(false);
doc.close();

I don't recommend rebuilding the seed every time, but you certainly could.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜