Forum How do I...?

Same input, same output

dima
Hi,

We are generating PDFs and need to do snapshot/golden tests against the content but prince generates different content for the same HTML on every invocation.

The diff is around this:
/ID [<E738F1AB3F55406098BD9478A7D62FEA> <E738F1AB3F55406098BD9478A7D62FEA>]>>


But the document has no encryption in which case this seems to be optional.

Is there a way to be able to always generate consistent output for the same input HTML?

Thanks.

mikeday
You can use the --pdf-id option to specify a fixed ID, or you can diff the files and exclude any lines beginning with "/ID".
dima
Thanks, will give the --pdf-id a go.

But I didn't see it in the `prince --help`. Is there an "extended" help somewhere in the CLI or are those options only documented online in the docs?
dima
Can you please give any pointers on the format of the --pdf-id option? It doesn't appear there is any documentation on it.
mikeday
It specifies the PDF ID, for example --pdf-id="ABC" or empty string or whatever. This option is not recommended for general use but may be of help for test suites.
dima
Hi,

Can you please confirm the format of the --pdf-id is a valid hex and not a random string?

It appears that Prince is quietly ignoring invalid values and not failing which is a bit dangerous and we would rather see an error for the invalid input.

$ prince --pdf-id "ABCDEF0123456789" example.html -o - | grep --text '/ID'
/ID [<ABCDEF0123456789> <ABCDEF0123456789>]>>
/ID [<ABCDEF0123456789> <ABCDEF0123456789>]>>

$ prince --pdf-id "aa" example.html -o - | grep --text '/ID'
/ID [<AA> <AA>]>>
/ID [<AA> <AA>]>>

$ prince --pdf-id "xx" example.html -o - | grep --text '/ID'
/ID [<> <>]>>
/ID [<> <>]>>

$ prince --pdf-id "xx" --fail-safe example.html -o - | grep --text '/ID'
/ID [<> <>]>>
/ID [<> <>]>>
mikeday
Sorry it needs to be valid hexadecimal, yes. This hasn't been exposed as a public option yet.