I have investigated further... and I have added already a
PDPageXYZDestination to my PDF file. But I have some issues/questions:
1.- I would like to add a destination pointing to a specific String. I
got COString reference but, I don't know how to find its X, Y coords.
Any help?
2.- When I open my new PDF file with Adobe Acrobat (not Reader) and I
show all the defined destinations, I can't see the names... I have to
click right button on top of where theoretically they should be listed,
select rename and then, "magically" the name appears. Any idea? Perhaps
I am creating the PDPageXYZDestination with wrong data.
Here is the piece of code I used to create and add my test destination
(it is based on Kevin piece of code).
Note: It is working with a PDF which already has destinations defined...
it is important because I think if there is no destinations already
defined this piece of code will crash.
Any comment on it?
PDDocument document = PDDocument.load("D:\\dev\\PDFOpenParameters.pdf",
false);
PDDocumentCatalog log = document.getDocumentCatalog();
PDDocumentNameDictionary dic = log.getNames();
PDDestinationNameTreeNode dests = dic.getDests();
PDPageXYZDestination d = new PDPageXYZDestination();
d.setLeft(500);
d.setTop(500);
d.setPageNumber(0);
List<PDNameTreeNode> destList = dests.getKids();
Map<String, Object> destList2 = destList.get(0).getNames();
Map<String, COSObjectable> newList = new HashMap<String, COSObjectable>();
Iterator<String> it = destList2.keySet().iterator();
while(it.hasNext())
{
String key = it.next();
newList.put(key,(COSObjectable)destList2.get(key));
}
newList.put("CHEMI",d);
destList.get(0).setNames(newList);
document.save("D:\\dev\\PDFOpenParameters2.pdf");
Thanks in advance,
Chemi.
On 7/18/2010 9:53 AM, Chemi wrote:
Hi, I would like to add named destinations to a PDf file.
Reading Adobe Reader documentation
(http://partners.adobe.com/public/developer/en/acrobat/PDFOpenParameters.pdf),
it seems there is an open parameter called:
nameddest=name (Specifies a named destination in the PDF).
Such named destination seems not to be a bookmark but a different
thing. I have reviewed PDFBox docs and was not able to fund such named
destination concept.
Do you know if it is possible to add named destinations to a PDF file
using PDFBox library?
Thanks in advance,
Chemi.