Top Banner
HTML to ODT to XML to PDF to . . . FrOSCon 2010 Tobias Schlitt <[email protected]> August 22, 2010
43

HTML to ODT to XML to PDF to …

May 18, 2015

Download

Technology

Tobias Schlitt

Converting document formats using the Apache Zeta Components Document component. Talk held on FrOSCon 2010 (PHP-Room).
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . .FrOSCon 2010

Tobias Schlitt <[email protected]>

August 22, 2010

Page 2: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 2 / 25

License

Copyright by Tobias Schlitt, Qafoo GmbH

Licensensed under Creative CommonsAttribution-NonCommercial-ShareAlike 2.0 Generic

Page 3: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 3 / 25

About me

I Tobias SchlittI Apprenticed IT specialistI Waiting for diploma to be approved (TU Dortmund)I Open source enthusiastI Co-founder of Qafoo - passion for software qualityI PMC member of Apache Zeta ComponentsI Contributor to various other OSS projects

Page 4: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 4 / 25

Outline

Introduction

The Document component

Getting into the code

End

Page 5: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 5 / 25

eZ Components

Page 6: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 5 / 25

Apache Zeta Components

ZetaComponents

apache

Page 7: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 6 / 25

Apache Zeta Components

I Previously developed by eZ SystemsI http://ez.no

I Originally named eZ ComponentsI Code donated to the Apache Software Foundation

I http://apache.org

I Currently incubatingI Re-organizing / re-gathering communityI Join us!

Page 8: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 7 / 25

Apache Zeta Components

I General purpose component library for PHP 5.1+

I Open source (Apache 2.0 license)I Focus

I High code qualityI Excellent docsI Backwards compatibility

I Professional support available

I http://zetacomponents.org

Page 9: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 8 / 25

The components

49 components, an extract . . .

I Archive

I ConsoleTools

I Graph

I Mail

I MvcTools

I Webdav

I Workflow

Page 10: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 9 / 25

Outline

Introduction

The Document component

Getting into the code

End

Page 11: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 10 / 25

Goal

I Applications need to deal withI Different input mechanisms

I WYSIWYG editor (HTML)I Simple text editor (wiki markup)I Emails (ReST)

I Different output formatsI Web front end (HTML)I Technical documentation management (Docbook)I Print (PDF)

I The Document component converts markup formats

Page 12: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 10 / 25

Goal

I Applications need to deal withI Different input mechanisms

I WYSIWYG editor (HTML)I Simple text editor (wiki markup)I Emails (ReST)

I Different output formatsI Web front end (HTML)I Technical documentation management (Docbook)I Print (PDF)

I The Document component converts markup formats

Page 13: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 10 / 25

Goal

I Applications need to deal withI Different input mechanisms

I WYSIWYG editor (HTML)I Simple text editor (wiki markup)I Emails (ReST)

I Different output formatsI Web front end (HTML)I Technical documentation management (Docbook)I Print (PDF)

I The Document component converts markup formats

Page 14: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 10 / 25

Goal

I Applications need to deal withI Different input mechanisms

I WYSIWYG editor (HTML)I Simple text editor (wiki markup)I Emails (ReST)

I Different output formatsI Web front end (HTML)I Technical documentation management (Docbook)I Print (PDF)

I The Document component converts markup formats

Page 15: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 11 / 25

Supported formats

I Currently supported formatsI DocbookI (X)HtmlI eZ XMLI ReSTI Wiki

I Dokuwiki, popular PHP based wiki (wiki.php.net) (read-only)I Creole, wiki markup standardization initiativeI Confluence, Apache Atlassian wiki dialect (read-only)

I PDF (write only)I ODF (only flat)

Page 16: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 12 / 25

Approach

I Docbook as central conversion formatI Possible conversion shortcutsI Conversions always configurable and extensible

Docbook

Creole

Dokuwiki

Confluence

ReST

ODF

(X)Html

eZ XML

PDF

➤➤ ➤

➤➤➤

➤➤

Page 17: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 13 / 25

