I would like to add a dynamically generated text. Is there a way to watermark an existing PDF in Ruby?
相关问题
- Question marks after images and js/css files in ra
- Correctly parse PDF paragraphs with Python
- Using :remote => true with hover event
- Eager-loading association count with Arel (Rails 3
- Set BaseUrl of an existing Pdf Document
相关文章
- Ruby using wrong version of openssl
- Right way to deploy Rails + Puma + Postgres app to
- AWS S3 in rails - how to set the s3_signature_vers
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- How to add a JSON column in MySQL with Rails 5 Mig
- “No explicit conversion of Symbol into String” for
- form_for wrong number of arguments in rails 4
Use Ruport.
1st result for Googling
ruby pdf watermark
.Prawn doesn't support templates anymore...
Try the combine_pdf gem.
You can combine, watermark, page-number and add simple text to existing PDF files (including the creation of a simple table of contents without PDF links).
It's a very simple and basic PDF library, written in pure Ruby with no dependencies.
This example can fit your situation (it's from the readme file):
Check out Prawn(http://github.com/sandal/prawn) for just ruby and Prawnto(http://github.com/thorny-sun/prawnto) for Ruby on Rails.
You are probably going to want to either use the image embedding functionality or the background image functionality.
Here's an example of using a background image http://cracklabs.com/prawnto/code/prawn_demos/source/general/background
Another option is to use PDFTK. It can be used to add a watermark and create a new PDF. Maybe prawn will do the same thing with it's templating.
pdftk in.pdf background arecibo.pdf output wmark1.pdf
Some more info: http://rhodesmill.org/brandon/2009/pdf-watermark-margins/
There is a ruby wrapper gem called active_pdftk which supports backgrounding, so you don't have to do the shell commands yourself.
This will do it:
PDF::Reader
to count the number of pages in the file.Prawn
to create a new PDF document using each page of the input pdf as a template.However, in my testing the output file size was huge with the latest Gem version of Prawn (0.12), but after pointing my Gemfile at the master branch on github, all worked fine.