[
https://issues.apache.org/jira/browse/PDFBOX-3594?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15696258#comment-15696258
]
Tilman Hausherr commented on PDFBOX-3594:
-----------------------------------------
Thank you for your investigation and your excellent report, which makes it much
easier for us. The cause is that the /limits entries in the file are not
sorted. I've made a change so that the branch is always searched if the limits
are bad.
Here's the output I get now (I've changed your code to output the page number)
{code}
sb.append("[page ").append(document.getPages().indexOf(page)).append("]");
{code}
{code}
POD® HD500 アドバンスド・ガイド[page 0]
1 - 概要[page 4]
ホーム・ビュー[page 4]
チューナー・モード[page 6]
タップ・テンポ[page 7]
接続[page 7]
POD HD500エディット・ソフトウエア[page 8]
2 - システム・セットアップ[page 10]
システム・セットアップへアクセスする[page 10]
ページ 1、Setup:Utilities[page 11]
ページ 2、Setup:Utilities[page 12]
ページ 3、Setup:Input[page 13]
ページ 4、Setup:Output[page 17]
ページ 5、Setup:S/PDIF Output[page 18]
ページ 6、MIDI/Tempo[page 19]
ページ 7、Setup:Variax[page 20]
ページ8、James Tyler Variax Tuning Options[page 25]
ページ9、Setup:L6 LINK Audio [page 26]
ページ10、Setup:L6 LINK Control[page 27]
{code}
You can get a snapshot here within a few hours:
https://repository.apache.org/content/groups/snapshots/org/apache/pdfbox/pdfbox-app/2.0.4-SNAPSHOT/
> Use PDOutlineItem#findDestinationPage() cannot get PDPage, return was null
> --------------------------------------------------------------------------
>
> Key: PDFBOX-3594
> URL: https://issues.apache.org/jira/browse/PDFBOX-3594
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 1.8.12, 2.0.3
> Environment: Java 8
> Reporter: kohdai
> Assignee: Tilman Hausherr
> Fix For: 1.8.13, 2.0.4, 2.1.0
>
>
> h3. Overview
> I try to extract Bookmarks of a PDF, but I could not get a destination page.
> h3. PDF
> http://www.line6.jp/products/pod-hd-x/img-pod-hd-x-resource/pod-hd-500x-advanced-guide.pdf
> h3. Code
> {code:title=main.PDFBookmarkExtractor.java|borderStyle=solid}
> package main;
> import java.io.File;
> import java.io.IOException;
> import org.apache.pdfbox.pdmodel.PDDocument;
> import org.apache.pdfbox.pdmodel.PDPage;
> import
> org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDDocumentOutline;
> import
> org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineItem;
> import
> org.apache.pdfbox.pdmodel.interactive.documentnavigation.outline.PDOutlineNode;
> public class PDFBookmarkExtractor {
> public static void main(String args[]) throws Exception {
> PDFBookmarkExtractor extractor = new PDFBookmarkExtractor();
> extractor.extract();
> }
> public void extract() {
> File pdf = new File("pod-hd-500x-advanced-guide.pdf");
> try (PDDocument document = PDDocument.load(pdf)) {
> PDDocumentOutline outline =
> document.getDocumentCatalog().getDocumentOutline();
> this.getBookmarks(document, outline);
> } catch(IOException e) {
> e.printStackTrace();
> }
> }
> private void getBookmarks(PDDocument document, PDOutlineNode
> outlineNode) throws IOException {
> PDOutlineItem current = outlineNode.getFirstChild();
> while(current != null) {
> this.getBookmark(document, current, 0);
> current = current.getNextSibling();
> }
> }
> private int getBookmark(PDDocument document, PDOutlineItem current, int
> indentCount) throws IOException {
> PDPage page = current.findDestinationPage(document);
> StringBuilder sb = new StringBuilder();
> for(int i=0; i<indentCount; i++) {
> sb.append("\t");
> }
> sb.append(current.getTitle());
> sb.append("[").append(page).append("]");
> System.out.println(sb);
> if(current.hasChildren()) {
> for(PDOutlineItem child : current.children()) {
> this.getBookmark(document, child, indentCount +
> 1);
> }
> }
> return indentCount;
> }
> }
> {code}
> h3. Result
> {noformat}
> POD® HD500 アドバンスド・ガイド[org.apache.pdfbox.pdmodel.PDPage@5910e440]
> 1 - 概要[null]
> ホーム・ビュー[null]
> チューナー・モード[null]
> タップ・テンポ[null]
> 接続[null]
> POD HD500エディット・ソフトウエア[null]
> 2 - システム・セットアップ[org.apache.pdfbox.pdmodel.PDPage@26a1ab54]
> システム・セットアップへアクセスする[org.apache.pdfbox.pdmodel.PDPage@26a1ab54]
> ページ 1、Setup:Utilities[org.apache.pdfbox.pdmodel.PDPage@3d646c37]
> ページ 2、Setup:Utilities[org.apache.pdfbox.pdmodel.PDPage@41cf53f9]
> [...snip...]
> {noformat}
> h3. Problem
> I think PDNameTreeNode#getValue has problems.
> {code:title=org.apache.pdfbox.pdmodel.common.PDNameTreeNode.java|borderStyle=solid}
> /**
> * The name to retrieve.
> *
> * @param name The name in the tree.
> * @return The value of the name in the tree.
> * @throws IOException If an there is a problem creating the destinations.
> */
> public T getValue( String name ) throws IOException
> {
> T retval = null;
> Map<String, T> names = getNames();
> if( names != null )
> {
> retval = names.get( name );
> }
> else
> {
> List<PDNameTreeNode<T>> kids = getKids();
> if (kids != null)
> {
> for( int i=0; i<kids.size() && retval == null; i++ )
> {
> PDNameTreeNode<T> childNode = kids.get( i );
> // [Problem] Cannot get retval.
> // Because "kids" were not sorted by name
> if( childNode.getLowerLimit().compareTo( name ) <= 0 &&
> childNode.getUpperLimit().compareTo( name ) >= 0 )
> {
> retval = childNode.getValue( name );
> }
> }
> }
> else
> {
> LOG.warn("NameTreeNode does not have \"names\" nor \"kids\"
> objects.");
> }
> }
> return retval;
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]