Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add watermark and signature to existing pdf #68

Open
harabbi opened this issue Mar 18, 2020 · 1 comment
Open

Add watermark and signature to existing pdf #68

harabbi opened this issue Mar 18, 2020 · 1 comment

Comments

@harabbi
Copy link

harabbi commented Mar 18, 2020

I've been trying to take an existing PDF file, add a watermark to it ("downloaded by X user at time Y"), modify the metadata, and then sign the file with my existing RSA key, but I can't for the life of me get it to work.

I'm using Prawn and CombinePDF to add watermark to the file because I couldn't get the watermark to write to the pages, and when I tried to create a new PDF with "fresh" metadata, the metadata from the parsed file always came through.

Also, I'm not trying to write the file to disk, I just want to pass it as a stream using Rails' send_data, so I've got some of the process worked out, but can't figure out the rest. Should this block work?

def generate_signed_pdf(original_pdf_path)
    info = {
      Title: 'this is my title',
      RetrievedBy: 'some user'
    }
    pdf = Origami::PDF.read(original_pdf_path)
    pdf.each_page do |page|
      page.write('This is my add on', x: 100, y: 10, rendering: Origami::Text::Rendering::FILL, size: 10)
    end
    pdf.create_metadata(info)
    pdf.sign(cert, key) # cert and key exist, just edited down the block a bit
    buffer = StringIO.new
    pdf.write(buffer)
    buffer.rewind
    buffer
end
@UniqueTokens
Copy link

The last row should be
buffer.read

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants