boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 155 forks source link

How to set the pdf-metadata? #150

Closed schulle877 closed 5 years ago

schulle877 commented 5 years ago

Thanks for that great gem. I sucessfully combined 2 pdf-files. My problem is, the original pdf-files have metadata, that I want to have in the resulting document. It is enough to take the metadata from the first file. Especially the title, subject, author and creator are important. I think this is important for others too.

schulle877 commented 5 years ago

Found the solution by myself...

[10] pry(main)> pdf.info[:Producer]
=> "Ruby CombinePDF 1.0.15 Library"
[11] pry(main)> pdf.info[:Producer]="My Producer"
=> "My Producer"
[12] pry(main)> pdf.save "test.pdf"
=> 412788

The same is possible with:

pdf.info[:Author]
pdf.info[:Creator]
pdf.info[:Title]
pdf.info[:Subject]
boazsegev commented 5 years ago

I'm happy you found a solution, I hope this means the documentation isn't that bad ;-)

I decided not to copy the original file's metadata, since it would raise a lot of questions when combining files with different metadata.

Also, altering the PDF might render the data invalid... I figured this was something we each needed to decide for our own.

I hope you understand my concerns and my choice about this.

Good luck with your project and happy new year!