You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Michel Cozzolino <mi...@gmail.com> on 2018/12/15 20:32:56 UTC
Re: outline pagedestination problem
Ciao Tilman,
while waiting for a "lorem ipsum" pdf (..still waiting...) I've resolved
the problem using findDestinationPage (below is the code).
the strange is that both methods current.action and current.destination
give null.
By exploring the pdf with PDFDebbugger as per your suggestions online, I
see actionGoto set on bookmarks.
Moreover the PDF has been created as an Arbortext export to pdf.
What do u think, could it be possible the pdf is malformed? (unfortunately
I don't have the permit to share it as it contains confidential infos)
Many thanks
here is my code (Kotlin):
val file = File("/home/miki/a/cover.pdf")
val document = PDDocument.load(file)
val outline = document.documentCatalog.documentOutline
val current = outline.firstChild.firstChild.nextSibling // testing
bookmark of para 2.1
println( current.getTitle())
//val gta = current.action as PDActionGoTo // is null
//val pd = current.destination as PDPageDestination //is null too
val pd = current.findDestinationPage(document) //as PDPageDestination
val allpages = document.getDocumentCatalog().pages
var pageNumber = allpages.indexOf(pd)+1
println("Destination page: " + pageNumber )
document.close()
On Tue, 27 Nov 2018 at 16:35, Michel Cozzolino <mi...@gmail.com>
wrote:
> Ciao Tilman,
>
> as it's a reserved document, I've asked them to get a sort of "lorem
> ipsum" pdf built in the very same manner that can be shared with the pdfbox
> community.
> Still waiting for it. As I get the file I'll share it with you.
> Many thanks for your availability.
> ciao
>
> Michele
>
>
> On Sun, 25 Nov 2018 at 11:33, Tilman Hausherr <TH...@t-online.de>
> wrote:
>
>> Hi,
>> please upload the PDF somewhere. Most attachments are not allowed here.
>> Tilman
>>
>> Am 25.11.2018 um 11:14 schrieb Michel Cozzolino:
>> > Hi,
>> > I'm a newbie on PDFBOX. I've to extract bookmarks and relevant
>> > destination pages from customer generated pdfs. All the pdf files have
>> > the very same structure.
>> > Opening such pdf in a pdf reader I see the bookmarks with pages.
>> >
>> >
>> > image.png
>> >
>> > But looking for page-destination in both PageDestination and
>> > ActionGoto modes, results in error. In fact both the following "if"
>> > statements result false:
>> > (Kotlin code)
>> > val document: /PDDocument/= load(file)val outline:/PDDocumentOutline!/
>> = document.documentCatalog.documentOutline var current: PDOutlineItem? =
>> outline.firstChild if
>> > (current.destination is PDPageDestination) --> results _false_ if
>> > (current.action is PDActionGoTo) --> results _false_ too
>> > current.title --> results the _correct_ value
>> > what am I doing wrong? Is there other way pdf store bookmark page
>> > destinations?
>> > Is there a way to analyse the structure of the "current" object?
>> > Thanks for help!
>> >
>> > Michele
>> >
>>
>>
Re: outline pagedestination problem
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 15.12.2018 um 21:46 schrieb Tilman Hausherr:
>
> However all this means that I the example code should be improved to
> include named destinations.
The example has now been improved, here's the new method. But you using
findDestinationPage() is fine too.
public void printBookmark(PDDocument document, PDOutlineNode
bookmark, String indentation) throws IOException
{
PDOutlineItem current = bookmark.getFirstChild();
while( current != null )
{
// one could also use current.findDestinationPage(document)
to get the page number,
// but this example does it the hard way to explain the
different types
// Note that bookmarks can also do completely different
things, e.g. link to a website,
// or to an external file. This example focuses on internal
pages.
if (current.getDestination() instanceof PDPageDestination)
{
PDPageDestination pd = (PDPageDestination)
current.getDestination();
System.out.println(indentation + "Destination page: " +
(pd.retrievePageNumber() + 1));
}
else if (current.getDestination() instanceof
PDNamedDestination)
{
PDPageDestination pd =
document.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination)
current.getDestination());
if (pd != null)
{
System.out.println(indentation + "Destination page:
" + (pd.retrievePageNumber() + 1));
}
}
else if (current.getDestination() != null)
{
System.out.println(indentation + "Destination class: "
+ current.getDestination().getClass().getSimpleName());
}
if (current.getAction() instanceof PDActionGoTo)
{
PDActionGoTo gta = (PDActionGoTo) current.getAction();
if (gta.getDestination() instanceof PDPageDestination)
{
PDPageDestination pd = (PDPageDestination)
gta.getDestination();
System.out.println(indentation + "Destination page:
" + (pd.retrievePageNumber() + 1));
}
else if (gta.getDestination() instanceof
PDNamedDestination)
{
PDPageDestination pd =
document.getDocumentCatalog().findNamedDestinationPage((PDNamedDestination)
gta.getDestination());
if (pd != null)
{
System.out.println(indentation + "Destination
page: " + (pd.retrievePageNumber() + 1));
}
}
else
{
System.out.println(indentation + "Destination
class2: " + gta.getDestination().getClass().getSimpleName());
}
}
else if (current.getAction() != null)
{
System.out.println(indentation + "Action class: " +
current.getAction().getClass().getSimpleName());
}
System.out.println( indentation + current.getTitle() );
printBookmark( document, current, indentation + " " );
current = current.getNextSibling();
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org
Re: outline pagedestination problem
Posted by Tilman Hausherr <TH...@t-online.de>.
Am 15.12.2018 um 21:32 schrieb Michel Cozzolino:
> Ciao Tilman,
>
> while waiting for a "lorem ipsum" pdf (..still waiting...) I've resolved
> the problem using findDestinationPage (below is the code).
> the strange is that both methods current.action and current.destination
> give null.
> By exploring the pdf with PDFDebbugger as per your suggestions online, I
> see actionGoto set on bookmarks.
> Moreover the PDF has been created as an Arbortext export to pdf.
> What do u think, could it be possible the pdf is malformed? (unfortunately
> I don't have the permit to share it as it contains confidential infos)
> Many thanks
>
> here is my code (Kotlin):
>
> val file = File("/home/miki/a/cover.pdf")
> val document = PDDocument.load(file)
>
> val outline = document.documentCatalog.documentOutline
>
> val current = outline.firstChild.firstChild.nextSibling // testing
> bookmark of para 2.1
>
> println( current.getTitle())
>
>
> //val gta = current.action as PDActionGoTo // is null
>
> //val pd = current.destination as PDPageDestination //is null too
I don't know that language, but is "current.action as PDActionGoTo" a
cast that returns null if it fails? Then you would never know if one of
the two is not null, but the cast fails.
I looked at findDestinationPage(). It could be that your destination is
not a PDPageDestination but a PDNamedDestination. See the source code of
findDestinationPage().
However all this means that I the example code should be improved to
include named destinations.
Tilman
>
> val pd = current.findDestinationPage(document) //as PDPageDestination
>
>
> val allpages = document.getDocumentCatalog().pages
> var pageNumber = allpages.indexOf(pd)+1
>
>
> println("Destination page: " + pageNumber )
>
> document.close()
>
>
>
> On Tue, 27 Nov 2018 at 16:35, Michel Cozzolino <mi...@gmail.com>
> wrote:
>
>> Ciao Tilman,
>>
>> as it's a reserved document, I've asked them to get a sort of "lorem
>> ipsum" pdf built in the very same manner that can be shared with the pdfbox
>> community.
>> Still waiting for it. As I get the file I'll share it with you.
>> Many thanks for your availability.
>> ciao
>>
>> Michele
>>
>>
>> On Sun, 25 Nov 2018 at 11:33, Tilman Hausherr <TH...@t-online.de>
>> wrote:
>>
>>> Hi,
>>> please upload the PDF somewhere. Most attachments are not allowed here.
>>> Tilman
>>>
>>> Am 25.11.2018 um 11:14 schrieb Michel Cozzolino:
>>>> Hi,
>>>> I'm a newbie on PDFBOX. I've to extract bookmarks and relevant
>>>> destination pages from customer generated pdfs. All the pdf files have
>>>> the very same structure.
>>>> Opening such pdf in a pdf reader I see the bookmarks with pages.
>>>>
>>>>
>>>> image.png
>>>>
>>>> But looking for page-destination in both PageDestination and
>>>> ActionGoto modes, results in error. In fact both the following "if"
>>>> statements result false:
>>>> (Kotlin code)
>>>> val document: /PDDocument/= load(file)val outline:/PDDocumentOutline!/
>>> = document.documentCatalog.documentOutline var current: PDOutlineItem? =
>>> outline.firstChild if
>>>> (current.destination is PDPageDestination) --> results _false_ if
>>>> (current.action is PDActionGoTo) --> results _false_ too
>>>> current.title --> results the _correct_ value
>>>> what am I doing wrong? Is there other way pdf store bookmark page
>>>> destinations?
>>>> Is there a way to analyse the structure of the "current" object?
>>>> Thanks for help!
>>>>
>>>> Michele
>>>>
>>>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org