pdftk agenda.pdf dump_data | grep NumberOfPages
- Create a bookmarks.txt file with your outline/bookmarks definitions:
BookmarkBegin
BookmarkTitle: Agenda
BookmarkLevel: 1
BookmarkPageNumber: 1
BookmarkBegin
BookmarkTitle: Proclamation #1
BookmarkLevel: 1
BookmarkPageNumber: 5
- Run pdftk command on pdf to add them:
run pdftk input.pdf update_info bookmarks.text ouptut pdf_with_outline.pdf
pdftotext
install with:
OSX: brew install poppler
LINUX: sudo apt-get install poppler-utils
https://stackoverflow.com/a/28857418/85359
You can use pdftotext -layout some.pdf some.txt
to create a file containing the text from your PDF. (This does not work reliably. Some PDFs, for example those which are missing a valid /ToUnicode table, will not lend themselves readily to text extraction.)
This can lead you to the page number for a match.
Using (with some trial'n'error) pdftotext -f 33 -l 33 -layout -x NN -y MM -W NN -H MM
can narrow down the location of your match on page 33 more exactly.
Using pdftotext -layout -bbox -f 33 -l 33
will return the coordinates of the bounding boxes for each word on page 33.
You could use TET, the Text Extraction Toolkit to find the exact coordinates of matching words too. TET can give you the coordinates of individual glyphs even.
- First need to find the location of the Rectangle that you want to draw the link at
First example:
https://stackoverflow.com/a/4674664/85359
gswin32c.exe ^ -o with-hyperlink.pdf ^ -sDEVICE=pdfwrite ^ -c "[ /Rect [0 425 295 465]" ^ -c " /Border [0 0 2]" ^ -c " /Color [.7 0 0]" ^ -c " /Page 1" ^ -c " /Action <</Subtype /URI" ^ -c " /URI (http://stackoverflow.com/questions/4663409/creating-a-pdf-hyperlink-with-postscript/4674664#4674664)>>" ^ -c " /Subtype /Link" ^ -c " /ANN pdfmark" ^ -f without-hyperlink.pdf
Second example:
https://stackoverflow.com/a/12884081/85359
-o output.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress original.pdf script.ps
Postscript code saved in script.ps:
[ /Rect [10 10 50 50]
/Page 2
/SrcPg 1
/Subtype /Link
/ANN pdfmark
pdfmark Primer ^ Search for 'pdfmark Primer' (chapter 6) ^
adding bookmarks to pdfs with pdfmark
[ /Title (Some Bookmark)
/Page 2
/Count 1
/View [/XYZ null null 0]
/OUT pdfmark
gs -o [outputfilename] -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress [originalPDFfilename] [pdfmarkfillename]
https://thechriskent.com/2017/02/13/applying-pdfmark-to-pdf-documents-using-ghostscript/
https://thechriskent.com/2017/03/06/setting-pdf-view-options-with-pdfmark/
[ /PageMode /UseOutlines
/Page 1
/View [/Fit]
/DOCVIEW pdfmark
gs -o [outputfilename] -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress [originalPDFfilename] [pdfmarkfillename]