How do you combine PDFs in ruby?

前端 未结 8 2079
你的背包
你的背包 2020-12-25 15:17

This was asked in 2008. Hopefully there\'s a better answer now.

How can you combine PDFs in ruby?

I\'m using the pdf-stamper gem to fill out a form in a PDF.

8条回答
  •  無奈伤痛
    2020-12-25 15:46

    After a long search for a pure Ruby solution, I ended up writing code from scratch to parse and combine/merge PDF files.

    (I feel it is such a mess with the current tools - I wanted something native but they all seem to have different issues and dependencies... even Prawn dropped the template support they use to have)

    I posted the gem online and you can find it at GitHub as well.

    you can install it with:

    gem install combine_pdf
    

    It's very easy to use (with or without saving the PDF data to a file).

    For example, here is a "one-liner":

    (CombinePDF.load("file1.pdf") << CombinePDF.load("file2.pdf") << CombinePDF.load("file3.pdf")).save("out.pdf")
    

    If you find any issues, please let me know and I will work on a fix.

提交回复
热议问题