ez.no / ezpublish / documentation / incoming / pdf export tutorial
These documentation pages are no longer maintained. Please visit the new documentation site.
Setting up and creating PDF exports
This description require some basic understanding of eZ publish. Please read the introduction section if there are some concepts you are unfamiliar with.
The PDF export utilizes templates like regular html sites. Instead of inserting the main result into pagelayout.tpl via $module_result.content, the content is fetched in node/view/pdf.tpl based on the description in the PDF export UI.
After all the content has been inserted through the template system, node/view/execute_pdf.tpl is calle by the system to generate the final PDF.
The templates used in the PDF generation are normally found in the same place as the html templates, except view is replaced with pdf in the path. Ex : datatype templates are under content/datatype/pdf, and general templates are under content/pdf.
Template overriding is done by creating an override file for override.ini.
In the following example we'll look at how the design of the documentation on this page is done.
First we need to create the override file for fetching the documentation pages. We add the following to settings/override/overrride.ini.append.php
[documentation] Source=node/view/pdf.tpl MatchFile=content/pdf/documentation.tpl Subdir=templates Match[class]=9
This will override all default accesses of the documentation objects.
We now need to create the documentation.tpl file.
{*---- design/<your design>/override/templates/content/pdf/documentation.tpl ----*} {* First we add the keywords in the dosumentation page to the keyword index using the bundeled keyword support in the PDF library *} {attribute_pdf_gui attribute=$node.object.data_map.keywords} {* Then we check if this is the first template to be called if so, start a page counter called main, at offset 1. ( generate_toc will not be send as a parameter to other templates ) *} {section show=$generate_toc|eq(1)} {pdf(pageNumber, hash( identifier, "main", start, 1 ) )} {/section} {* Insert the name of the documentation object as header level 1, font size 24, font Times, align to the left. *} {pdf(header, hash( level, 1, text, $node.name|wash(pdf), size, 24, font, Times-Roman, align, left ) )} {* The body of the documentation object is an xml text field, so we're going to use the build in templates to diplay it's content. *} {attribute_pdf_gui attribute=$node.object.data_map.body} {* Fetch all children of class 9 (documentation), and add the to the PDF document *} {let children=$node.children class_array=array(9)} {section name=Child loop=$children} {section show=$class_array|contains($Child:item.object.contentclass_id)} {node_view_gui view=pdf content_node=$Child:item} {/section} {/section} {/let} {* Last we insert and generate frontpage and Table of Contents (toc) *} {section show=$generate_toc|eq(1)} {* {pdf(createIndex)} *} {* we skip creating keyword index. *} {pdf(pageNumber, hash( identifier, "main", stop, 1 ) )} {include uri="design:content/pdf/footer.tpl"} {section show=$show_frontpage|eq(1)} {pdf(frontpage, hash( text, $intro_text|wash(pdf), align, center, size, 24, top_margin, 200 ) )} {pdf(frontpage, hash( text, $sub_intro_text|wash(pdf), align, center, size, 10, top_margin, 700 ) )} {/section} {include uri="design:content/pdf/toc.tpl"} {/section}
Since we wish to display images in the documentation we have to override the embed template. Both Jpeg and Png images are supported.
Add to the override.ini.append.php file :
[embedImage] Source=content/pdf/embed.tpl MatchFile=content/pdf/image.tpl Subdir=templates Match[class]=5
Create the template file
{* ------- design/<your design>/override/templates/content/pdf/image.tpl ------ *} {default image_class=large alignment=false() hspace=false() border_size=0} {let image_attribute=$object.data_map.image image_content=$image_attribute.content} {let image=$image_content[$image_class]} {pdf(image,hash(src,$image.full_path, width,$image.width, height,$image.height, border,$border_size))} {/let} {/let} {/default}
Futher we wish to render the tables without borders, so we create a override template for the table template
[table] Source=content/datatype/pdf/ezxmltags/table.tpl MatchFile=content/pdf/table.tpl Subdir=templates
Create the template file.
{* ------- design/<your design>/override/templates/content/pdf/table.tpl ------ *} {pdf(table, $rows, hash( showLines, 0 ) )}
The footer is also created by standard overriding. The page numbers are inserted inserting #page for current page number, nd #total for total number of pages.
Add override definition:
[footer] Source=content/pdf/footer.tpl MatchFile=content/pdf/footer.tpl Subdir=templates
{* ------- design/<your design>/override/templates/content/pdf/footer.tpl ------ *} {pdf(footer, hash( text, "eZ publish - http://ez.no"|i18n( "design/standard/content/pdf" )|wash(pdf), size, 10, align, "left" ) ) } {pdf(footer, hash( text, "#page of #total"|i18n( "design/standard/content/pdf" )|wash(pdf), align, "right", size, 10 ) ) } {pdf(footer, hash( line, hash( margin, 80, thicknes, 1, size, "full" ) ) ) }
For the titles we wish to use Times Roman, change the font size and alignment.
Add override definition:
[header] Source=content/datatype/pdf/ezxmltags/header.tpl MatchFile=content/pdf/header.tpl Subdir=templates
Create the template file.
{* ------- design/<your design>/override/templates/content/pdf/header.tpl ------ *} {switch name=sw match=$level} {case match=1} {pdf(header, hash( level, 1, text, $content|wash(pdf), size, 18, font, Times-Roman, align, left ) )} {/case} {case match=2} {pdf(header, hash( level, 2, text, $content|wash(pdf), font, Times-Roman, align, left, size, 14 ) )} {/case} {case match=3} {pdf(header, hash( level, 3, text, $content|wash(pdf), font, Times-Roman, align, left, size, 12 ) )} {/case} {case match=4} {pdf(header, hash( level, 4, text, $content|wash(pdf), font, Times-Roman, align, left, size, 10 ) )} {/case} {case} {pdf(header, hash( level, 5, text, $content|wash(pdf), font, Times-Roman, align, left, size, 10 ) )} {/case} {/switch}
Last we create the table of contents with some indenting and different font size
Add to override:
[toc] Source=content/pdf/toc.tpl MatchFile=content/pdf/toc.tpl Subdir=templates
Create the template file.
{* ------- design/<your design>/override/templates/content/pdf/toc.tpl ------ *} {pdf(toc, hash( size, array( 14, 12, 14, 12, 10 ), dots, true(), contentText, "Table of contents"|wash(pdf), indent, array( 0, 20, 6, 8, 10 ) ) )}
Comments