Skip to content

Instantly share code, notes, and snippets.

@dwarring
Last active May 11, 2021 01:28
Show Gist options
  • Save dwarring/1e4e056d84d6fe125262bba1da1f58fb to your computer and use it in GitHub Desktop.
Save dwarring/1e4e056d84d6fe125262bba1da1f58fb to your computer and use it in GitHub Desktop.
#!/usr/bin/env raku
use PDF::IO::Reader;
#| strip non-deterministic data from ps2pdf output.
#| Ensure multiple runs produce exactly the same binary output
#| see https://www.mail-archive.com/debian-user@lists.debian.org/msg763682.html
sub MAIN(
Str $file-in, #= input PDF
Str $file-out = $file-in, #= output PDF (optional)
Str :$id = "wôBÚ¦Ø峧\x[9D]¡tõpÍ\x[16]",
) {
CATCH {
when X::PDF { note .message; exit 1; }
}
my PDF::IO::Reader $reader .= new.open($file-in);
given $reader.trailer {
.<ID> = [$id, $id];
with .<Info> {
.<CreationDate>:delete;
.<ModDate>:delete;
}
with .<Root> {
.<Metadata>:delete;
}
}
$reader.save-as($file-out, :rebuild);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment