FOP : Installer de quoi créer des PDF
Par PiR le jeudi, 15 avril 2010, 23:26 - Linux - Lien permanent
Le but est de créer des fichiers PDF sous Linux, en lignes de commandes, et avec FOP.
- téléchargement des sources :
http://apache.crihan.fr/dist/xmlgraphics/fop/source/fop-0.95-src.tar.gz
http://archive.apache.org/dist/xmlgraphics/fop/source/fop-1.0-src.tar.gz
Ou un des snapshots.
- décompression :
tar -xzf fop-0.95-src.tar.gz
- si ce n'est pas déjà fait, installation de java :
sudo apt-get install openjdk-6-jdk
- si ce n'est pas déjà fait, installation de ant :
apt-get install ant
apt-get install ant-optional
- aller dans le répertoire fop-0.95
et rentrer la commande ant
Voici la commande à utiliser pour construire un pdf :
- A partir d'un fichier XML et d'un fichier XSL :
./fop -xml hello.xml -xsl hello.xsl -pdf hello.pdf
- A partir d'un fichier FO :
./fop -fo hello.fo -pdf hello.pdf
Ensuite le plus délicat est de fabriquer ou de trouver des fichiers à convertir...
Exemples de fichiers FO.
Dont celui-ci (NB : utf-8 est à changer selon le système utilisé) :
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master page-height="29.7cm" page-width="21cm" master-name="only"> <fo:region-body region-name="xsl-region-body" margin="2cm" /> <!-- Corps de page --> <fo:region-before region-name="xsl-region-before" extent="1cm" /> <!-- En-tete de page --> <fo:region-after region-name="xsl-region-after" extent="1cm" /> <!-- Pied de page --> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="only" format="A4" initial-page-number="1"> <!-- En-tete de page --> <fo:static-content flow-name="xsl-region-before"> <fo:block margin="1cm">Page <fo:page-number/> sur <fo:page-number-citation ref-id="last-page"/> <!-- Récupération du numéro de la page du block last-page --> </fo:block> </fo:static-content> <!-- Pied de page --> <fo:static-content flow-name="xsl-region-after"> <fo:block text-align="right" margin-right="1cm">Page <fo:page-number/> sur <fo:page-number-citation ref-id="last-page"/> </fo:block> </fo:static-content> <!-- Corps de page --> <fo:flow flow-name="xsl-region-body"> <!-- Texte justifié --> <fo:block text-align="justify">Some base content, containing an inline warning, <fo:inline >Warning: </fo:inline>Do not touch blue paper, a fairly straightforward piece requiring emphasis <fo:inline font-weight="bold">TEXT</fo:inline>, and some instructions which require presenting in a different way, such as <fo:inline font-style="italic">Now light the blue paper</fo:inline>. </fo:block> <!-- Une image entourée de texte, alignée à droite --> <fo:block text-align="right"> Un texte avant l'image <fo:external-graphic content-height="2.6cm" content-width="8cm" src='url(images/example12.png)'/> Un texte après l'image </fo:block> <!-- Une image centrée --> <fo:block text-align="center" space-before="1em" space-after="1em" > <fo:external-graphic content-height="1cm" content-width="2cm" src="url(images/logo-hover.jpg)"/> <fo:block/> <!-- Un saut de ligne --> Du texte sous l'image </fo:block> <fo:block >A block containing the graphic wrapped in an inline container, <fo:external-graphic height="3cm" width="3cm" content-width="scale-to-fit" content-height="scale-to-fit" src="url(images/example8.png)"/> </fo:block> <!-- Sauts de lines --> <fo:block space-before="1em" space-after="1em" background-color="grey" margin-left="1cm" padding-left="1cm" color="blue" > Une ligne de texte.<fo:block/> Puis un saut de ligne.<fo:block space-before="1em"/> Et un double saut de ligne. </fo:block> <fo:block>Some base content, containing an inline warning, <fo:inline >Warning: </fo:inline>Do not touch blue paper, a fairly straightforward piece requiring emphasis <fo:inline font-weight="bold">TEXT</fo:inline>, and some instructions which require presenting in a different way, such as <fo:inline font-style="italic">Now light the blue paper</fo:inline>. </fo:block> <!-- Saut de page --> <fo:block break-after="page"/> <fo:block font-weight="bold" font-size="18pt"> Un titre de paragraphe </fo:block> <fo:block font-weight="bold" font-size="18pt" text-align="center"> Un titre de paragraphe centré </fo:block> <fo:block>Some base content, containing an inline warning, <fo:inline >Warning: </fo:inline>Do not touch blue paper, a fairly straightforward piece requiring emphasis <fo:inline font-weight="bold">TEXT</fo:inline>, and some instructions which require presenting in a different way, such as <fo:inline font-style="italic">Now light the blue paper</fo:inline>. </fo:block> <!-- Pour récupérer le nombre total de pages --> <fo:block id="last-page"/> <!-- Fin de Corps de page --> </fo:flow> </fo:page-sequence> </fo:root>