main
Matthew Butterick 6 years ago
parent 8821fffd4f
commit f11dbfb02a

@ -30,8 +30,7 @@
(current-auto-first-page (hash-ref options 'autoFirstPage #t))
(current-doc-offset 0)
(field [doc-portal (open-output-bytes)]
[_pageBuffer null]
(field [_pageBuffer null]
[_offsets (mhasheqv)] ; The PDF object store
[_ended #f]
[ref-gen (generator ()
@ -52,7 +51,7 @@
'CreationDate (seconds->date (if (test-mode)
0
(current-seconds)) #f))] ; Initialize the metadata
[output-port #f]) ; for `pipe`
) ; for `pipe`
;; Initialize mixins
@ -70,7 +69,7 @@
(define bstr (if (not (bytes? x))
(string->bytes/latin-1 (string-append x "\n"))
x))
(write-bytes bstr doc-portal)
(write-bytes bstr)
(current-doc-offset (+ (current-doc-offset) (bytes-length bstr))))
(define/public (addPage [options-arg options])
@ -107,9 +106,6 @@
(define/public (_refEnd aref)
(hash-set! _offsets (· aref id) (· aref offset)))
(define/public (pipe port)
(set! output-port port))
(define/public (end) ; called from source file to finish doc
(flushPages)
@ -150,14 +146,7 @@
'Info _info)))
(write "startxref")
(write (number xref-offset))
(write "%%EOF")
;; end the stream
;; in node you (@push null) which signals to the stream
;; to copy to its output port
;; here we'll do it manually
(write-bytes (get-output-bytes doc-portal) output-port)
(close-output-port output-port))
(write "%%EOF"))
; if no 'info key, nothing will be copied from (hash)
(for ([(key val) (in-hash (hash-ref options 'info (hash)))])

@ -27,7 +27,7 @@
(define-macro (check-copy-equal? THIS)
(syntax/loc caller-stx (check-true (for/and ([b1 (in-input-port-bytes (open-input-file THIS))]
[b2 (in-input-port-bytes (open-input-file (this->control THIS)))])
(equal? b1 b2)))))
(equal? b1 b2)))))
(define-syntax-rule (check-pdfkit? this)
@ -36,10 +36,12 @@
(define (make-doc ps [compress? #false] [proc (λ (doc) doc)] #:test [test? #t] #:pdfkit [pdfkit? #t])
(time
(let ()
(define doc (make-object PDFDocument (hash 'compress compress?)))
(send doc pipe (open-output-file ps #:exists 'replace))
(proc doc)
(send doc end)))
(define f (open-output-file ps #:exists 'replace))
(parameterize ([current-output-port f])
(define doc (make-object PDFDocument (hash 'compress compress?)))
(proc doc)
(send doc end))
(close-output-port f)))
(when test?
(check-pdfs-equal? ps (this->control ps))
(when pdfkit?

Loading…
Cancel
Save