PDFUnit comes with the utility ExtractBookmarks
which exports bookmarks from PDF documents into an XML file.
Chapter 3.5: “Bookmarks and Named Destinations”
describes how to use this created XML file for bookmark tests.
:: :: Extract bookmarks from a PDF document into an XML file :: @echo off setlocal set CLASSPATH=./lib/aspectj-1.8.7/*;%CLASSPATH% set CLASSPATH=./lib/bouncycastle-jdk15on-153/*;%CLASSPATH% set CLASSPATH=./lib/commons-collections4-4.1/*;%CLASSPATH% set CLASSPATH=./lib/commons-logging-1.2/*;%CLASSPATH% set CLASSPATH=./lib/pdfbox-2.0.0/*;%CLASSPATH% set CLASSPATH=./lib/pdfunit-2016.05/*;%CLASSPATH% set TOOL=com.pdfunit.tools.ExtractBookmarks set OUT_DIR=./tmp set IN_FILE=diverseContentOnMultiplePages.pdf set PASSWD= java %TOOL% %IN_FILE% %OUT_DIR% %PASSWD% endlocal
The output file _bookmarks_diverseContentOnMultiplePages.out.xml
can be used a an information base for tests:
<?xml version="1.0" encoding="utf-8"?> <bookmarks> <bookmark label="Content on first page." page="1" /> <bookmark label="Content on page 2." page="2" /> <bookmark label="Content on page 3." page="3" /> <bookmark label="Content on last page." page="4" /> </bookmarks>