Per prima cosa dobbiamo scaricarci e scompattare la libreria TCPDF che la troviamo qui
Apriamo la cartella e andiamo a modificare il file "tcpdf_config.php" , lo troviamo nella cartella "Config" :
Modifichiamo le seguenti variabili :
/**
* document creator
*/
define ('PDF_CREATOR', 'TCPDF');
/**
* document author
*/
define ('PDF_AUTHOR', 'TCPDF');
/**
* header title
*/
define ('PDF_HEADER_TITLE', 'TCPDF Example');
/**
* header description string
*/
define ('PDF_HEADER_STRING', "by Nicola Asuni - Tecnick.com\nwww.tcpdf.org");
/**
* image logo
*/
define ('PDF_HEADER_LOGO', 'tcpdf_logo.jpg');
In qualcosa del genere :
/**
* document creator
*/
define ('PDF_CREATOR', 'Davide86');
/**
* document author
*/
define ('PDF_AUTHOR', 'Davide86');
/**
* header title
*/
define ('PDF_HEADER_TITLE', 'Imaginsystems');
/**
* header description string
*/
define ('PDF_HEADER_STRING', "by Davide86 - Imaginsystems.it\nwww.imaginsystems.it");
/**
* image logo
*/
define ('PDF_HEADER_LOGO', 'logo.jpg'); //Ricordati di salvare il file immagine nella cartella "images"
Ora passiamo alla creazione del file "creapdf.php" nella cartella principale (Qui troverete tanti file di esempio ):
(Ricordati che il file punterà a due librerie importantissime "config/lang/eng.php" e "tcpdf.php" quindi stai attento a dove salvi il file.)
<?php
//============================================================+
// File name : example065.php
// Begin : 2011-09-28
// Last Update : 2011-09-28
//
// Description : Example 065 for TCPDF class
// Default Header and Footer
//
// Author: Nicola Asuni
//
// (c) Copyright:
// Nicola Asuni
// Tecnick.com s.r.l.
// Via Della Pace, 11
// 09044 Quartucciu (CA)
// ITALY
// www.tecnick.com
// info@tecnick.com
//============================================================+
/**
* Creates an example PDF/A-1b document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: PDF/A-1b mode
* @author Nicola Asuni
* @since 2011-09-28
*/
require_once('config/lang/eng.php');
require_once('tcpdf.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false, true);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 065');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 065', PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
//set some language-dependent strings
$pdf->setLanguageArray($l);
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
$pdf->SetFont('helvetica', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// Set some content to print
$html = <<<EOD
<h1>Esempio Creazione File PDF </h1>
<br>
<p> by Davide86 <a href="http://www.imaginsystems.it" style="text-decoration:none;background-color:#CC0000;color:black;">Imaginsystems.it</a>
</p>
<i>Questo documento è conforme allo standard <b>PDF/A-1b (ISO 19005-1:2005)</b>.</i>
<br><br>Inserisco qui il codice HTML <br>
EOD;
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
$pdf->Output('creapdf_temp.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
?>
Finito, semplice e pulito, grazie alla libreria TCPDF.
Cosi facendo il nostro file "creapdf.php" crerea il file "creapdf_temp.pdf" che è un PDF-A, dove l'utente può decidesere se stamparlo o salvarlo.
Buon divertimento by Davide86













