gettalong / hexapdf

Versatile PDF creation and manipulation for Ruby
https://hexapdf.gettalong.org
Other
1.21k stars 69 forks source link

Output is non-deterministic #285

Closed gregorw closed 6 months ago

gregorw commented 7 months ago

We have a test case where we compare the generated PDF with a file on disk. Unfortunately, these two files never match due to the following differences:

 17 0 obj
-<</ModDate(D:20240214000000+01'00')/Producer(HexaPDF version 0.36.0)>>
+<</ModDate(D:20240131115730+01'00')/Producer(HexaPDF version 0.36.0)>>
 endobj
 xref
 0 18
@@ -120,7 +120,7 @@ xref
 0000009843 00000 n
 0000011337 00000 n
 trailer
-<</Root 3 0 R/ID[(�Q������#?n�n)(�Q������#?n�n)]/Info 17 0 R/Size 18>>
+<</Root 3 0 R/ID[(��/-kϸ2N�R<�R�)(��/-kϸ2N�R<�R�)]/Info 17 0 R/Size 18>>
 startxref
 11424
 %%EOF

Even if we freeze time using travel_to we get different outputs each time.

It would be great to have a deterministic output, i.e. the exact same output for the same input.

gettalong commented 7 months ago

Have a look at the comment here. It basically boils down to setting a fixed ID in the trailer and making sure to use update_fields: false when invoking HexaPDF::Document#write.

This should make the output deterministic. Please let me know if this doesn't work for you!

gregorw commented 6 months ago

It works!