Outline

Introduction

The Document component

Getting into the code

End

Page 18: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 14 / 25

Reading ReStructered Text

1 ==================2 PHP @ FrOSCon 20103 ==================45 For the f i f t h t ime we w i l l be at the ‘ Free and Open Source Confe rence ‘6 ( FrOSCon ) i n St . August in , nea r Bonn , o r g a n i z i n g a t r a c k f u l l o f PHP r e l a t e d7 t a l k s . We a l s o o f f e r space to d i s c u s s PHP r e l a t e d t op i c s , o r j u s t hack wi th8 o th e r open minded peop l e around you . We would l o v e to welcome you i n the PHP9 room .

1011 We a r e c u r r e n t l y l o o k i n g f o r t a l k s f o r the PHP room , and the ‘ C a l l For12 Papers ‘ w i l l l a s t u n t i l the 23 . 05 . 2010 , j u s t l i k e the ‘ C a l l For Papers ‘ o f13 the FrOSCon . P l e a s e submit a t a l k , i f you got someth ing i n t e r e s t i n g to t a l k14 about .1516 You might a l s o want to submit t a l k s to the ‘ main s chedu l e ‘ o f the17 con f e r ence , which a l s o a c c ep t s PHP r e l a t e d t a l k s . For t a l k s i n the main18 con f e r e n c e your c o s t s w i l l be cove r ed as usua l , d e t a i l s a r e on the ‘ d e d i c a t e d19 webs i t e ‘ .2021 ht tp : // phpugdo . de/22 ht tp : // f r o s c o n . de/23 / c a l l f o r p a p e r s . html24 h t tp : //www. f r o s c o n . de/ i ndex . php? i d=15&mid=119& r e t=15&L=0&L=025 ht tp : //www. f r o s c o n . de/ i ndex . php? i d=15&mid=119& r e t=15&L=0&L=026 ht tp : //www. f r o s c o n . de/ i ndex . php? i d=15&mid=119& r e t=15&L=0&L=0

Page 19: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 15 / 25

Reading ReStructered Text

1 <?php23 r e q u i r e ’ . / au to l oad . php ’ ;45 $document = new ezcDocumentRst ( ) ;6 $document−>l o a d F i l e ( ’ f r o s c o n . t x t ’ ) ;78 echo $document−>getAsDocbook ( ) ;

Page 20: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 15 / 25

Reading ReStructered Text

1 <?php23 r e q u i r e ’ . / au to l oad . php ’ ;45 $document = new ezcDocumentRst ( ) ;6 $document−>l o a d F i l e ( ’ f r o s c o n . t x t ’ ) ;78 echo $document−>getAsDocbook ( ) ;

Page 21: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 15 / 25

Reading ReStructered Text

1 <?php23 r e q u i r e ’ . / au to l oad . php ’ ;45 $document = new ezcDocumentRst ( ) ;6 $document−>l o a d F i l e ( ’ f r o s c o n . t x t ’ ) ;78 echo $document−>getAsDocbook ( ) ;

Page 22: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 15 / 25

Reading ReStructered Text

1 <?php23 r e q u i r e ’ . / au to l oad . php ’ ;45 $document = new ezcDocumentRst ( ) ;6 $document−>l o a d F i l e ( ’ f r o s c o n . t x t ’ ) ;78 echo $document−>getAsDocbook ( ) ;

Page 23: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 16 / 25

Reading ReStructered Text1 <?xml v e r s i o n=” 1 .0 ”?>2 <!DOCTYPE a r t i c l e PUBLIC ”−//OASIS//DTD DocBook XML V4 .5//EN” ” h t t p : //www. o a s i s−

open . org /docbook/xml /4 .5/ docbookx . dtd ”>3 <a r t i c l e xmlns=” h t t p : // docbook . org / ns /docbook”>4 <s e c t i o n ID=” php f r o s con 2010 ”>5 < t i t l e>PHP @ FrOSCon 2010</ t i t l e>6 <para>For the f i f t h t ime <u l i n k u r l=” h t t p : //phpugdo . de/”>we</ u l i n k> w i l l be

