Hello,
I have already send this question yesterday but somehow text is
not appearing in the post so again sending this.Please find the file said
below from yesterday's post with same subject. I have created a PDF with
bookmarks which is working fine. but then as per
http://itextsharp.sourceforge.net/examples/Chap0112.cs
example i have re arranged the page and copied the bookmarks from the
original page. But after doing that bookmarks are displayed in bookmark
section but not working.
i.e. when i click on the bookmark it does not go to that page. I have
attached both file. In 1000115.pdf bookmarks are working. then i created the
Chap0112.pdf using link above where bookmark doesn't work.Please help.
Here is my code which rearrange the 1000115.pdf to generate Chap0112.pdf.
Code:-
public static void main(String args[]) {
try { ArrayList bookmarks = new ArrayList();
// we create a reader for a certain document
PdfReader reader = new PdfReader("D:/memory/1000115.
pdf");
// we retrieve the total number of pages
int n = reader.getNumberOfPages();
// we retrieve the size of the first page
Rectangle psize = reader.getPageSize(1);
float width = psize.getWidth();
float height = psize.getHeight();
// step 1: creation of a document-object
Document document = new Document(PageSize.A4, 9.36f, 9.36f,
24.48f, 24.48f);
// step 2: we create a writer that listens to the document
PdfWriter writer = PdfWriter.getInstance(document, new
FileOutputStream("D:/memory/Chap0112.pdf",true));
// step 3: we open the document
document.open();
// step 4: we add content
PdfContentByte cb = writer.getDirectContent();
bookmarks.addAll(SimpleBookmark.getBookmark(reader));
SimpleBookmark.shiftPageNumbers(bookmarks, 0,
null);
int i = 0;
int p = 0;
System.out.println("There are " + n + " pages in the
document.");
while (i < n) {
document.newPage();
p++;
i++;
PdfImportedPage page1 = writer.getImportedPage(reader, i);
//cb.addTemplate(page3, .5f, 0, 0, .5f, 0, height / 2);
cb.addTemplate(page1, .5f, 0, 0, .5f, 0,
0);//Actual
System.out.println("processed page " + i);
if (i < n) {
i++;
PdfImportedPage page2 = writer.getImportedPage(reader,
i);
//cb.addTemplate(page2, .5f, 0, 0, .5f, width / 2,
height / 2);
cb.addTemplate(page2, .5f, 0, 0,
.5f, (width / 2), 0);
System.out.println("processed page " + i);
}
if (i < n) {
i++;
PdfImportedPage page3 = writer.getImportedPage(reader,
i);
//cb.addTemplate(page3, .5f, 0, 0, .5f, 0, 0);
cb.addTemplate(page3, .5f, 0, 0,
.5f, 0, (height / 2));//actual
System.out.println("processed page " + i);
}
if (i < n) {
i++;
PdfImportedPage page4 = writer.getImportedPage(reader,
i);
//cb.addTemplate(page4, .5f, 0, 0, .5f, width / 2, 0);
cb.addTemplate(page4, .5f, 0, 0,
.5f, (width / 2), (height / 2));
System.out.println("processed page " + i);
}
BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA,
BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
cb.beginText();
cb.setFontAndSize(bf, 14);
cb.endText();
}
writer.setOutlines(bookmarks);
// step 5: we close the document
document.close();
}
catch (Exception de) {
de.printStackTrace();
}
}
------------------------------------------------------------------------------
_______________________________________________
iText-questions mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/itext-questions
Buy the iText book: http://www.itextpdf.com/book/
Check the site with examples before you ask questions:
http://www.1t3xt.info/examples/
You can also search the keywords list: http://1t3xt.info/tutorials/keywords/