Comments (4)
After some investigation I found this is how you do it:
509 0 obj
<<
/Parent 5 0 R
/Next 524 0 R
/Title (ir\056zig\056pdf)
/A 508 0 R
/Prev 505 0 R
>>
It seems like this is a doubly linked list with a prev and next (I think the object numbers, I dont really know anything about pdfs, this was just examining it with a text editor. /A
is actually the page it is referring (marked) to.)
Hopefully this gives more insight.
from printpdf.
Yeah, it's probably not that hard to implement, but I've not done it since it wasn't important for me. If you want to implement it, you'd probably want to start like this:
printpdf/src/types/pdf_layer.rs
Lines 124 to 133 in 1b0aa7a
I.e. .add_bookmark(page: &PdfPageId, text: &str)
The only difficulty is that you need to create the bookmark after the page that you're referencing has been created, plus you'd need access to the internal PDF object ID. Maybe instead of writing the bookmarks directly, just store all bookmarks as a HashMap and defer writing them until the document is being saved - because you can't really reference the PDF page until the document is actually written. Otherwise you're going to have a problem trying to reference a page whose PDF object ID hasn't yet been determined.
You need to insert a Reference to reference a page, otherwise refer to the Adobe PDF spec, it probably has some info on creating bookmarks.
from printpdf.
Thanks. Would the object I would want to use be Object::Dictionary(Dictionary)
from LoPdf to implement this feature?
You were right, the spec did have a feature for this .
Edit:
This feature is turning out harder than I thought. The main confusion point for me is where I insert the information. It does not seem like the font setting, because the font is a /Tf name size
, while this requires a whole new object (Dictionary) like this (listing the first, last, and how many bookmarks)
5 0 obj
<<
/Count 49
/First 6 0 R
/Last 1559 0 R
>>
endobj
plus an individual object for each bookmark
6 0 obj
<<
/Parent 5 0 R
/Title (astgen\056zig\056pdf)
/A 4 0 R
/Next 73 0 R
>>
endobj
If you could catch me up to speed on where exactly and what functions I should use to insert these "objects" that would be awesome!
from printpdf.
Dictionaries can be built from a Vec<(String, Object)>
, if you pass that to lopdf, it'll create a dictionary. See here:
printpdf/src/types/pdf_document.rs
Lines 327 to 332 in 1b0aa7a
(I've also noticed that Use0
is technically not a valid value, should be UseNone
instead). But basically you need to add a new ("Outlines", Reference(outline_dictionary))
to that /Catalog
, after the PageMode
You need to "reserve" a new object ID for the catalog with document.inner_doc.new_object_id()
, because it has to be an indirect reference, not a direct one. If you're not sure about how the final PDF should look like, one technique I like to do is to download PDFExplorer (see README) and open an existing PDF that already has working bookmarks, that way you know where to insert them.
from printpdf.
Related Issues (20)
- Add opacity to text HOT 1
- [Feature suggestion]Vertical text HOT 4
- Clarify function input units using Pt or Mm struct HOT 1
- target wasm32 is using stdweb HOT 3
- How To Use FontData for Calculating Width and Height of a Text HOT 2
- Hyperlinks HOT 5
- `write_text` function cannot use different font than used `use_text`
- Update dependencies
- `set_text_matrix(TextMatrix::Rotate(45.0))` rotate text only in its corner
- documenation is not updated with the changes in v 0.6.0 HOT 1
- Font example(and also normal pdfs) produce error in Adobe reader
- requires JavaScript for wasm builds
- get_font clones external font data everytime
- How can i end a pdf line before it overflows HOT 1
- Use differents layer to put text HOT 2
- Can't print image in pdf HOT 1
- Build error with target=wasm32-unknown-unknown HOT 5
- PDF file size is 3.5x bigger than its contents HOT 2
- Error building as wasm32-wasi target HOT 1
- Rotate text HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from printpdf.