at the <u l i n k u r l=” h t t p : // f r o s c o n . de/”>Free and Open Source Con fe r ence</ u l i n k> ( FrOSCon ) i n St . August in , nea r Bonn , o r g a n i z i n g a t r a c k f u l lo f PHP r e l a t e d t a l k s . We a l s o o f f e r space to d i s c u s s PHP r e l a t e d t op i c s, o r j u s t hack wi th o th e r open minded peop l e around you . We would l o v eto welcome you i n the PHP room .</ para>

7 <para>We are c u r r e n t l y l o o k i n g f o r t a l k s f o r the PHP room , and the <u l i n ku r l=”/ c a l l f o r p a p e r s . html ”>Ca l l For Papers</ u l i n k> w i l l l a s t u n t i l the23 . 05 . 2010 , j u s t l i k e the <u l i n k u r l=” h t t p : //www. f r o s c o n . de/ i ndex . php?

i d=15&amp ; amp ; mid=119&amp ; amp ; r e t=15&amp ; amp ; L=0&amp ; amp ; L=0”>Ca l l ForPapers</ u l i n k> o f the FrOSCon . P l e a s e submit a t a l k , i f you gotsometh ing i n t e r e s t i n g to t a l k about .</ para>

8 <para>You might a l s o want to submit t a l k s to the <u l i n k u r l=” h t t p : //www.f r o s c o n . de/ i ndex . php? i d=15&amp ; amp ; mid=119&amp ; amp ; r e t=15&amp ; amp ; L=0&amp ; amp ; L=0”>main s c h edu l e</ u l i n k> o f the con f e r ence , which a l s oa c c ep t s PHP r e l a t e d t a l k s . For t a l k s i n the main c on f e r e n c e your c o s t sw i l l be cove r ed as usua l , d e t a i l s a r e on the <u l i n k u r l=” h t t p : //www.f r o s c o n . de/ i ndex . php? i d=15&amp ; amp ; mid=119&amp ; amp ; r e t=15&amp ; amp ; L=0&amp ; amp ; L=0”>ded i c a t e d web s i t e</ u l i n k>.</ para>

9 </ s e c t i o n>10 </ a r t i c l e>

Page 24: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 17 / 25

HTML to RST conversion

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlConten tLoca to rF i l t e r ( ) ,9 ) ) ;

1011 $xhtml−>l o a d F i l e ( ’ wh i t epape r . html ’ ) ;12 // $xhtml−>l o a d F i l e ( ’ h t tp : // qafoo . com/

wh i t epape r . html ’ ) ;1314 $ r s t = new ezcDocumentRst ( ) ;15 $ r s t−>createFromDocbook ( $xhtml−>getAsDocbook ( )

) ;1617 echo $ r s t ;

Page 25: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 17 / 25

HTML to RST conversion

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlConten tLoca to rF i l t e r ( ) ,9 ) ) ;

1011 $xhtml−>l o a d F i l e ( ’ wh i t epape r . html ’ ) ;12 // $xhtml−>l o a d F i l e ( ’ h t tp : // qafoo . com/

wh i t epape r . html ’ ) ;1314 $ r s t = new ezcDocumentRst ( ) ;15 $ r s t−>createFromDocbook ( $xhtml−>getAsDocbook ( )

) ;1617 echo $ r s t ;

Page 26: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 17 / 25

HTML to RST conversion

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlConten tLoca to rF i l t e r ( ) ,9 ) ) ;

1011 $xhtml−>l o a d F i l e ( ’ wh i t epape r . html ’ ) ;12 // $xhtml−>l o a d F i l e ( ’ h t tp : // qafoo . com/

wh i t epape r . html ’ ) ;1314 $ r s t = new ezcDocumentRst ( ) ;15 $ r s t−>createFromDocbook ( $xhtml−>getAsDocbook ( )

) ;1617 echo $ r s t ;

Page 27: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 17 / 25

