gdelugre / origami

Origami is a pure Ruby library to parse, modify and generate PDF documents.
GNU Lesser General Public License v3.0
326 stars 110 forks source link

Is it possible to change the PDF version of a file? #43

Closed davidalejandroaguilar closed 5 years ago

davidalejandroaguilar commented 6 years ago

Went through the Rubydoc documentation but couldn't find anything related to it, but I've could've missed it. Is it possible?

KDGundermann commented 6 years ago

what exactly do you want to achive? The Pdf Version is indicated in the first bytes of the file: %PDF-1.3 sure you may change it to: %PDF-1.7

gdelugre commented 6 years ago

As far as I know, this number is just ignored by any PDF viewer. However Origami automatically generates the version number in order to be compliant, based on the objects that compose the document. Have you found a case where this causes breakage?

If your only goal is to modify this number in a document, I think it's much simpler to just modify the single byte in the file header rather than loading a full PDF parser/generator like Origami.

gdelugre commented 5 years ago

Alternative solution is to modify it like:

pdf.header.minor_version = 5 # will set version 1.5
pdf.save "doc.pdf"

But that's overly expensive as it will recompile the entire document while you could do it just by overwriting a single byte. I am closing this issue now.