summaryrefslogtreecommitdiffstats
path: root/pdf-clobber-stamps.tl
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2021-07-17 19:11:20 -0700
committerKaz Kylheku <kaz@kylheku.com>2021-07-17 19:11:20 -0700
commita5ed04c903c17da953ce89ce41c785bc605751aa (patch)
treec96c8a8fe82af872d5492222499d80460b8fe4f4 /pdf-clobber-stamps.tl
parent613ad713e515d0bb0c8c90426194e10501beeaa9 (diff)
downloadtxr-a5ed04c903c17da953ce89ce41c785bc605751aa.tar.gz
txr-a5ed04c903c17da953ce89ce41c785bc605751aa.tar.bz2
txr-a5ed04c903c17da953ce89ce41c785bc605751aa.zip
doc: reproducible PDF.
* Makefile (txr-manpage.pdf): If SOURCE_DATE_EPOCH exists, then run pdf-clobber-stamps.tl. * pdf-clobber-stamps.tl: New file.
Diffstat (limited to 'pdf-clobber-stamps.tl')
-rw-r--r--pdf-clobber-stamps.tl22
1 files changed, 22 insertions, 0 deletions
diff --git a/pdf-clobber-stamps.tl b/pdf-clobber-stamps.tl
new file mode 100644
index 00000000..78ea06c6
--- /dev/null
+++ b/pdf-clobber-stamps.tl
@@ -0,0 +1,22 @@
+(let* ((epoch (or (tointz (getenv "SOURCE_DATE_EPOCH")) 0))
+ (pdf (file-get-string "txr-manpage.pdf"))
+ (start (search-str pdf "<?xpacket begin="))
+ (end (if start (search-str pdf "/Creator(" start)))
+ (xml (if end [pdf start..end]))
+ (orig-len (len xml))
+ (isotime (time-string-utc epoch "%FT%T"))
+ (gstime (time-string-utc epoch "%Y%m%d%H%M%SZ0000")))
+ (unless xml
+ (format *stderr* "XML block not found in PDF")
+ (exit nil))
+ (upd xml
+ (regsub #/uuid:........-....-....-....-............/
+ "uuid:00000000-0000-0000-0000-000000000000")
+ (regsub #/Date>....-..-..T..:..:..(Z|[+\-]..:..)/
+ (ret `Date>@isotime@(if (ends-with "Z" @1) "Z" "+00:00")`))
+ (regsub #/Date\(D:..............[Z+\-]..../
+ `Date(D:@gstime`))
+ (assert (eql (len xml) orig-len))
+ (set [pdf start..end] xml)
+ (file-put-string "txr-manpage.pdf.temp" pdf)
+ (rename-path "txr-manpage.pdf.temp" "txr-manpage.pdf"))