HTML to RST conversion

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlConten tLoca to rF i l t e r ( ) ,9 ) ) ;

1011 $xhtml−>l o a d F i l e ( ’ wh i t epape r . html ’ ) ;12 // $xhtml−>l o a d F i l e ( ’ h t tp : // qafoo . com/

wh i t epape r . html ’ ) ;1314 $ r s t = new ezcDocumentRst ( ) ;15 $ r s t−>createFromDocbook ( $xhtml−>getAsDocbook ( )

) ;1617 echo $ r s t ;

Page 28: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 17 / 25

HTML to RST conversion

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlConten tLoca to rF i l t e r ( ) ,9 ) ) ;

1011 $xhtml−>l o a d F i l e ( ’ wh i t epape r . html ’ ) ;12 // $xhtml−>l o a d F i l e ( ’ h t tp : // qafoo . com/

wh i t epape r . html ’ ) ;1314 $ r s t = new ezcDocumentRst ( ) ;15 $ r s t−>createFromDocbook ( $xhtml−>getAsDocbook ( )

) ;1617 echo $ r s t ;

Page 29: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 18 / 25

HTML to RST conversion1 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−2 Your s o f tw a r e s q u a l i t y mat t e r s3 −−−−−−−−−−−−−−−−−−−−−−−−−−−−−−45 Contents6 ========78 − ‘ I n t r o d u c t i o n ‘9 − ‘ Bu s i n e s s goa l s ‘

10 [ . . ]1112 Ra i s i n g and c o n t i n u o u s l y mon i t o r i ng the q u a l i t y o f s o f twa r e a l l ow s you to13 improve the Return On Inves tment , to r educe the t ime to market and to i n c r e a s e14 customer s a t i s f a c t i o n f o r your s o f twa r e p roduc t . No matte r i f you deve l op f o r15 company i n t e r n a l use on ly , on a customer b a s i s o r s t anda rd s o f twa r e .1617 i n t r o d u c t i o n18 bu s i n e s s−g o a l s19 [ . . ]2021 . . f i g u r e : : / images / wh i t epape r / s t a i r w a y s t o q u a l i t y . png22 : width : 50023 : h e i g h t : 22524 : a l t : S t a i rway s to q u a l i t y2526 I n t r o d u c t i o n27 ============2829 Qua l i t y impact s v a r i o u s a r e a s o f your company\ ’ s s o f twa r e deve lopment [ . . ]

Page 30: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 31: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 32: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 33: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 34: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 35: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 19 / 25

PDF generation

1 <?php2 r e q u i r e ’ au to l oad . php ’ ;34 // Conver t some web page to PDF5 $xhtml = new ezcDocumentXhtml ( ) ;6 $xhtml−>s e t F i l t e r s ( a r r a y (7 new ezcDocumentXhtmlE lementF i l t e r ( ) ,8 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,9 ) ) ;

10 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1112 // Load the docbook document and c r e a t e a PDF from i t13 $pdf = new ezcDocumentPdf ( ) ;14 $pdf−>op t i on s−>e r r o r R e p o r t i n g = E PARSE | E ERROR | E WARNING ;1516 // Load a custom s t y l e s h e e t17 $pdf−>l o a d S t y l e s ( ’ custom . c s s ’ ) ;1819 // Add a cus tomized heade r20 $pdf−>r e g i s t e r P d f P a r t ( new ezcDocumentPdfHeaderPdfPart (21 new ezcDocumentPdfFooterOpt ions ( a r r a y (22 ’ showPageNumber ’ => f a l s e ,23 ’ h e i g h t ’ => ’ 10mm’ ,24 ) )25 ) ) ;2627 $pdf−>createFromDocbook ( $xhtml−>getAsDocbook ( ) ) ;28 f i l e p u t c o n t e n t s ( F I LE . ’ . pd f ’ , $pdf ) ;

Page 36: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 20 / 25

