From 785035627115e1547c7ef748dc38c5c8f5c89cce Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Fri, 31 Mar 2017 22:34:30 -0700 Subject: [PATCH] startxref --- pitfall/pitfall/render.rkt | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/pitfall/pitfall/render.rkt b/pitfall/pitfall/render.rkt index 87794952..50263efe 100644 --- a/pitfall/pitfall/render.rkt +++ b/pitfall/pitfall/render.rkt @@ -35,9 +35,19 @@ (cons (cons (co-io-idx cosexpr) offset) io-locs) io-locs)))) (define trailer-str (car bstrs)) - (define other-strs (cdr bstrs)) - (define result (apply bytes-append `(,@(reverse other-strs) ,(make-xref-table locs) ,trailer-str #"\n%%EOF"))) + (define other-bstrs (cdr bstrs)) + (define last-offset (for/sum ([bstr (in-list other-bstrs)]) + (bytes-length bstr))) + (define result (apply bytes-append `(,@(reverse other-bstrs) + ,(make-xref-table locs) + ,trailer-str + #"\nstartxref\n" + ,(string->bytes/latin-1 (number->string last-offset)) + #"\n%%EOF"))) (display result) + (let ([op (open-output-file (expand-user-path "~/Desktop/foo.pdf") #:exists 'replace)]) + (write-bytes result op) + (close-output-port op)) result) (define (cosexpr->bytes x)