fschutt / printpdf

An easy-to-use library for writing PDF in Rust
https://docs.rs/printpdf/
MIT License
777 stars 95 forks source link

Adds escape hatch for pages to add annotations #141

Closed nubis closed 9 months ago

nubis commented 1 year ago

Hi,

I need to apologize in advance for making this PR overlooking all the contributing guidelines.

Take it as the beginning of a discussion rather than something I expect you to merge right away.

This is the only PDF generation library I found that supports custom fonts, unicode and SVG out of the box, but I was only missing annotations because I need to put links on my PDFs.

2 hours ago I had no idea how PDF works internally, but looking at your code and the output from other PDF libraries I made a scape hatch to lopdf in the Page struct, so that it can be extended with arbitrary PDF dictionaries.

I added a specific example adding a link to some text because from all the different types of annotations, I think links may be the most useful.

Maybe it's something that can be kept around until there's a proper implementation for all the missing features, at which point people should stop using this error-prone variant and instead use specific functions that do the type checking.

Thanks for the great work.

fschutt commented 1 year ago

Yeah, I can see what this is doing, it's good to have escape hatches but I'm not sure I'll merge it like this, would be better to support it properly to make sure that users can't generate broken PDFs.

nubis commented 1 year ago

I figured as much :)

I'll try to get some help, or I will do it myself sometime during the next 2 weeks.