> Document document = new Document();
> try {
> PdfWriter writer =
> PdfWriter.getInstance(document,
> new
> FileOutputStream("toc.pdf"));
> document.open();
> PdfDestination dest = new
> PdfDestination(PdfDestination.FIT);
> Chunk chunk;
> Paragraph p;
> int pagenumbers = 8;
> for (int i=0;i<pagenumbers;) {
> ++i;
> chunk = new Chunk("Page "+i);
>
> chunk.setAction(PdfAction.gotoLocalPage(i, dest, writer));
> p = new Paragraph(chunk);
> document.add(p);
> }
> for (int i=0;i<pagenumbers;) {
> ++i;
> document.newPage();
> writer.setPageEmpty(false);
> }
> document.close();
I suspect the page has to exist before you can use it as a destination. Lets
have a look...
Yep.
http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/com/lowagie/text/pdf/PdfAction.java?revision=2526&view=markup:
457 public static PdfAction gotoLocalPage(int page, PdfDestination dest,
PdfWriter writer) {
458 PdfIndirectReference ref = writer.getPageReference(page);
459 dest.addPage(ref);
460 PdfAction action = new PdfAction();
461 action.put(PdfName.S, PdfName.GOTO);
462 action.put(PdfName.D, dest);
463 return action;
464 }
So the first thing it does is get a reference to the destination page. I'd
imagine that's a null the way your code is currently laid out.
It also looks like you'll want to use a seperate PdfDestination for each link:
"dest.addPage(ref);".
Yep again.
http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/com/lowagie/text/pdf/PdfDestination.java?revision=1733&view=markup:
213 public boolean addPage(PdfIndirectReference page) {
214 if (!status) {
215 addFirst(page);
216 status = true;
217 return true;
218 }
219 return false;
220 }
So only the first "addPage" will actually work... giving you the results you're
seeing.
--Mark Storer
Senior Software Engineer
Cardiff.com
#include <disclaimer>
typedef std::Disclaimer<Cardiff> DisCard;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
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/