HOW TO Produce printable documents
Clone this wiki locally
If you want your users to be able to print Plomino documents, you can just let them use the Plone print function.
Note: if this function is not visible in your Plone site, go to ZMI / portal_actions / document_actions / print, check Visible, and save. The Print action will be displayed in the bottom-right corner of the content area.
The Plone print function allows to print the current page and as Plone provides some print-specific CSS, the rendering is correct (navigation, portlets, background, etc., are all removed, so the printed document only contains the content itself).
Nevertheless in some cases, you might need to change the document content itself for printing (for instance, if some parts of the Plomino documents are dynamic, or you prefer to hide some of the fields, etc.).
To do so, you need to create a Plomino form that will produce the print-specific layout. You can create it from scratch (and then just make sure you create fields having the very same ids as the fields from the original form), or you can just copy/paste your original form (go to your database contents tab, and then copy/paste the form) and then change its layout and/or its fields settings.
Let's assume your regular form is frmEmployee, and your print-specific form is frmEmployeePrint.
If you open an employee document using its regular url, like this:
it is displayed using the form it has been created with, in our case: frmEmployee.
If you want to display it with the frmEmployeePrint form, you can use the openwithform url parameter:
It does display the same document but the layout is the one implemented by frmEmployeePrint.
So, to provide access to the printable version of a document, we need to generate such alink into the frmEmployee form.
We do it using a computed for display rich text field having the following formula:
html="""<a href="%s?openwithform=frmEmployeePrint" target="_new">Print</a>""" % context.doc_url() return html
Note: we add target="_new" so the resulting page is opened in a new tab in the user web browser.
And now you just need to make sure the web browser print function is called as soon as the user open this page.
You do it by adding a computed for display rich text field in frmEmployeePrint:
html="""<script> this.print(); </script>""" return html
Note: the resulting print uses the Plone print-specific CSS, but if you do not want that, you can use the /OpenBareDocument directive that will only return the Plomino form layout only:
This way you can control entirely the print layout independently from Plone.
The sample can be downloaded here.