32
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-11-18 19:15:27 +00:00
tcpdf/examples/example_014.php

195 lines
6.0 KiB
PHP
Raw Normal View History

2009-09-30 09:18:36 +00:00
<?php
//============================================================+
// File name : example_014.php
// Begin : 2008-03-04
2010-06-07 14:46:49 +00:00
// Last Update : 2010-06-07
2010-05-21 16:47:01 +00:00
//
2009-09-30 09:18:36 +00:00
// Description : Example 014 for TCPDF class
// Javascript Form and user rights (only works on Adobe Acrobat)
2010-05-21 16:47:01 +00:00
//
2009-09-30 09:18:36 +00:00
// Author: Nicola Asuni
2010-05-21 16:47:01 +00:00
//
2009-09-30 09:18:36 +00:00
// (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 TEST document using TCPDF
* @package com.tecnick.tcpdf
* @abstract TCPDF - Example: Javascript Form and user rights (only works on Adobe Acrobat)
* @author Nicola Asuni
* @copyright 2004-2009 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
* @link http://tcpdf.org
* @license http://www.gnu.org/copyleft/lesser.html LGPL
* @since 2008-03-04
*/
require_once('../config/lang/eng.php');
require_once('../tcpdf.php');
// create new PDF document
2010-05-21 16:47:01 +00:00
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
2009-09-30 09:18:36 +00:00
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 014');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
2010-05-21 16:47:01 +00:00
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.' 014', PDF_HEADER_STRING);
2009-09-30 09:18:36 +00:00
// 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));
2009-03-24 18:37:18 +00:00
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
2009-09-30 09:18:36 +00:00
//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
2010-05-21 16:47:01 +00:00
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
2009-09-30 09:18:36 +00:00
//set some language-dependent strings
2010-05-21 16:47:01 +00:00
$pdf->setLanguageArray($l);
2009-09-30 09:18:36 +00:00
// ---------------------------------------------------------
2010-06-02 10:33:59 +00:00
// IMPORTANT: disable font subsetting to allow users editing the document
2010-06-07 14:46:49 +00:00
$pdf->setFontSubsetting(false);
// set font
$pdf->SetFont('helvetica', '', 10, '', false);
2009-09-30 09:18:36 +00:00
// add a page
$pdf->AddPage();
/*
2009-09-07 21:53:40 +00:00
It is possible to create text fields, combo boxes, check boxes and buttons.
Fields are created at the current position and are given a name.
2009-09-30 09:18:36 +00:00
This name allows to manipulate them via JavaScript in order to perform some validation for instance.
2009-09-02 12:35:08 +00:00
*/
2009-05-07 13:08:11 +00:00
2009-09-07 21:53:40 +00:00
// set default form properties
$pdf->setFormDefaultProp(array('lineWidth'=>1, 'borderStyle'=>'solid', 'fillColor'=>array(255, 255, 200), 'strokeColor'=>array(255, 128, 128)));
2009-09-30 09:18:36 +00:00
$pdf->SetFont('helvetica', 'BI', 18);
2010-05-21 16:47:01 +00:00
$pdf->Cell(0, 5, 'Example of Form', 0, 1, 'C');
2009-09-02 12:35:08 +00:00
$pdf->Ln(10);
2009-09-30 09:18:36 +00:00
$pdf->SetFont('helvetica', '', 12);
// First name
$pdf->Cell(35, 5, 'First name:');
$pdf->TextField('firstname', 50, 5);
$pdf->Ln(6);
// Last name
$pdf->Cell(35, 5, 'Last name:');
$pdf->TextField('lastname', 50, 5);
$pdf->Ln(6);
// Gender
$pdf->Cell(35, 5, 'Gender:');
2009-09-07 21:53:40 +00:00
//$pdf->ComboBox('gender', 10, 5, array('', 'M', 'F'));
2009-09-30 09:18:36 +00:00
$pdf->ComboBox('gender', 30, 5, array(array('', '-'), array('M', 'Male'), array('F', 'Female')));
$pdf->Ln(6);
// Drink
$pdf->Cell(35, 5, 'Drink:');
$pdf->RadioButton('drink', 5, array(), array(), 'Water');
$pdf->Cell(35, 5, 'Water');
$pdf->Ln(6);
$pdf->Cell(35, 5, '');
$pdf->RadioButton('drink', 5, array(), array(), 'Beer', true);
$pdf->Cell(35, 5, 'Beer');
$pdf->Ln(6);
$pdf->Cell(35, 5, '');
$pdf->RadioButton('drink', 5, array(), array(), 'Wine');
$pdf->Cell(35, 5, 'Wine');
$pdf->Ln(10);
// Listbox
$pdf->Cell(35, 5, 'List:');
$pdf->ListBox('listbox', 60, 15, array('', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7'), array('multipleSelection'=>'true'));
$pdf->Ln(20);
// Adress
$pdf->Cell(35, 5, 'Address:');
$pdf->TextField('address', 60, 18, array('multiline'=>true));
$pdf->Ln(19);
// E-mail
$pdf->Cell(35, 5, 'E-mail:');
$pdf->TextField('email', 50, 5);
$pdf->Ln(6);
// Newsletter
$pdf->Cell(35, 5, 'Newsletter:');
$pdf->CheckBox('newsletter', 5, true, array(), array(), 'OK');
$pdf->Ln(10);
// Date of the day
$pdf->Cell(35, 5, 'Date:');
$pdf->TextField('date', 30, 5, array(), array('v'=>date('Y-m-d'), 'dv'=>date('Y-m-d')));
2009-09-07 21:53:40 +00:00
$pdf->Ln(10);
$pdf->SetX(50);
2009-09-30 09:18:36 +00:00
2009-09-07 21:53:40 +00:00
// Button to validate and print
$pdf->Button('print', 30, 10, 'Print', 'Print()', array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
// Reset Button
$pdf->Button('reset', 30, 10, 'Reset', array('S'=>'ResetForm'), array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
// Submit Button
$pdf->Button('submit', 30, 10, 'Submit', array('S'=>'SubmitForm', 'F'=>'http://localhost/printvars.php', 'Flags'=>array('ExportFormat')), array('lineWidth'=>2, 'borderStyle'=>'beveled', 'fillColor'=>array(128, 196, 255), 'strokeColor'=>array(64, 64, 64)));
2009-09-30 09:18:36 +00:00
// Form validation functions
2009-09-07 21:53:40 +00:00
$js = <<<EOD
2009-09-30 09:18:36 +00:00
function CheckField(name,message) {
var f = getField(name);
if(f.value == '') {
app.alert(message);
f.setFocus();
return false;
}
return true;
}
function Print() {
if(!CheckField('firstname','First name is mandatory')) {return;}
if(!CheckField('lastname','Last name is mandatory')) {return;}
if(!CheckField('gender','Gender is mandatory')) {return;}
if(!CheckField('address','Address is mandatory')) {return;}
print();
2009-09-07 21:53:40 +00:00
}
EOD;
2009-09-30 09:18:36 +00:00
// Add Javascript code
2009-09-07 21:53:40 +00:00
$pdf->IncludeJS($js);
2009-09-30 09:18:36 +00:00
// ---------------------------------------------------------
//Close and output PDF document
2009-09-07 21:53:40 +00:00
$pdf->Output('example_014.pdf', 'I');
2009-09-30 09:18:36 +00:00
//============================================================+
2010-06-02 10:33:59 +00:00
// END OF FILE
2009-09-30 09:18:36 +00:00
//============================================================+
2009-03-24 18:37:18 +00:00
?>