[Seaside] Printing - via rendering to static HTML file and princeCSS?

Boris Popov boris at deepcovelabs.com
Fri Mar 14 14:50:00 UTC 2008

Here's a rough sketch of how we do it in-memory before feeding the XHTML
to PDFReactor for conversion (apologies for formatting),

| handler response |
handler := WARenderContinuation root: (PDFRoot for: self).
response := WAResponse new.
handler context: (WARenderingContext new session: self session;
actionUrl: WAUrl new; yourself).
handler processRendering: response.
^(PDFClient default convertXHTML: response contents contents) pDF.

This returns PDF bytes that you can send back to the client with
something like,

	downloadBytes: (self report asPDF: self contact)
	mime: 'application/pdf'
	filename: ('Accounts <1s>.pdf' expandMacrosWith: (Core.Date
today printUsing: 'yyyy-mm-dd')).

And here's all the other supporting stuff to make it work, its somewhat
specific to what we do, but you should get an idea anyway,

Component>>asPDF: contact
^self application rootComponent pdfSessionFor: contact do: [self asPDF]

RootComponent class>>pdfSessionFor: contact do: block
	sessionFor: contact
	do: block
	isPDF: true.

RootComponent class>>sessionFor: contact do: block isPDF: boolean
^WACurrentSession value
		[| session |
		session := (self sessionClass new)
						isPDF: boolean;
						setParent: self
						attachContact: contact;
			use: session
			during: block] ensure: [session expire]]
		[:session | 
		| old |
		old := session isPDF.
		session isPDF: boolean.
		block ensure: [session isPDF: old]].

PDFRoot class>>for: aComponent
^(self new)
	component: aComponent;

^Array with: component.

PDFRoot>>component: anObject
component := anObject.

renderContentOn: html
 html render: self component.

updateRoot: root
root initialize.
root beXhtml10Strict.
root style add: (Styles default documentForFile: 'print.css').
root style add: self session branding default print.
root style add: 'svg {-ro-replacedelement:

Component>>downloadBytes: bytes mime: mime filename: filename
| handler |
handler := WADocumentHandler document: bytes mimeType: mime fileName:
^self session returnResponse: handler response

Hope this helps,


DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5

boris at deepcovelabs.com


This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any

Thank you.
> -----Original Message-----
> From: seaside-bounces at lists.squeakfoundation.org [mailto:seaside-
> bounces at lists.squeakfoundation.org] On Behalf Of itsme213
> Sent: Friday, March 14, 2008 7:28 AM
> To: seaside at lists.squeakfoundation.org
> Subject: [Seaside] Printing - via rendering to static HTML file and
> princeCSS?
> How would I go about doing a #renderContentOn: run re-directed to a
> disk-based html file? I am looking for an easy way to print to nice
> and
> apparently
>   xhtml->Prince CSS
> is a good option.
> Any other suggestions welcome as well.
> Thanks - Sophie
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside

More information about the seaside mailing list