parent
12dc8c3206
commit
4d137dd17c
@ -0,0 +1,165 @@ |
||||
GNU LESSER GENERAL PUBLIC LICENSE |
||||
Version 3, 29 June 2007 |
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> |
||||
Everyone is permitted to copy and distribute verbatim copies |
||||
of this license document, but changing it is not allowed. |
||||
|
||||
|
||||
This version of the GNU Lesser General Public License incorporates |
||||
the terms and conditions of version 3 of the GNU General Public |
||||
License, supplemented by the additional permissions listed below. |
||||
|
||||
0. Additional Definitions. |
||||
|
||||
As used herein, "this License" refers to version 3 of the GNU Lesser |
||||
General Public License, and the "GNU GPL" refers to version 3 of the GNU |
||||
General Public License. |
||||
|
||||
"The Library" refers to a covered work governed by this License, |
||||
other than an Application or a Combined Work as defined below. |
||||
|
||||
An "Application" is any work that makes use of an interface provided |
||||
by the Library, but which is not otherwise based on the Library. |
||||
Defining a subclass of a class defined by the Library is deemed a mode |
||||
of using an interface provided by the Library. |
||||
|
||||
A "Combined Work" is a work produced by combining or linking an |
||||
Application with the Library. The particular version of the Library |
||||
with which the Combined Work was made is also called the "Linked |
||||
Version". |
||||
|
||||
The "Minimal Corresponding Source" for a Combined Work means the |
||||
Corresponding Source for the Combined Work, excluding any source code |
||||
for portions of the Combined Work that, considered in isolation, are |
||||
based on the Application, and not on the Linked Version. |
||||
|
||||
The "Corresponding Application Code" for a Combined Work means the |
||||
object code and/or source code for the Application, including any data |
||||
and utility programs needed for reproducing the Combined Work from the |
||||
Application, but excluding the System Libraries of the Combined Work. |
||||
|
||||
1. Exception to Section 3 of the GNU GPL. |
||||
|
||||
You may convey a covered work under sections 3 and 4 of this License |
||||
without being bound by section 3 of the GNU GPL. |
||||
|
||||
2. Conveying Modified Versions. |
||||
|
||||
If you modify a copy of the Library, and, in your modifications, a |
||||
facility refers to a function or data to be supplied by an Application |
||||
that uses the facility (other than as an argument passed when the |
||||
facility is invoked), then you may convey a copy of the modified |
||||
version: |
||||
|
||||
a) under this License, provided that you make a good faith effort to |
||||
ensure that, in the event an Application does not supply the |
||||
function or data, the facility still operates, and performs |
||||
whatever part of its purpose remains meaningful, or |
||||
|
||||
b) under the GNU GPL, with none of the additional permissions of |
||||
this License applicable to that copy. |
||||
|
||||
3. Object Code Incorporating Material from Library Header Files. |
||||
|
||||
The object code form of an Application may incorporate material from |
||||
a header file that is part of the Library. You may convey such object |
||||
code under terms of your choice, provided that, if the incorporated |
||||
material is not limited to numerical parameters, data structure |
||||
layouts and accessors, or small macros, inline functions and templates |
||||
(ten or fewer lines in length), you do both of the following: |
||||
|
||||
a) Give prominent notice with each copy of the object code that the |
||||
Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the object code with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
4. Combined Works. |
||||
|
||||
You may convey a Combined Work under terms of your choice that, |
||||
taken together, effectively do not restrict modification of the |
||||
portions of the Library contained in the Combined Work and reverse |
||||
engineering for debugging such modifications, if you also do each of |
||||
the following: |
||||
|
||||
a) Give prominent notice with each copy of the Combined Work that |
||||
the Library is used in it and that the Library and its use are |
||||
covered by this License. |
||||
|
||||
b) Accompany the Combined Work with a copy of the GNU GPL and this license |
||||
document. |
||||
|
||||
c) For a Combined Work that displays copyright notices during |
||||
execution, include the copyright notice for the Library among |
||||
these notices, as well as a reference directing the user to the |
||||
copies of the GNU GPL and this license document. |
||||
|
||||
d) Do one of the following: |
||||
|
||||
0) Convey the Minimal Corresponding Source under the terms of this |
||||
License, and the Corresponding Application Code in a form |
||||
suitable for, and under terms that permit, the user to |
||||
recombine or relink the Application with a modified version of |
||||
the Linked Version to produce a modified Combined Work, in the |
||||
manner specified by section 6 of the GNU GPL for conveying |
||||
Corresponding Source. |
||||
|
||||
1) Use a suitable shared library mechanism for linking with the |
||||
Library. A suitable mechanism is one that (a) uses at run time |
||||
a copy of the Library already present on the user's computer |
||||
system, and (b) will operate properly with a modified version |
||||
of the Library that is interface-compatible with the Linked |
||||
Version. |
||||
|
||||
e) Provide Installation Information, but only if you would otherwise |
||||
be required to provide such information under section 6 of the |
||||
GNU GPL, and only to the extent that such information is |
||||
necessary to install and execute a modified version of the |
||||
Combined Work produced by recombining or relinking the |
||||
Application with a modified version of the Linked Version. (If |
||||
you use option 4d0, the Installation Information must accompany |
||||
the Minimal Corresponding Source and Corresponding Application |
||||
Code. If you use option 4d1, you must provide the Installation |
||||
Information in the manner specified by section 6 of the GNU GPL |
||||
for conveying Corresponding Source.) |
||||
|
||||
5. Combined Libraries. |
||||
|
||||
You may place library facilities that are a work based on the |
||||
Library side by side in a single library together with other library |
||||
facilities that are not Applications and are not covered by this |
||||
License, and convey such a combined library under terms of your |
||||
choice, if you do both of the following: |
||||
|
||||
a) Accompany the combined library with a copy of the same work based |
||||
on the Library, uncombined with any other library facilities, |
||||
conveyed under the terms of this License. |
||||
|
||||
b) Give prominent notice with the combined library that part of it |
||||
is a work based on the Library, and explaining where to find the |
||||
accompanying uncombined form of the same work. |
||||
|
||||
6. Revised Versions of the GNU Lesser General Public License. |
||||
|
||||
The Free Software Foundation may publish revised and/or new versions |
||||
of the GNU Lesser General Public License from time to time. Such new |
||||
versions will be similar in spirit to the present version, but may |
||||
differ in detail to address new problems or concerns. |
||||
|
||||
Each version is given a distinguishing version number. If the |
||||
Library as you received it specifies that a certain numbered version |
||||
of the GNU Lesser General Public License "or any later version" |
||||
applies to it, you have the option of following the terms and |
||||
conditions either of that published version or of any later version |
||||
published by the Free Software Foundation. If the Library as you |
||||
received it does not specify a version number of the GNU Lesser |
||||
General Public License, you may choose any version of the GNU Lesser |
||||
General Public License ever published by the Free Software Foundation. |
||||
|
||||
If the Library as you received it specifies that a proxy can decide |
||||
whether future versions of the GNU Lesser General Public License shall |
||||
apply, that proxy's public statement of acceptance of any version is |
||||
permanent authorization for you to choose that version for the |
||||
Library. |
||||
Binary file not shown.
@ -0,0 +1,181 @@ |
||||
******************************************************* |
||||
** Ce programme est distribué sous la licence LGPL, ** |
||||
** reportez-vous au fichier _LGPL.txt ou à ** |
||||
** http://www.gnu.org/licenses/lgpl.html ** |
||||
** pour en savoir plus. ** |
||||
** ** |
||||
** Copyright 2000-2009 par Laurent Minguet ** |
||||
******************************************************* |
||||
******************************** |
||||
* HTML2PDF v3.22a - 15/06/2009 * |
||||
******************************** |
||||
|
||||
Utilisation : |
||||
------------ |
||||
- regardez les exemples fournis pour voir le fonctionnement. |
||||
|
||||
- les formulaires ne marchent QUE avec ADOBE READER 8 et ADOBE READER 9.0 |
||||
|
||||
- il est TRES IMPORTANT de fournir du HTML 4.01 valide au convertisseur, |
||||
mais seulement ce que contient le <body> |
||||
|
||||
- pour les borders : il est conseillé qu'ils soient au format "solid 1mm #000000" |
||||
|
||||
- pour les paddings : ils ne sont applicables qu'aux balises table, th, td, div, li |
||||
|
||||
- la liste des balises HTML reconnues se trouve dans le fichier "_balises_html.xls" |
||||
|
||||
- la possibilité de protégé vos PDF est présente, CF Exemple 7. Elle utilise le script |
||||
fpdf_protection de Klemen Vodopivec. |
||||
|
||||
- Certaines balises spécifiques ont été introduites : |
||||
* <page></page> (CF Exemple 7) : |
||||
permet de définir l'orientation, les marges left, right, top et bottom, l'image |
||||
et la couleur de fond d'une page, sa taille et position, le footer. |
||||
Il est egalement possible de garder les header et footer des pages précédentes, |
||||
grace à l'attribue pageset="old" (CF Exemple 3) |
||||
|
||||
* <page_header></page_header> (CF Exemple 3) |
||||
|
||||
* <page_footer></page_footer> (CF Exemple 3) |
||||
|
||||
* <nobreak></nobreak> : |
||||
permet de forcer l'affichage d'une partie sur une même page. |
||||
Si cette partie ne rentre pas dans le reste de la page, un saut de page est |
||||
effectué avant. |
||||
|
||||
* <barcode></barcode> (CF Exemples 0 et 9) : |
||||
permet d'inserer des barcodes dans les pdfs, CF Exemples 0 et 9 |
||||
Les types de codebar possible sont : EAN13, UPC_A, CODE39. Ceci utilise les |
||||
scripts de The-eh et Olivier |
||||
|
||||
* <bookmark></bookmark> (CF Exemples 7 et About) : |
||||
permet d'inserer des bookmark dans les pdfs, CF Exemple 7 et About. |
||||
Il est egalement possible de créer un index automatiquement en fin de |
||||
document, CF exemple About. |
||||
Ceci utilise les scripts d'Olivier et de Min's |
||||
|
||||
Modification : |
||||
------------- |
||||
3.22a: redistribution de HTML2PDF sous la licence LGPL !!! (au lieu de GPL) |
||||
3.22 : correction sur le background-color |
||||
refonte totale de la gestion de text-align. les valeurs center et right marchent maintenant meme en cas de contenu riche |
||||
3.21 : ajout de la propriété css FLOAT pour la balise IMG |
||||
correction sur la gestion des TFOOT |
||||
correction sur le positionnement des images |
||||
3.20 : ajout de la gestion des margins pour la balise DIV |
||||
ajout de la gestion de la propriete css LINE-HEIGHT |
||||
correction sur l'interpretation de la valeur de certains styles CSS (background-image, background-position, ...) |
||||
correction sur la reconnaissance des balises thead et tfoot |
||||
correction sur la balise select |
||||
correction sur les fichiers de langue (merci à Sinan) |
||||
3.19 : optimisation du parseur HTML - merci à Jezelinside |
||||
ajout de la balise TFOOT |
||||
amélioration de la gestion des tableaux : les contenus des balises THEAD et TFOOT sont maintenant répétés sur chaque page. |
||||
ajout de la balise spécifique BOOKMARK afin de créer des "marques-page" |
||||
possibilité de rajouter un index automatique en fin de fichier |
||||
ajout de la langue turque TR (merci à Hidayet) |
||||
amélioration de la méthode Output. Elle est maintenant également utilisable comme celle de FPDF |
||||
3.18 : correction sur les sauts de page automatique pour les balises TABLE, UL, OL |
||||
correction sur l'interpretation des styles pour la balise HR |
||||
correction sur l'interpretation du style border-collapse pour la balise TABLE |
||||
prise en compte de margin:auto pour les tables et les divs |
||||
les commentaires dans les CSS sont acceptés |
||||
3.17 : ajout de la gestion des balises INPUT (text, radio, checkbox, button, hidden, ...), SELECT, OPTION, TEXTAREA (cf exemple 14) |
||||
ajout de la possibilité de mettre des scripts dans le pdf, via $html2pdf->pdf->IncludeJS(...); (cf exemples JS) |
||||
correction sur le saut de page automatique pour les images |
||||
correction sur les sauts de lignes automatiques pour certaines balises (UL, P, ...) |
||||
ajout de la langue NL (merci à Roland) |
||||
3.16 : ajout de la gestion de list-style: none (cf exemple 13) |
||||
correction dans la gestion des fontes ajoutées à fpdf (via la méthode AddFont) |
||||
nombreuses corrections sur le calcul des largeurs des éléments table, div, hr, td, th |
||||
ajout de l'exemple about.php |
||||
(pour info, les PDF générés à partir des exemples sont maintenant dans le répertoire /exemples/pdf/, et sont supprimables) |
||||
3.15 : correction sur l'identification des styles en cas de valeurs multiples dans la propriete class |
||||
prise en compte de border-radius pour la limite des backgrounds (color et image) |
||||
ajout des proprietes CSS border-top-*, border-right-*, border-bottom-*, border-left-* |
||||
ajout de la propriété CSS list-style-image (cf exemple 12) |
||||
pour la balise table, ajout de l'interprétation de align="center" et align="right" (cf exemple 1) |
||||
correction dans le positionnement des images |
||||
correction de quelques bugs |
||||
ajout d'une fonction d'analyse des ressources HTML2PDFgetTimerDebug (cf début du fichier html2pdf.class.php) |
||||
3.14 : ajout d'une langue (pt : Brazilian Portuguese language) et amelioration de la methode vueHTML (merci à Rodrigo) |
||||
correction du positionnement du contenu des DIVs. gestion des proprietes valign et align |
||||
ajout de la propriete CSS border-collapse (cf exemple 0) |
||||
ajout de la propriete CSS border-radius (cf exemple 1) |
||||
correction de quelques bugs |
||||
3.13 : reecriture de la balise hr, avec prise en compte des styles (cf exemple 0) |
||||
ajout de la propriete backcolor pour la balise page (cf exemple 9) |
||||
ajout des proprietes backleft et backright pour la balise page afin de pouvoir changer les marges des pages (cf exemple 8) |
||||
nombreuses corrections sur les balises et les styles |
||||
3.12 : ajout des balises ol, ul, li (cf exemple 12) |
||||
correction sur le calcul de la taille des td en cas de colspan et rowspan |
||||
ajout de la méthode setTestTdInOnePage afin de pouvoir desactiver le test sur la taille des TD (cf exemple 11) |
||||
correction de quelques bugs |
||||
3.11 : ajout des balises div, p, pre, s |
||||
gestion des styles CSS position (relative, absolute), left, top, right, bottom (cf exemple 10) |
||||
meilleur gestion des border : border-style, border-color, border-width (cf exemple 10) |
||||
possibilité d'indiquer les marges par défault, via le constructeur (cf exemple 2) |
||||
3.10a: correction pour compatibilité php4 / php5 |
||||
3.10 : ajout des liens internes (cf exemple 7) |
||||
gestion complete des background : image, repeat, position, color (cf exemple 1) |
||||
gestion de underline, overline, linethrough (cf exemple 2) |
||||
correction de quelques bugs |
||||
3.09 : mise à jour vers fpdf version 1.6, ajout de barcode, correction de l'affichage de certains caractères spéciaux |
||||
correction du calcul de la hauteur de ligne de la balise br |
||||
detection en cas de contenu trop grand dans un TD |
||||
amélioration de la balise page (ajout de l'attribue pageset, avec les valeurs new et old) |
||||
ajout de FPDF_PROTECTION, accesible via $pdf->pdf->SetProtection(...) |
||||
3.08 : version opérationnelle de page_header, ajout de page_footer, correction des borders des tableaux |
||||
3.07 : correction de l'interpretation de cellspacing, amélioration de la balise page_header |
||||
3.06 : première gestion de la balise page_header, correction des dimensions des tableaux |
||||
3.05 : ajout de la propriété vertical-align, ajout de la gestion des fichiers de langue |
||||
3.04 : correction du saut de page automatique pour les tableaux. Ajout de propriétés à la balise PAGE |
||||
3.03 : correction de bugs au niveau de la gestion des images PHP par FPDF, meilleure gestion des erreurs |
||||
3.02 : ajout de la gestion des noms des couleurs, correction de la gestion des images générées par php, correction de quelques bugs |
||||
3.01 : correction de quelques bugs, ajout d'une protection pour les balises non existantes |
||||
3.00 : refont totale du calcul des tableaux. Prise en compte des colspan et rowspan |
||||
2.85 : ajout de la propriété cellspacing, nouvelle gestion des padding des tableaux (identique à l'html) |
||||
2.80 : ajout des types de border dotted et dasheds |
||||
2.75 : ajout des top, left, right, bottom pour padding et border |
||||
2.70 : correction de la balise HR, ajout de la propriété padding pour les table, th, td |
||||
correction des dimensions, les unités px, mm, in, pt sont enfin réellement reproduites, correction de font-size, border, ... |
||||
ajout d'une propriété à la balise page : footer |
||||
correction dans l'affichage et le calcul des tables |
||||
2.55 : vérification de la validité du code (ouverture / fermeture) - ajout des unités mm, in, pt |
||||
2.50 : correction de nobreak, des marges, ajout de nombreuses balises |
||||
2.40 : refonte totale de l'identification des styles CSS. Les héritages marchent. |
||||
2.39 : corrections diverses, ajout de certaines propriétés (bgcolor, ...) |
||||
2.38 : meilleur identification des propriétés border et color |
||||
2.37 : nombreuses corrections : balise A, couleur de fond, retour à la ligne, gestion des images dans un texte, ... |
||||
2.36 : ajout des balises STRONG, EM |
||||
2.35 : amélioration de la gestion des feuilles de style |
||||
2.31 : correction de quelques bugs |
||||
2.30 : première version opérationnel des feuilles de style |
||||
2.25 : ajout de la balise LINK pour le type text/css |
||||
2.20 : premier jet de la gestion des feuilles de style, ajout de la balise STYLE |
||||
2.15 : n'interprète plus l'HTML en commentaire <!-- --> |
||||
2.10 : ajout des balises H1 -> H6 |
||||
2.01 : correction de quelques bugs |
||||
2.00 : première version diffusée |
||||
|
||||
Aide et Support : |
||||
---------------- |
||||
pour toutes questions et rapport de bug, merci d'utiliser exclusivement le lien de support ci-dessous. |
||||
Je ne répondrais à aucune question en dehors, afin que tout le monde puisse profiter des réponses. |
||||
|
||||
Informations : |
||||
------------- |
||||
Programmation en PHP4 |
||||
|
||||
Programmeur : Spipu |
||||
email : webmaster@spipu.net |
||||
site : http://html2pdf.fr/ |
||||
wiki : http://html2pdf.fr/wiki.php |
||||
support : http://html2pdf.fr/forum.php |
||||
|
||||
Remerciement : |
||||
------------- |
||||
* Olivier PLATHEY pour sa librairie Fpdf (http://www.fpdf.org/) |
||||
* yAronet pour l'hebergement du forum de support |
||||
* toutes les personnes qui m'ont aidé à développer cet librairie, et à traduire les différents textes |
||||
@ -0,0 +1,79 @@ |
||||
********************************************************* |
||||
** This program is distributed under the LGPL License, ** |
||||
** for more information see file _LGPL.txt or ** |
||||
** http://www.gnu.org/licenses/lgpl.html ** |
||||
** ** |
||||
** Copyright 2000-2009 by Laurent Minguet ** |
||||
********************************************************* |
||||
******************************** |
||||
* HTML2PDF v3.22a - 2009-06-15 * |
||||
******************************** |
||||
|
||||
How to use : |
||||
------------ |
||||
- Look at the examples provided to see how it works. |
||||
|
||||
- forms work only with ADOBE READER 8 and 9.0 |
||||
|
||||
- It is very important to provide valid HTML 4.01 to the converter, |
||||
but only what is in the <body> |
||||
|
||||
- for borders: it is advised that they are like "solid 1mm #000000" |
||||
|
||||
- for padding, they are applicable only on tags table, th, td, div, li |
||||
|
||||
- the list of recognized HTML tags is in the file "_balises_html.xls" |
||||
|
||||
- The possibility to protect your PDF is present, CF Example 7. It uses the script |
||||
fpdf_protection of Klemen Vodopivec. |
||||
|
||||
- Some specific tags have been introduced: |
||||
* <page></page> (CF Exemple 7) : |
||||
determines the orientation, margins left, right, top and bottom, the background image |
||||
and the background color of a page, its size and position, the footer. |
||||
It is also possible to keep the header and footer of the previous pages, |
||||
through the attribut pageset="old" (see Example 3) |
||||
|
||||
* <page_header></page_header> (CF Example 3) |
||||
|
||||
* <page_footer></page_footer> (CF Example 3) |
||||
|
||||
* <nobreak></nobreak> : |
||||
used to force the display of a section on the same page. |
||||
If this section does not fit into the rest of the page, a page break is done before. |
||||
|
||||
* <barcode></barcode> (CF Examples 0 et 9) : |
||||
can insert barcodes in pdfs, CF Examples 0 and 9 |
||||
The possible types od codebar are: EAN13, UPC_A, CODE39. |
||||
This uses the scripts of The-eh and Olivier |
||||
|
||||
* <bookmark></bookmark> (CF Examples 7 et About) : |
||||
can insert bookmark in pdfs, CF Example 7 and About. |
||||
It is also possible to automatically create an index at the end of |
||||
documentv CF Example About. |
||||
This uses the scripts of Olivier and Min's |
||||
|
||||
change log : |
||||
----------- |
||||
see the _lisez_moi.txt file, in french sorry ;) |
||||
|
||||
Help & Support : |
||||
--------------- |
||||
For questions and bug reports, thank you to use only the support link below. |
||||
I will answer to your questions only on it... |
||||
|
||||
Informations : |
||||
------------- |
||||
Programming in PHP4 |
||||
|
||||
Programmer : Spipu |
||||
email : webmaster@spipu.net |
||||
web site : http://html2pdf.fr/ |
||||
wiki : http://html2pdf.fr/wiki.php |
||||
support : http://html2pdf.fr/forum.php |
||||
|
||||
Thanks : |
||||
------- |
||||
* Olivier PLATHEY for his library Fpdf (http://www.fpdf.org/) |
||||
* yAronet for hosting support forum |
||||
* everyone who helped me to develop this library and to bring the texts |
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,421 @@ |
||||
<?php |
||||
/** |
||||
* Logiciel : HTML2PDF - classe ParsingHTML |
||||
* |
||||
* Convertisseur HTML => PDF, utilise fpdf de Olivier PLATHEY |
||||
* Distribué sous la licence LGPL. |
||||
* |
||||
* @author Laurent MINGUET <webmaster@spipu.net> |
||||
* @version 3.22a - 15/06/2009 |
||||
*/ |
||||
|
||||
if (!defined('__CLASS_PARSINGHTML__')) |
||||
{ |
||||
define('__CLASS_PARSINGHTML__', true); |
||||
|
||||
class parsingHTML |
||||
{ |
||||
var $html = ''; // code HTML à parser |
||||
var $code = array(); // code HTML parsé |
||||
var $num = 0; // numéro de table |
||||
var $level = 0; // niveaux de table |
||||
|
||||
/** |
||||
* Constructeur |
||||
* |
||||
* @return null |
||||
*/ |
||||
function parsingHTML() |
||||
{ |
||||
$this->num = 0; |
||||
$this->level = array($this->num); |
||||
$this->html = ''; |
||||
$this->code = array(); |
||||
} |
||||
|
||||
/** |
||||
* Définir le code HTML à parser |
||||
* |
||||
* @param string code html |
||||
* @return null |
||||
*/ |
||||
function setHTML($html) |
||||
{ |
||||
$html = preg_replace('/<!--(.*)-->/isU', '', $html); |
||||
$this->html = $html; |
||||
} |
||||
|
||||
/** |
||||
* parser le code HTML |
||||
* |
||||
* @return null |
||||
*/ |
||||
function parse() |
||||
{ |
||||
$parents = array(); |
||||
// récupérer le code à parser |
||||
$content = $this->html; |
||||
|
||||
// chercher les balises HTML du code |
||||
$tmp = array(); |
||||
$this->searchCode($content, $tmp); |
||||
|
||||
// identifier les balises une à une |
||||
$pre_in = false; |
||||
$pre_br = array( |
||||
'name' => 'br', |
||||
'close' => false, |
||||
'param' => array( |
||||
'style' => array(), |
||||
'num' => 0 |
||||
) |
||||
); |
||||
|
||||
$todos = array(); |
||||
foreach($tmp as $part) |
||||
{ |
||||
// si c'est un texte |
||||
if ($part[0]=='txt') |
||||
{ |
||||
// enregistrer l'action correspondante |
||||
if (!$pre_in) |
||||
{ |
||||
if (trim($part[1])!=='') |
||||
{ |
||||
// remplacer tous les espaces, tabulations, saufs de ligne multiples par de simples espaces |
||||
$part[1] = preg_replace('/([\s]+)/is', ' ', $part[1]); |
||||
|
||||
$todos[] = array( |
||||
'name' => 'write', |
||||
'close' => false, |
||||
'param' => array('txt' => $part[1]), |
||||
); |
||||
} |
||||
} |
||||
else |
||||
{ |
||||
$part[1] = str_replace("\r", '', $part[1]); |
||||
$part[1] = explode("\n", $part[1]); |
||||
|
||||
foreach($part[1] as $k => $txt) |
||||
{ |
||||
$txt = str_replace("\t", ' ', $txt); |
||||
$txt = str_replace(' ', ' ', $txt); |
||||
if ($k>0) $todos[] = $pre_br; |
||||
|
||||
$todos[] = array( |
||||
'name' => 'write', |
||||
'close' => false, |
||||
'param' => array('txt' => $txt), |
||||
); |
||||
} |
||||
} |
||||
} |
||||
// sinon, analyser le code |
||||
else |
||||
{ |
||||
$res = $this->analiseCode($part[1]); |
||||
if ($res) |
||||
{ |
||||
if (!in_array($res['name'], array('br', 'hr', 'img', 'input', 'link', 'option'))) |
||||
{ |
||||
if ($res['close']) |
||||
{ |
||||
if (count($parents)<1) |
||||
HTML2PDF::makeError(3, __FILE__, __LINE__, $res['name']); |
||||
else if ($parents[count($parents)-1]!=$res['name']) |
||||
HTML2PDF::makeError(4, __FILE__, __LINE__, $parents); |
||||
else |
||||
unset($parents[count($parents)-1]); |
||||
} |
||||
else |
||||
{ |
||||
$parents[count($parents)] = $res['name']; |
||||
} |
||||
} |
||||
if ($res['name']=='pre' || $res['name']=='code') |
||||
{ |
||||
$pre_in = !$res['close']; |
||||
} |
||||
$todos[] = $res; |
||||
} |
||||
} |
||||
} |
||||
|
||||
// pour chaque action identifiée, il faut nettoyer le début et la fin des textes |
||||
// en fonction des balises qui l'entourent. |
||||
$nb = count($todos); |
||||
for($k=0; $k<$nb; $k++) |
||||
{ |
||||
//si c'est un texte |
||||
if ($todos[$k]['name']=='write') |
||||
{ |
||||
// et qu'une balise spécifique le précède => on nettoye les espaces du début du texte |
||||
if ($k>0 && in_array($todos[$k-1]['name'], array('table', 'tr', 'td', 'th', 'br', 'div', 'hr', 'p', 'ul', 'ol', 'li'))) |
||||
$todos[$k]['param']['txt'] = preg_replace('/^([\s]*)([^\s])/isU', '$2', $todos[$k]['param']['txt']); |
||||
|
||||
// et qu'une balise spécifique le suit => on nettoye les espaces de la fin du texte |
||||
if ($k<count($todos)-1 && in_array($todos[$k+1]['name'], array('table', 'tr', 'td', 'th', 'br', 'div', 'hr', 'p', 'ol', 'ul', 'li'))) |
||||
$todos[$k]['param']['txt'] = preg_replace('/([^\s])([\s]*)$/isU', '$1', $todos[$k]['param']['txt']); |
||||
} |
||||
} |
||||
if (count($parents)) HTML2PDF::makeError(5, __FILE__, __LINE__, $parents); |
||||
|
||||
// liste des actions sauvée |
||||
$this->code = $todos; |
||||
} |
||||
|
||||
/** |
||||
* parser le code HTML |
||||
* |
||||
* @param string contenu à parser. |
||||
* @param &array tableau de retour des données |
||||
* @return null |
||||
*/ |
||||
function searchCode($content, &$tmp) |
||||
{ |
||||
// séparer les balises du texte |
||||
$tmp = array(); |
||||
$reg = '/(<[^>]+>)|([^<]+)+/isU'; |
||||
|
||||
// pour chaque élément trouvé : |
||||
$str = ''; |
||||
$offset = 0; |
||||
while(preg_match($reg, $content, $parse, PREG_OFFSET_CAPTURE, $offset)) |
||||
{ |
||||
// si une balise a été détectée |
||||
if ($parse[1][0]) |
||||
{ |
||||
// sauvegarde du texte précédent si il existe |
||||
if ($str!=='') $tmp[] = array('txt',$str); |
||||
|
||||
// sauvegarde de la balise |
||||
$tmp[] = array('code',trim($parse[1][0])); |
||||
|
||||
// initialisation du texte suivant |
||||
$str = ''; |
||||
} |
||||
else |
||||
{ |
||||
// ajout du texte à la fin de celui qui est déjà détecté |
||||
$str.= $parse[2][0]; |
||||
} |
||||
// Update offset to the end of the match |
||||
$offset = $parse[0][1] + strlen($parse[0][0]); |
||||
unset($parse); |
||||
} |
||||
// si un texte est présent à la fin, on l'enregistre |
||||
if ($str!='') $tmp[] = array('txt',$str); |
||||
unset($str); |
||||
} |
||||
|
||||
/** |
||||
* analyse une balise HTML |
||||
* |
||||
* @param string code HTML à identifier |
||||
* @return array action correspondante |
||||
*/ |
||||
function analiseCode($code) |
||||
{ |
||||
// nom de la balise et ouverture ou fermeture |
||||
$balise = '<([\/]{0,1})([_a-z0-9]+)([\/>\s]+)'; |
||||
preg_match('/'.$balise.'/isU', $code, $match); |
||||
$close = ($match[1]=='/' ? true : false); |
||||
$name = strtolower($match[2]); |
||||
|
||||
// paramètres obligatoires en fonction du nom de la balise |
||||
$param = array(); |
||||
$param['style'] = ''; |
||||
if ($name=='img') { $param['alt'] = ''; $param['src'] = ''; } |
||||
if ($name=='a') { $param['href'] = ''; } |
||||
|
||||
// lecture des paramétres du type nom=valeur |
||||
$prop = '([a-zA-Z0-9_]+)=([^"\'\s>]+)'; |
||||
preg_match_all('/'.$prop.'/is', $code, $match); |
||||
for($k=0; $k<count($match[0]); $k++) |
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||||
|
||||
// lecture des paramétres du type nom="valeur" |
||||
$prop = '([a-zA-Z0-9_]+)=["]([^"]*)["]'; |
||||
preg_match_all('/'.$prop.'/is', $code, $match); |
||||
for($k=0; $k<count($match[0]); $k++) |
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||||
|
||||
// lecture des paramétres du type nom='valeur' |
||||
$prop = "([a-zA-Z0-9_]+)=[']([^']*)[']"; |
||||
preg_match_all('/'.$prop.'/is', $code, $match); |
||||
for($k=0; $k<count($match[0]); $k++) |
||||
$param[trim(strtolower($match[1][$k]))] = trim($match[2][$k]); |
||||
|
||||
// mise en conformité en style de chaque paramètre |
||||
$color = "#000000"; |
||||
$border = null; |
||||
foreach($param as $key => $val) |
||||
{ |
||||
$key = strtolower($key); |
||||
switch($key) |
||||
{ |
||||
case 'width': |
||||
unset($param[$key]); |
||||
$param['style'] = 'width: '.$val.'px; '.$param['style']; |
||||
break; |
||||
|
||||
case 'align': |
||||
if ($name!=='table') |
||||
{ |
||||
unset($param[$key]); |
||||
$param['style'] = 'text-align: '.$val.'; '.$param['style']; |
||||
} |
||||
break; |
||||
|
||||
case 'valign': |
||||
unset($param[$key]); |
||||
$param['style'] = 'vertical-align: '.$val.'; '.$param['style']; |
||||
break; |
||||
|
||||
case 'height': |
||||
unset($param[$key]); |
||||
$param['style'] = 'height: '.$val.'px; '.$param['style']; |
||||
break; |
||||
|
||||
case 'bgcolor': |
||||
unset($param[$key]); |
||||
$param['style'] = 'background: '.$val.'; '.$param['style']; |
||||
break; |
||||
|
||||
case 'bordercolor': |
||||
unset($param[$key]); |
||||
$color = $val; |
||||
break; |
||||
|
||||
case 'border': |
||||
unset($param[$key]); |
||||
if (preg_match('/^[0-9]$/isU', $val)) $val = $val.'px'; |
||||
$border = $val; |
||||
break; |
||||
|
||||
case 'cellpadding': |
||||
case 'cellspacing': |
||||
if (preg_match('/^([0-9]+)$/isU', $val)) $param[$key] = $val.'px'; |
||||
break; |
||||
|
||||
case 'colspan': |
||||
case 'rowspan': |
||||
$val = preg_replace('/[^0-9]/isU', '', $val); |
||||
if (!$val) $val = 1; |
||||
$param[$key] = $val; |
||||
break; |
||||
} |
||||
} |
||||
if ($border!==null) |
||||
{ |
||||
if ($border) $param['style'] = 'border: solid '.$border.' '.$color.'; '.$param['style']; |
||||
else $param['style'] = 'border: none'; |
||||
} |
||||
|
||||
// lecture des styles - décomposition |
||||
$styles = explode(';', $param['style']); |
||||
$param['style'] = array(); |
||||
foreach($styles as $style) |
||||
{ |
||||
$tmp = explode(':', $style); |
||||
if (count($tmp)>1) |
||||
{ |
||||
$cod = $tmp[0]; unset($tmp[0]); $tmp = implode(':', $tmp); |
||||
$param['style'][trim(strtolower($cod))] = preg_replace('/[\s]+/isU', ' ', trim($tmp)); |
||||
} |
||||
} |
||||
|
||||
// détermination du niveau de table pour les ouverture, avec ajout d'un level |
||||
if (in_array($name, array('ul', 'ol', 'table')) && !$close) |
||||
{ |
||||
$this->num++; |
||||
$this->level[count($this->level)] = $this->num; |
||||
} |
||||
|
||||
// attribution du niveau de table où se trouve l'élément |
||||
if (!isset($param['num'])) $param['num'] = $this->level[count($this->level)-1]; |
||||
|
||||
// pour les fins de table : suppression d'un level |
||||
if (in_array($name, array('ul', 'ol', 'table')) && $close) |
||||
{ |
||||
unset($this->level[count($this->level)-1]); |
||||
} |
||||
|
||||
// retour de l'action identifiée |
||||
return array('name' => $name, 'close' => $close ? 1 : 0, 'param' => $param); |
||||
} |
||||
|
||||
// récupérer un niveau complet d'HTML entre une ouverture de balise et la fermeture correspondante |
||||
function getLevel($k) |
||||
{ |
||||
// si le code n'existe pas : fin |
||||
if (!isset($this->code[$k])) return ''; |
||||
|
||||
// quelle balise faudra-t-il détecter |
||||
$detect = $this->code[$k]['name']; |
||||
|
||||
$level = 0; // niveau de profondeur |
||||
$end = false; // etat de fin de recherche |
||||
$code = ''; // code extrait |
||||
|
||||
// tant que c'est pas fini, on boucle |
||||
while (!$end) |
||||
{ |
||||
// action courante |
||||
$row = $this->code[$k]; |
||||
|
||||
// si write => on ajoute le texte |
||||
if ($row['name']=='write') |
||||
{ |
||||
$code.= $row['param']['txt']; |
||||
} |
||||
// sinon, c'est une balise html |
||||
else |
||||
{ |
||||
$not = false; // indicateur de non prise en compte de la balise courante |
||||
|
||||
// si c'est la balise que l'on cherche |
||||
if ($row['name']==$detect) |
||||
{ |
||||
if ($level==0) { $not = true; } // si on est à la premiere balise : on l'ignore |
||||
$level+= ($row['close'] ? -1 : 1); // modification du niveau en cours en fonction de l'ouvertre / fermeture |
||||
if ($level==0) { $not = true; $end = true; } // si on est au niveau 0 : on a fini |
||||
} |
||||
|
||||
// si on doit prendre en compte la balise courante |
||||
if (!$not) |
||||
{ |
||||
// ecriture du code HTML de la balise |
||||
$code.= '<'.($row['close'] ? '/' : '').$row['name']; |
||||
foreach($row['param'] as $key => $val) |
||||
{ |
||||
if ($key=='style') |
||||
{ |
||||
$tmp = ''; |
||||
if (isset($val['text-align'])) unset($val['text-align']); |
||||
foreach($val as $ks => $vs) $tmp.= $ks.':'.$vs.'; '; |
||||
if (trim($tmp)) $code.= ' '.$key.'="'.$tmp.'"'; |
||||
} |
||||
else |
||||
{ |
||||
$code.= ' '.$key.'="'.$val.'"'; |
||||
} |
||||
} |
||||
$code.= '>'; |
||||
} |
||||
} |
||||
|
||||
// on continue tant qu'il y a du code à analyser... |
||||
if (isset($this->code[$k+1])) |
||||
$k++; |
||||
else |
||||
$end = true; |
||||
} |
||||
|
||||
// retourne la position finale et le code HTML extrait |
||||
return array($k, $code); |
||||
} |
||||
} |
||||
} |
||||
?> |
||||
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue