Print News to pdf

by Pedro Barbosa last modified Dec 30, 2008 05:51 PM

How to print news to pdf using Plone2pdf

Purpose

This "how to" will explain in a very simple way how anyone can print news to pdf using Plone2Pdf.

The product by default only allows printing to pdf the following objects : Document, ZWiki Page, ATDocument, PloneArticle, BlogEntry. This is already great but in my case I needed to print News ... how to?

Display the pdf Icon

To allow the product to print your object you'll need access to the action. To do it just go to /mysite/portal_skins/Plone2Pdf/pdfConvertTypes customize it by adding your objects to the array of possible objects to be printed:

return ['Document', 'ZWiki Page', 'ATDocument', 'PloneArticle', 'BlogEntry', 'News Item' ]

Define what to print

Now you can see the icon when visualizing your object. You cant try it out but only the title will be printed.

The next step is to define what to print when the print2pdf action to a specified object is requested. For that we must customize  /mysite/portal_skins/Plone2Pdf/viewPDF.

Before the byline macro you can place your code. For the News object the code I used was:

<tal:ifDocument tal:condition="python: here.portal_type == 'News Item'">
<div class="stx" tal:replace="structure python: here.ploneChar2SystChar(here.CookedBody())">
description

</div>
</tal:ifDocument>


  • The first line checks if the object requested has the type 'News Item'.
  • The second line defines that we want to print all the text body from the News. Also, I called the

    ploneChar2SystChar function to convert the text to my charset.

    Charset is a collection of characters so if you don't define one that contains your language characters the visual results will not be as expected, this is caused by an htmldoc limitation that does not (yet support) UTF-8. Since Plone2PDF uses UTF-8 enconding as default you'll may need to change your charset. This can be done in /mysite/portal_properties/plone2pdf_properties (thanks to Zoltan Soos).


Congratulations!
You can now print your news to pdf