30
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-06-07 08:10:48 +00:00
tcpdf/examples/example_014.php

195 lines
6.1 KiB
PHP
Raw Normal View History

2009-09-30 09:18:36 +00:00
<?php
//============================================================+
// File name : example_014.php
// Begin : 2008-03-04
// Last Update : 2013-05-14
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
2011-12-23 17:19:43 +00:00
// Tecnick.com LTD
2009-09-30 09:18:36 +00:00
// 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
* @since 2008-03-04
*/
2011-10-07 18:06:32 +00:00
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
2009-09-30 09:18:36 +00:00
// 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
2009-09-30 09:18:36 +00:00
$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
2009-09-30 09:18:36 +00:00
$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 (optional)
if (file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$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:');
$pdf->ComboBox('gender', 30, 5, array(array('', '-'), array('M', 'Male'), array('F', 'Female')));
$pdf->Ln(6);
// Drink
$pdf->Cell(35, 5, 'Drink:');
2011-10-07 18:06:32 +00:00
//$pdf->RadioButton('drink', 5, array('readonly' => 'true'), array(), 'Water');
2009-09-30 09:18:36 +00:00
$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');
2011-10-07 18:06:32 +00:00
$pdf->Ln(6);
$pdf->Cell(35, 5, '');
$pdf->RadioButton('drink', 5, array(), array(), 'Milk');
$pdf->Cell(35, 5, 'Milk');
2009-09-30 09:18:36 +00:00
$pdf->Ln(10);
2011-10-07 18:06:32 +00:00
// Newsletter
$pdf->Cell(35, 5, 'Newsletter:');
$pdf->CheckBox('newsletter', 5, true, array(), array(), 'OK');
2009-09-30 09:18:36 +00:00
2011-10-07 18:06:32 +00:00
$pdf->Ln(10);
2009-09-30 09:18:36 +00:00
// Adress
$pdf->Cell(35, 5, 'Address:');
2011-10-07 18:06:32 +00:00
$pdf->TextField('address', 60, 18, array('multiline'=>true, 'lineWidth'=>0, 'borderStyle'=>'none'), array('v'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 'dv'=>'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'));
2009-09-30 09:18:36 +00:00
$pdf->Ln(19);
2011-10-07 18:06:32 +00:00
// 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);
2009-09-30 09:18:36 +00:00
// E-mail
$pdf->Cell(35, 5, 'E-mail:');
$pdf->TextField('email', 50, 5);
$pdf->Ln(6);
// 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
$pdf->Output('example_014.pdf', 'D');
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
//============================================================+