[cl-typesetting-devel] An interesting problem from a neophyte...
Robert L. Read
read at robertlread.net
Mon Jan 21 17:51:24 UTC 2008
Sure, you can use (defmethod write-document ((s stream) &optional
> (document *document*)) to write to a string:
>
> (with-output-to-string (s)
> (pdf:with-document ()
> ...
> (pdf:write-document s)))
>
> Marc
Unfortunately, this fails for me on SBCL 1.0.13, with the following
error. Below this trace is an example of what I am doing with
flexi-streams, which seems to work, but is hideous (function
"third-doc").
It seems likely that some change in SBCL's stream typing has lead to
this error. I have also tried removing :pdf-binary from *features*. I
notice in config.lisp that for sbcl the +external-format+ is set
to :latin-1, which seems a bit antiquated, in that SBCL is now fully
unicode-compatible.
#<SB-IMPL::STRING-OUTPUT-STREAM {100475E241}> is not a binary output
stream.
[Condition of type SIMPLE-TYPE-ERROR]
Restarts:
0: [ABORT] Return to SLIME's top level.
1: [TERMINATE-THREAD] Terminate this thread (#<THREAD
"repl-thread" {10031A8D31}>)
Backtrace:
0: (SB-KERNEL:ILL-BOUT #<SB-IMPL::STRING-OUTPUT-STREAM {100475E241}>)
1: (WRITE-BYTE 66 #<SB-IMPL::STRING-OUTPUT-STREAM {100475E241}>)
2: ((SB-PCL::FAST-METHOD PDF::WRITE-STREAM-CONTENT (STRING))
#<unavailable argument>
#<unavailable argument>
"BT
0.0 829.0 Td
/CLF101 12.00 Tf
100.0 Tz
[ (Gener) 10 (ated) -278 (with) -278 (Cl-Pdf) -278 (and) -278
(Cl-typesetting) -31419 ] TJ
ET
BT ..)
3: ((SB-PCL::FAST-METHOD PDF::WRITE-OBJECT (PDF::PDF-STREAM))
#<unavailable argument>
#S(SB-PCL::FAST-METHOD-CALL
:FUNCTION #<FUNCTION #>
:PV NIL
:NEXT-METHOD-CALL #S(SB-PCL::FAST-METHOD-CALL
:FUNCTION #
:PV NIL
:NEXT-METHOD-CALL NIL
:ARG-INFO (1 . T)) ..))
4: ((SB-PCL::FAST-METHOD PDF::WRITE-OBJECT (PDF::INDIRECT-OBJECT))
#<unused argument>
#<unused argument>
#<PDF::INDIRECT-OBJECT {1003853061}>
T)
5: ((LAMBDA ()))
6: (SB-IMPL::%WITH-STANDARD-IO-SYNTAX #<CLOSURE (LAMBDA #)
{10029FEF79}>)
7: ((SB-PCL::FAST-METHOD PDF:WRITE-DOCUMENT (STREAM))
#<unused argument>
#<unused argument>
#<SB-IMPL::STRING-OUTPUT-STREAM {100475E241}>
#<PDF::DOCUMENT {100245C801}>)
8: (FOURTH-DOC)
(defmethod flexi-streams::stream-write-char ((imo
flexi-streams::in-memory-output-stream) c)
(format t "trying to write: ~A~%" c)
(format t "trying to type: ~A~%" (type-of c))
(flexi-streams::stream-write-byte imo (char-code c))
)
(defun third-doc ()
(let ((str
(flexi-streams::make-in-memory-output-stream :element-type :character)))
(tt:with-document
()
(let ((content (tt:compile-text
()
(tt:paragraph () "Generated with Cl-Pdf and Cl-typesetting")
(tt::with-style (:font "Helvetica" :font-size 8)
(tt:paragraph () "Spudalicious")
)
)))
(tt:draw-pages content)
(when pdf:*page* (typeset:finalize-page pdf:*page*))
(tt:write-document str))
)
(let ((output (make-string-output-stream)))
(loop for obj across (flexi-streams::get-output-stream-sequence
str) do
(if (typep obj 'character) (write-char obj output) (write-char
(code-char obj) output)))
(get-output-stream-string output)
)
))
(defun fourth-doc ()
(with-output-to-string (str)
(tt:with-document
()
(let ((content (tt:compile-text
()
(tt:paragraph () "Generated with Cl-Pdf and Cl-typesetting")
(tt::with-style (:font "Helvetica" :font-size 8)
(tt:paragraph () "Spudalicious")
)
)))
(tt:draw-pages content)
(when pdf:*page* (typeset:finalize-page pdf:*page*))
(tt:write-document str))
)
str)
)
More information about the cl-typesetting-devel
mailing list