PDF generation1 a r t i c l e {2 font−f am i l y : ” sans−s e r i f ” ;3 font−s i z e : ”10 pt ” ;4 }56 t i t l e {7 font−f am i l y : ” sans−s e r i f ” ;8 c o l o r : #97BF0D ;9

10 border−bottom : 1px s o l i d #555753;11 border−l e f t : 4px s o l i d #555753;12 padding−l e f t : 4px ;13 }1415 s e c t i o n > s e c t i o n > s e c t i o n > s e c t i o n > t i t l e {16 border−c o l o r : #babdb6 ;17 }1819 page {20 padd ing : ”15mm 30mm” ;21 }2223 u l i n k {24 c o l o r : #97BF0D ;25 }2627 l i n k {28 c o l o r : #97BF0D ;29 }

Page 37: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 21 / 25

PDF generation

Page 38: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 22 / 25

ODT generation

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 // Conver t some i npu t RSTf i l e to docbook6 $xhtml = new ezcDocumentXhtml ( ) ;7 $xhtml−>s e t F i l t e r s ( a r r a y (8 new ezcDocumentXhtmlE lementF i l t e r ( ) ,9 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,

10 ) ) ;11 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1213 $ c on v e r t e r = new ezcDocumentDocbookToOdtConverter ( ) ;14 $conve r t e r−>op t i on s−>s t y l e r−>a d d S t y l e s h e e t F i l e ( ’ custom . c s s ’ ) ;1516 $odt = $conve r t e r−>conv e r t ( $xhtml−>getAsDocbook ( ) ) ;17 f i l e p u t c o n t e n t s ( F I LE . ’ . f o d t ’ , $odt ) ;

Page 39: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 22 / 25

ODT generation

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 // Conver t some i npu t RSTf i l e to docbook6 $xhtml = new ezcDocumentXhtml ( ) ;7 $xhtml−>s e t F i l t e r s ( a r r a y (8 new ezcDocumentXhtmlE lementF i l t e r ( ) ,9 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,

10 ) ) ;11 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1213 $ c on v e r t e r = new ezcDocumentDocbookToOdtConverter ( ) ;14 $conve r t e r−>op t i on s−>s t y l e r−>a d d S t y l e s h e e t F i l e ( ’ custom . c s s ’ ) ;1516 $odt = $conve r t e r−>conv e r t ( $xhtml−>getAsDocbook ( ) ) ;17 f i l e p u t c o n t e n t s ( F I LE . ’ . f o d t ’ , $odt ) ;

Page 40: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 22 / 25

ODT generation

1 <?php23 r e q u i r e ’ au to l oad . php ’ ;45 // Conver t some i npu t RSTf i l e to docbook6 $xhtml = new ezcDocumentXhtml ( ) ;7 $xhtml−>s e t F i l t e r s ( a r r a y (8 new ezcDocumentXhtmlE lementF i l t e r ( ) ,9 new ezcDocumentXhtmlXpathF i l te r ( ’ // d i v [ @ c l a s s=”con t en t ” ] ’ ) ,

10 ) ) ;11 $xhtml−>l o a d F i l e ( ’ c o n s u l t i n g . html ’ ) ;1213 $ c on v e r t e r = new ezcDocumentDocbookToOdtConverter ( ) ;14 $conve r t e r−>op t i on s−>s t y l e r−>a d d S t y l e s h e e t F i l e ( ’ custom . c s s ’ ) ;1516 $odt = $conve r t e r−>conv e r t ( $xhtml−>getAsDocbook ( ) ) ;17 f i l e p u t c o n t e n t s ( F I LE . ’ . f o d t ’ , $odt ) ;

Page 41: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 23 / 25

ODT generation

Page 42: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 24 / 25

Outline

Introduction

The Document component

Getting into the code

End

Page 43: HTML to ODT to XML to PDF to …

HTML to ODT to XML to PDF to . . . 25 / 25

Thanks for listening

I Apache Zeta ComponentsI http://zetacomponents.orgI #zetacomponents @ Freenode

I Stay in touchI [email protected] @tobySen

I Take care for your software qualityI http://qafoo.comI Also consulting / training / support for Zeta