OK, I've found a solution for that:) I've downloaded v1.3.6 from CVS and this functionality works, and also there is no problem with big files. So perfect for me.
But, if you want, I can check in which version of iText it doesn't work. Thanks, Mariusz Mariusz Pala wrote: > Thanks Paulo for your help, but still I have no idea how to write a code > to agglutinate all the destinations and add it to the catalog. > As I sad before, it was working with old iText (from early 2005 release). > I was trying to compare source code to investigate why it stop working, > but unfortunalety without success. > Could you give me some example how to do it? > > Thanks in advance. > > Mariusz > > > Mariusz Pala wrote: > >> Paulo Soares wrote: >> >> >>>> Yes, I've already done it, but named destinations are still >>>> not copied, >>>> it was working with (very) old version of iText for sure. >>>> >>>> >>>> >>> What version? >>> >>> >>> >> I only know that is from 2005.03.14 >> >> >>> >>> >>> >>>> I've found that my problem is connected with >>>> http://threebit.net/mail-archive/itext-questions/msg02256.html - >>>> unfortunately without answer. >>>> >>>> >>>> >>>> >>> It doesn't have an answer because it's application specific. Not >>> everything is already done the way we want it. >>> >>> >>> >>> >>>> So my question is: is there any way to merge named destinations (with >>>> PdfCopy)? >>>> >>>> >>>> >>>> >>> Yes but you have to write code to aglutinate all the destinations and >>> add them to the catalog. >>> >>> Paulo >>> >>> >>> >> Ok, but how to do it? Some example maybe? >> >> Thanks, >> Mariusz >> >> >>> >>> >>> >>>> Thanks, >>>> Mariusz >>>> >>>> Paulo Soares wrote: >>>> >>>> >>>> >>>>> Named destinations were never supported in PdfCopy, what >>>>> >>>>> >>>>> >>>> you can do is >>>> >>>> >>>> >>>>> call PdfReader.consolidateNamedDestinations() to replace >>>>> >>>>> >>>>> >>>> all the local >>>> >>>> >>>> >>>>> named links with the actual destinations. >>>>> >>>>> Paulo >>>>> >>>>> >>>>> >>>>> >>>>> >>>>>> -----Original Message----- >>>>>> From: [EMAIL PROTECTED] >>>>>> [mailto:[EMAIL PROTECTED] On >>>>>> Behalf Of Mariusz Pala >>>>>> Sent: Friday, February 23, 2007 11:18 AM >>>>>> To: [email protected] >>>>>> Subject: [iText-questions] Problem with ToC in PDF after >>>>>> merging usingPdfCopy >>>>>> >>>>>> >>>>>> Hi, >>>>>> I have a problem with ToC links in documents. >>>>>> Everything is fine after creating Toc using function below, >>>>>> ToC is created >>>>>> with links and that links work. >>>>>> >>>>>> This is part of my code: >>>>>> >>>>>> public static int addTableOfContents(File pdfFile, >>>>>> String tocTitle, int >>>>>> additionalPageOffset) throws Exception { >>>>>> >>>>>> PdfReader reader = new PdfReader(pdfFile.toString()); >>>>>> List bookmarks = SimpleBookmark.getBookmark(reader); >>>>>> if (bookmarks == null || bookmarks.size()==0) return 0; >>>>>> >>>>>> File fileResult = UtilEx.createTempFile(FormatEx.PDF); >>>>>> >>>>>> // step 1: creation of a document-object >>>>>> Document document = new Document(); >>>>>> PdfWriter writer = PdfWriter.getInstance(document, new >>>>>> FileOutputStream(fileResult)); >>>>>> document.open(); >>>>>> generateTableOfContents(document, null, >>>>>> bookmarks, tocTitle, 0, false); >>>>>> document.close(); >>>>>> writer.close(); >>>>>> PdfReader tmpReader = >>>>>> PdfUtils.getPdfReader(fileResult.toString()); >>>>>> int tocPageOffset = tmpReader.getNumberOfPages(); >>>>>> tmpReader.close(); >>>>>> >>>>>> try { >>>>>> fileResult.delete(); >>>>>> fileResult.createNewFile(); >>>>>> } catch (Exception e) {} >>>>>> writer.close(); >>>>>> >>>>>> document = new Document(); >>>>>> writer = PdfWriter.getInstance(document, new >>>>>> FileOutputStream(fileResult)); >>>>>> document.open(); >>>>>> >>>>>> iterateBookmarks(bookmarks, tocPageOffset); >>>>>> >>>>>> /** >>>>>> * in this method I'm creating ToC with >>>>>> something like this: >>>>>> chunk.setLocalGoto("page"+pageDestination); >>>>>> */ >>>>>> generateTableOfContents(document, writer, >>>>>> bookmarks, tocTitle, >>>>>> additionalPageOffset, true); >>>>>> >>>>>> int pageOfCurrentReaderPDF = 0; >>>>>> >>>>>> PdfImportedPage page = null; >>>>>> PdfContentByte cb = writer.getDirectContent(); >>>>>> while (pageOfCurrentReaderPDF < >>>>>> reader.getNumberOfPages()) { >>>>>> document.newPage(); >>>>>> pageOfCurrentReaderPDF++; >>>>>> >>>>>> document.setPageSize(reader.getPageSizeWithRotation(pageOfCurr >>>>>> entReaderPDF)); >>>>>> page = writer.getImportedPage(reader, >>>>>> pageOfCurrentReaderPDF); >>>>>> if (page != null) >>>>>> cb.addTemplate(page, 0, 0); >>>>>> >>>>>> PdfDestination d1 = new >>>>>> PdfDestination(PdfDestination.FIT); >>>>>> >>>>>> writer.getDirectContent().localDestination("page" + >>>>>> (pageOfCurrentReaderPDF + additionalPageOffset), d1); >>>>>> } >>>>>> document.close(); >>>>>> writer.close(); >>>>>> >>>>>> reader = new PdfReader(fileResult.toString()); >>>>>> PdfStamper stamper = new PdfStamper(reader, new >>>>>> BufferedOutputStream(new >>>>>> FileOutputStream(pdfFile))); >>>>>> stamper.setOutlines(bookmarks); >>>>>> stamper.close(); >>>>>> reader.close(); >>>>>> >>>>>> return tocPageOffset; >>>>>> } >>>>>> >>>>>> >>>>>> But! After merging this file with some other, links in ToC >>>>>> are broken, I get >>>>>> an error in Acrobat that page tree node is invalid or >>>>>> something like this. >>>>>> Google doesn't know anything about this Acrobat message:) >>>>>> >>>>>> This is part of code after which the file (ToC) is broken: >>>>>> >>>>>> if (document == null) { >>>>>> // step 1: creation of >>>>>> a document-object >>>>>> document = new >>>>>> Document(reader.getPageSizeWithRotation(1)); >>>>>> // step 2: we create a >>>>>> writer that listens to the document >>>>>> writer = new >>>>>> PdfCopy(document, new >>>>>> FileOutputStream(tempFile.toString())); >>>>>> //temporary disabled >>>>>> >>>>>> writer.setViewerPreferences(PdfCopy.PageModeUseOutlines); >>>>>> // step 3: we open the document >>>>>> document.open(); >>>>>> } >>>>>> >>>>>> // step 4: we add content >>>>>> for (int j = 1; j <= numberPages; j++) { >>>>>> >>>>>> PdfImportedPage page = >>>>>> writer.getImportedPage(reader, j); >>>>>> if (page != null) { >>>>>> document.newPage(); >>>>>> writer.addPage(page); >>>>>> writer.flush(); >>>>>> } >>>>>> } >>>>>> >>>>>> So I've found out that the problem is because in PdfCopy file >>>>>> merging method >>>>>> named destination are not copied. I have to use PdfCopy, >>>>>> cause I have to >>>>>> merge also AcroForms. But is there any way to make it work? >>>>>> >>>>>> I have to say, that in old version of iText (I don't remember >>>>>> exact version) >>>>>> this piece of code was working! >>>>>> But I've encountered problem with big files, and I've decided >>>>>> to use new >>>>>> iText. Big files work fine, but there is a problem with links >>>>>> in ToC - named >>>>>> destinations merging. >>>>>> >>>>>> Please help me.. >>>>>> >>>>>> Thanks in advance, >>>>>> Mariusz >>>>>> >>>>>> >>>>>> >>> Aviso Legal: >>> Esta mensagem é destinada exclusivamente ao destinatário. Pode conter >>> informação confidencial ou legalmente protegida. A incorrecta transmissão >>> desta mensagem não significa a perca de confidencialidade. Se esta mensagem >>> for recebida por engano, por favor envie-a de volta para o remetente e >>> apague-a do seu sistema de imediato. É proibido a qualquer pessoa que não o >>> destinatário de usar, revelar ou distribuir qualquer parte desta mensagem. >>> >>> Disclaimer: >>> This message is destined exclusively to the intended receiver. It may >>> contain confidential or legally protected information. The incorrect >>> transmission of this message does not mean the loss of its confidentiality. >>> If this message is received by mistake, please send it back to the sender >>> and delete it from your system immediately. It is forbidden to any person >>> who is not the intended receiver to use, distribute or copy any part of >>> this message. >>> >>> >>> >>> ------------------------------------------------------------------------ >>> >>> ------------------------------------------------------------------------- >>> Take Surveys. Earn Cash. Influence the Future of IT >>> Join SourceForge.net's Techsay panel and you'll get the chance to share your >>> opinions on IT & business topics through brief surveys-and earn cash >>> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >>> ------------------------------------------------------------------------ >>> >>> _______________________________________________ >>> iText-questions mailing list >>> [email protected] >>> https://lists.sourceforge.net/lists/listinfo/itext-questions >>> Buy the iText book: http://itext.ugent.be/itext-in-action/ >>> >>> >>> >> ------------------------------------------------------------------------- >> Take Surveys. Earn Cash. Influence the Future of IT >> Join SourceForge.net's Techsay panel and you'll get the chance to share your >> opinions on IT & business topics through brief surveys-and earn cash >> http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV >> _______________________________________________ >> iText-questions mailing list >> [email protected] >> https://lists.sourceforge.net/lists/listinfo/itext-questions >> Buy the iText book: http://itext.ugent.be/itext-in-action/ >> >> >> >> > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > iText-questions mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/itext-questions > Buy the iText book: http://itext.ugent.be/itext-in-action/ > > > ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ iText-questions mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
