java - Bookmarks imbalance when rotating pdf page -
i'm building pdf multiple tables. of them wider usual, have rotate several pages (put them in landscape) in order see whole table comfortably.
the problem is: when rotate document landscape, bookmarks generated point delayed (more or less) 1 page. it's not 1 page, there imbalaced, i've been able workaround shifting bookmarks 1 page back.
at biggining tried rotate document while being written. tried open both writings (portrait , landscape) in separated documents, merging them 1 final document bookmarks. (bad) result same in both cases.
here code use it:
bytearrayoutputstream baos = new bytearrayoutputstream(); bytearrayoutputstream baoslandscape = new bytearrayoutputstream(); bytearrayoutputstream baostotal = new bytearrayoutputstream(); pdfcopyfields copier = new pdfcopyfields(baostotal); copier.setviewerpreferences(pdfwriter.pagemodeuseoutlines); document document = new document(pagesize.a4, 72, 48, 48, 24); pdfwriter writer = pdfwriter.getinstance(document, baos); writer.setviewerpreferences(pdfwriter.pagemodeuseoutlines); document.open(); // write tables in portrait document.close(); document documentlandscape = new document(pagesize.a4.rotate(), 48, 65, 71, 48); pdfwriter writerlandscape = pdfwriter.getinstance(documentlandscape, baoslandscape); documentlandscape.open(); // write tables in landscape documentlandscape.close(); pdfreader reader = new pdfreader(baos.tobytearray()); list bookmarks = simplebookmark.getbookmark(reader); copier.adddocument(reader); pdfreader readerlandscape = new pdfreader(baoslandscape.tobytearray()); list bookmarkslandscape = simplebookmark.getbookmark(readerlandscape); copier.adddocument(readerlandscape); // here correct delay landscape bookmarks simplebookmark.shiftpagenumbers(bookmarkslandscape, reader.getnumberofpages()-1, null); bookmarks.addall(bookmarkslandscape); copier.setoutlines(bookmarks); copier.close(); return baostotal;
but, mentioned before, not 1 page, , in end bookmarks not exact like.
have of faced problem before? solution that? or doing wrong?
thanks in advance!
p.s.: forgot mention generating bookmarks creating chapter , sections (a bookmark generated per each section) inside and, finally, adding chapter document:
paragraph titulo = new paragraph("title", mytitlefont); titulo.setspacingafter(20f); chapter chapter = new chapter(titulo, 5); chapter.setnumberdepth(0); section section = null; for(int = 0; < max; i++){ paragraph tablename = new paragraph("table " + i, myfont); section = chapter.addsection(10f, tablename, i); section.setnumberdepth(0); // generate eventstable eventstable.setspacingbefore(10f); eventstable.setspacingafter(20f); section.add(eventstable); section.newpage(); section.setcomplete(true); } chapter.setcomplete(true); document.add(chapter);
@gayolomao, not sure if helps, ran similar problem. when set bookmark on landscape page (located after portrait page), shows 1 page later.
here's how set bookmarks portrait page, works great portrait pages (although, when used landscape page, bookmark shows on start of 2nd landscape page):
document.newpage(); sect = "chapter 1 title"; sectionbookmark=new pdfoutline(root, new pdfdestination(pdfdestination.fith, writer.getverticalposition(true)), sect); document.add(new paragraph(lead, sect, stylechaptertitle));
and here's how modified bookmark @ top of first landscape page located after portrait page:
document.setpagesize(pagesize.a4.rotate()); // landscape document.newpage(); sect="chapter 2 title"; sectionbookmark=new pdfoutline(root, new pdfdestination(pdfdestination.fith,0),sect); // use 0 on landscape pages trigger bookmark @ top of page document.add(new paragraph(lead, sect, stylechaptertitle));
Comments
Post a Comment