Just as simple as that !
You are absolutely right Julien ... I have tried it, and the bookmarks now
appear and work fine in Mac "Preview" :)
And thanks a lot Andreas for your suggestion.
Best regards ,
Hesham
---------------------------------------------
Included message :
Then try to pdfBookmarks.openNode() after (maybe be before works too)
pdfFile.getDocumentCatalog().setDocumentOutline( pdfBookmarks ) and it
should be ok.
Julien
Le 25 oct. 2010 à 09:08, "Hesham G." <[email protected]> a écrit :
Okay ... Here you go a sample code :
I brought a PDF file that has no bookmarks at all:
http://www.4shared.com/document/YhsIX4Fg/pdf_with_no_bookmarks.html
Then using the following code i defined 3 bookmarks nodes to it. I then
opened the output PDF in windows Adobe reader & the bookmarks worked
fine, then I tried it on Mac's "Preview" program, but the bookmarks do
not appear.
Here is the output PDF:
http://www.4shared.com/document/wK8SzJsW/pdf_after_adding_bookmarks.html
My code :
*
private void noBookmarksButtonActionPerformed() {
List<PDPage> allPages = new ArrayList<PDPage>();
// Load the PDF bookmarks in the From list :
try {
String pdfPath = "C:\\pdf_with_no_bookmarks.pdf";
PDDocument pdfFile = PDDocument.load( pdfPath );
PDDocumentOutline pdfBookmarks = new PDDocumentOutline (); //
Create a new bookmarks tree.
pdfFile.getDocumentCatalog().getPages().getAllKids (
allPages ); // All kids will be added to allPages.
// Initialize some bookmarks :
PDOutlineItem bookmark1 = new PDOutlineItem();
PDOutlineItem bookmark2 = new PDOutlineItem();
PDOutlineItem bookmark3 = new PDOutlineItem();
// Define the bookmarks properties :
bookmark1.setTitle( "Go to page 3" );
bookmark1.setDestination( allPages.get( 2 ) );
bookmark2.setTitle( "Go to page 20" );
bookmark2.setDestination( allPages.get( 19 ) );
bookmark3.setTitle( "Go to page 30" );
bookmark3.setDestination( allPages.get( 29 ) );
// Insert the bookmarks nodes in the bookmarks tree :
pdfBookmarks.appendChild( bookmark1 );
pdfBookmarks.appendChild( bookmark2 );
pdfBookmarks.appendChild( bookmark3 );
// Insert the bookmarks tree in the PDF :
pdfFile.getDocumentCatalog().setDocumentOutline (
pdfBookmarks );
// Save & Close the PDF
pdfFile.save( pdfPath );
pdfFile.close();
System.out.println( "Bookmarks tree added successfully ...
Time to try this PDF's bookmarks on Mac." );
} catch (IOException e) {
e.printStackTrace();
} catch (COSVisitorException e) {
e.printStackTrace();
}
}
Best regards ,
Hesham
---------------------------------------------
Included message :
Hesham,
My partner used my code to translate table of contents into bookmarks
on PDFs for some times now and never reported such a thing. (he uses
both Preview -sorry, I though like Bonjour that apple was getting into
internationlizing French words ;)- and acrobat pro)
Would you put your code so that I may compare it to mine.
Regards,
Julien
Le 24 oct. 2010 à 23:31, "Hesham G." <[email protected]> a é crit
:
I think this answer will not convince my customers :)
Ok, I hope someone would check this. If i can give any help, I'd be
delighted.
Best regards ,
Hesham
---------------------------------------------
Included message :
Not necessarily a bug in PDFBox. Preview on the Mac is not the same
thing as Acrobat, and has some bugs and shortcomings. One needs to
determine whether specs or standards have been violated by PDFBox or
by Preview.
On Oct 24, 2010, at 4:09 PM, Hesham G. wrote:
Ok ... Now that is more clear :)
I have tried this on more than 1 PDF, and they did the same thing
(The bookmarks appear and work fine in Windows, but do not appear
in Mac).
So is this considered a bug in PDFBox ?
I can give you a sample code here if you like for writing such
bookmarks.
Best regards ,
Hesham
---------------------------------------------
Included message :
Hello Hesham,
Sorry for that, I can be a bit messy sometimes. I meant that the
first
debugging exectution provided the same results as you (in Aperçu,
didn't try on Windows).
Then, I added an instruction like outlineItem.openNode() where
outlineItem is the PDDocumentOutline object.
Aperçu then understands that there is an outline attached to the
document. I don't know if it feets the specs but works like this.
Regards,
Julien PLÉE
Le 24 oct. 10 à 18:41, Hesham G. a écrit :
Thanks Julian for your reply.
Sorry, I do not understand your answer ! Do you mean the bookmarks
appeared fine to you in Mac ?
Best regards ,
Hesham
---------------------------------------------
Included message :
Hello Hesham,
I had the same result in Aperçu at the beginning. I di dn't tried
to
open it in Windows, I did instead "open" the bookmark root after
adding the bookmarks to it and it did well.
Regards
Julien PLÉE
Le 24 oct. 10 à 17:04, Hesham G. a écrit :
Hello ,
I have created a new PDF book using PDFBox, copied pages to it
from
another PDF, then I defined a new bookmarks tree for it
normally as
specified here : http://www.pdfbox.org/userguide/ bookmarks.html
The output PDF works perfect in Windows, and the bookmarks work
great.
But when I opened the same PDF in Mac OS X using the default PDF
viewer(Called 'Preview')... The PDF worked fine, but no
bookmarks
appear in it. Here is a PDF sample so you can test it :
http://www.4shared.com/document/99lLOhb0/PDF_with_PDFBox_bookmarks_that.html
You will see the bookmarks appear fine in Windows, but it does
not
appear at all in Mac. Any idea what is wrong ?
Best regards ,
Hesham