Paul wrote:
Hi,
is it possible to re-open a pdf file as save it in different parts ?
In my case, I will produce a full pdf document but in some cases, I would like
to re-open it and save only a few number of pages in a new pdf file.
Yes, this is possible.
When you say re-open, you should think of PdfReader and use the method
selectPages:
http://itextdocs.lowagie.com/docs/com/lowagie/text/pdf/PdfReader.html#selectPages(java.lang.String)
See also
http://itextdocs.lowagie.com/docs/com/lowagie/text/pdf/SequenceList.html
if you want to know how to select a sequence of pages.
Use PdfReader in combination with PdfStamper or PdfCopy to save the
selection.
This is generally the best solution:
PdfReader reader = new PdfReader("complete.pdf");
PdfStamper stamper = new PdfStamper(reader, new
FileOutputStream("selected_pages.pdf"));
reader.selectPages("4-9, !8");
stamper.close();
This will create a new PDF with pages 4, 5, 6, 7 and 9 (not 8!).
If you want to compose a PDF built from page selections of different PDF
files,
you can use PdfCopy. Note that you can lose some interactive features
with PdfCopy
(there are ways to concatenate the outline tree, but that's advanced
matter).
PdfReader reader = new PdfReader("complete.pdf");
reader.selectPages("4-9, !8");
int pages = reader.getNumberOfPages();
Document document = new Document();
copy = new PdfCopy(document, new
FileOutputStream("selected_pages_plus.pdf"));
document.open();
for (int i = 0; i < pages; ) {
++i;
copy.addPage(copy.getImportedPage(reader, i));
}
document.close();
br,
Bruno
-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions