Question

I have a rails project that I'm using wicked_pdf to generate PDFs from generated html and I'm appending a slick footer to each page of that pdf. A lot of these pages to pdfs are actually coming from parsed word .doc or .txt files and then I convert them to PDF with this footer upon download.

But... PDFs are also being uploaded to the system and although not parsed and displayed in the application I need them upon download to have the footer as the other files above. Is there anyway to do this?

I don't need to edit anything in the PDF, just need to add this footer.

Thanks a bunch!

Was it helpful?

Solution

If it is already a PDF, then wicked_pdf won't help you here, but you might be able to use Prawn or PDFtk.

You can layer some content on top of the bottom area of each page of an existing pdf with the following:

require 'prawn'
require 'pdf-reader'

respond_to do |format|
  format.pdf {
    input_filename = Rails.root.join('input.pdf')

    page_count = PDF::Reader.new(input_filename).page_count

    file = Prawn::Document.new(:skip_page_creation => true) do |pdf|

      page_count.times do |num|
        pdf.start_new_page(:template => input_filename, :template_page => num+1)
        pdf.move_down(700)
        pdf.text('FOOTER TEXT')
      end

    end
    send_data file.render
  }
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top