Valid XHTML    Valid CSS2    

Listing du fichier l2aprog12.php

 

00001     <?php
00002     
00003     
# (gH) -_- l2aprog09.php ; TimeStamp (unix) : 07 Mars 2013 vers 18:32
00004     
00005     
error_reporting(E_ALL | E_NOTICE | E_STRICT ) ;
00006     
00007     
###########################################################################
00008     # #
00009     # exemple de programme php pour le cours Développement Web Avancé en L2 #
00010     # #
00011     ###########################################################################
00012     # #
00013     # #
00014     # Ecrire du PDF #
00015     # #
00016     # #
00017     ###########################################################################
00018     
00019     
00020     # html2pdf (1)
00021     
00022     
$content
= "
00023      <page>
00024      <h1>Exemple d'utilisation</h1>
00025      <br>
00026      Ceci est un <b>exemple d'utilisation</b>
00027      de <a href='http://html2pdf.fr/'>HTML2PDF</a>.<br>
00028      </page>"
;
00029     
00030      require_once(
dirname
(__FILE__).'/html2pdf/html2pdf.class.php');
00031     
$html2pdf
= new HTML2PDF('P','A4','fr');
00032     
$html2pdf
->WriteHTML($content);
00033     
$html2pdf
->Output('exemple.pdf');
00034     
00035     
# html2pdf (2)
00036     
00037     /**
00038      * HTML2PDF Librairy - example
00039      *
00040      * HTML => PDF convertor
00041      * distributed under the LGPL License
00042      *
00043      * @author Laurent MINGUET <webmaster@html2pdf.fr>
00044      *
00045      * isset($_GET['vuehtml']) is not mandatory
00046      * it allow to display the result in the HTML format
00047      */
00048     
00049      // demmarage de la mise en memoire tampon
00050     
ob_start
() ; //
00051     
00052      // recuperation du fichier qui génère la page
00053     
include(
dirname(__FILE__).'maPage.php') ;
00054     
00055     
// met le contenu de la memoire tampon dans la variable
00056     
$content
= ob_get_contents() ;
00057     
00058     
// vide la memoire tampon
00059     
ob_get_clean() ;
00060     
00061     
// fait appel a la classe html2pdf
00062     
require_once(
dirname(__FILE__).'/html2pdf.class.php') ;
00063     
00064      try {
00065     
00066     
// creation d'un nouvel objet HTML2PDF
00067     
$html2pdf
= new HTML2PDF('P', 'A4', 'fr') ;
00068     
00069     
// pour mettre ensuite en affichage page entiere
00070     
$html2pdf
->pdf->SetDisplayMode('fullpage') ;
00071     
00072     
// transformation du fichier en pdf
00073     
$html2pdf
->writeHTML($content) ;
00074     
00075     
// insertion de la date et de l'heure
00076     
$html2pdf
->writeHTML('Le '.date("d/m/Y H:i:s")) ;
00077     
00078     
// affichage a l'ecran
00079     
$html2pdf
->Output('exempleCV.pdf') ;
00080     
00081     
// gestion des erreurs eventuelles
00082     
00083     
} catch(
HTML2PDF_exception $e) {
00084      echo
$e ;
00085      exit ;
00086     
00087      }
# fin de try
00088     
00089     # fpdf (manuel PHP)
00090     
00091     
$p
= PDF_new();
00092     
00093     
/* ouvre un nouveau fichier PDF ; insère un nom de fichier pour créer le PDF sur le disque */
00094     
if (
PDF_begin_document($p, "", "") == 0) {
00095      die(
"Error: "
. PDF_get_errmsg($p));
00096     }
00097     
00098     
PDF_set_info
($p, "Creator", "hello.php");
00099     
PDF_set_info
($p, "Author", "Rainer Schaaf");
00100     
PDF_set_info
($p, "Title", "Bonjour le monde (PHP)!");
00101     
00102     
PDF_begin_page_ext
($p, 595, 842, "");
00103     
00104     
$font
= PDF_load_font($p, "Helvetica-Bold", "winansi", "");
00105     
00106     
PDF_setfont
($p, $font, 24.0);
00107     
PDF_set_text_pos
($p, 50, 700);
00108     
PDF_show
($p, "Hello world!");
00109     
PDF_continue_text
($p, "(dit PHP)");
00110     
PDF_end_page_ext
($p, "");
00111     
00112     
PDF_end_document
($p, "");
00113     
00114     
$buf
= PDF_get_buffer($p);
00115     
$len
= strlen($buf);
00116     
00117     
header
("Content-type: application/pdf");
00118     
header
("Content-Length: $len");
00119     
header
("Content-Disposition: inline; filename=hello.pdf");
00120     print
$buf;
00121     
00122     
PDF_delete
($p);
00123     
00124     
# tcpdf, exemple recopié de http://www.phpkode.com/source/s/tcpdf/tcpdf/examples/example_028.php
00125     
00126     
00127     
require_once(
'../config/lang/eng.php');
00128      require_once(
'../tcpdf.php');
00129     
00130     
// create new PDF document
00131     
$pdf
= new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
00132     
00133     
// set document information
00134     
$pdf
->SetCreator(PDF_CREATOR);
00135     
$pdf
->SetAuthor('Nicola Asuni');
00136     
$pdf
->SetTitle('TCPDF Example 028');
00137     
$pdf
->SetSubject('TCPDF Tutorial');
00138     
$pdf
->SetKeywords('TCPDF, PDF, example, test, guide');
00139     
00140     
// remove default header/footer
00141     
$pdf
->setPrintHeader(false);
00142     
$pdf
->setPrintFooter(false);
00143     
00144     
// set default monospaced font
00145     
$pdf
->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
00146     
00147     
//set margins
00148     
$pdf
->SetMargins(10, PDF_MARGIN_TOP, 10);
00149     
00150     
//set auto page breaks
00151     
$pdf
->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
00152     
00153     
//set image scale factor
00154     
$pdf
->setImageScale(PDF_IMAGE_SCALE_RATIO);
00155     
00156     
//set some language-dependent strings
00157     
$pdf
->setLanguageArray($l);
00158     
00159     
// ---------------------------------------------------------
00160     
00161     
$pdf
->SetDisplayMode('fullpage', 'SinglePage', 'UseNone');
00162     
00163     
// set font
00164     
$pdf
->SetFont('times', 'B', 20);
00165     
00166     
$pdf
->AddPage('P', 'A4');
00167     
$pdf
->Cell(0, 0, 'A4 PORTRAIT', 1, 1, 'C');
00168     
00169     
$pdf
->AddPage('L', 'A4');
00170     
$pdf
->Cell(0, 0, 'A4 LANDSCAPE', 1, 1, 'C');
00171     
00172     
$pdf
->AddPage('P', 'A5');
00173     
$pdf
->Cell(0, 0, 'A5 PORTRAIT', 1, 1, 'C');
00174     
00175     
$pdf
->AddPage('L', 'A5');
00176     
$pdf
->Cell(0, 0, 'A5 LANDSCAPE', 1, 1, 'C');
00177     
00178     
$pdf
->AddPage('P', 'A6');
00179     
$pdf
->Cell(0, 0, 'A6 PORTRAIT', 1, 1, 'C');
00180     
00181     
$pdf
->AddPage('L', 'A6');
00182     
$pdf
->Cell(0, 0, 'A6 LANDSCAPE', 1, 1, 'C');
00183     
00184     
$pdf
->AddPage('P', 'A7');
00185     
$pdf
->Cell(0, 0, 'A7 PORTRAIT', 1, 1, 'C');
00186     
00187     
$pdf
->AddPage('L', 'A7');
00188     
$pdf
->Cell(0, 0, 'A7 LANDSCAPE', 1, 1, 'C');
00189     
00190     
00191     
// --- test backward editing ---
00192     
00193     
00194     
$pdf
->setPage(1, true);
00195     
$pdf
->SetY(50);
00196     
$pdf
->Cell(0, 0, 'A4 test', 1, 1, 'C');
00197     
00198     
$pdf
->setPage(2, true);
00199     
$pdf
->SetY(50);
00200     
$pdf
->Cell(0, 0, 'A4 test', 1, 1, 'C');
00201     
00202     
$pdf
->setPage(3, true);
00203     
$pdf
->SetY(50);
00204     
$pdf
->Cell(0, 0, 'A5 test', 1, 1, 'C');
00205     
00206     
$pdf
->setPage(4, true);
00207     
$pdf
->SetY(50);
00208     
$pdf
->Cell(0, 0, 'A5 test', 1, 1, 'C');
00209     
00210     
$pdf
->setPage(5, true);
00211     
$pdf
->SetY(50);
00212     
$pdf
->Cell(0, 0, 'A6 test', 1, 1, 'C');
00213     
00214     
$pdf
->setPage(6, true);
00215     
$pdf
->SetY(50);
00216     
$pdf
->Cell(0, 0, 'A6 test', 1, 1, 'C');
00217     
00218     
$pdf
->setPage(7, true);
00219     
$pdf
->SetY(40);
00220     
$pdf
->Cell(0, 0, 'A7 test', 1, 1, 'C');
00221     
00222     
$pdf
->setPage(8, true);
00223     
$pdf
->SetY(40);
00224     
$pdf
->Cell(0, 0, 'A7 test', 1, 1, 'C');
00225     
00226     
$pdf
->lastPage();
00227     
00228     
// ---------------------------------------------------------
00229     
00230      //Close and output PDF document
00231     
$pdf
->Output('example_028.pdf', 'I');
00232     
00233     
00234     
?>

Pour ne pas voir les numéros de ligne, ajoutez &nl=non à la suite du nom du fichier.

 

 

retour gH    Retour à la page principale de   (gH)