gdelugre / origami

Origami is a pure Ruby library to parse, modify and generate PDF documents.
GNU Lesser General Public License v3.0
326 stars 110 forks source link

Adding a FreeText annotation #59

Closed dvanderbeek closed 5 years ago

dvanderbeek commented 5 years ago

Is there anywhere in the documentation where I can find a basic example of adding a FreeText annotation to a page in a PDF? I have tried the following but do not see any text on the resulting document:

require 'origami'

pdf = Origami::PDF.read("templates/input.pdf")
page = pdf.get_page(1)

annot = Origami::Annotation::FreeText.new
annot.Contents = "Hello World"
annot.Rectangle = Origami::Rectangle[llx: 0, lly: 0, urx: 200, ury: 100]
page.add_annotation(annot)

pdf.save("documents/output.pdf")
dvanderbeek commented 5 years ago

I think the main problem was annot.Rectangle should be annot.Rect. It seems to work with that change, although then I am not able to add a digital signature to the particular file in question.