32
1
mirror of https://github.com/vdm-io/tcpdf.git synced 2024-11-10 15:20:59 +00:00
tcpdf/examples/example_027.php

326 lines
8.6 KiB
PHP
Raw Normal View History

2009-09-30 09:18:36 +00:00
<?php
//============================================================+
// File name : example_027.php
// Begin : 2008-03-04
2010-05-21 16:47:01 +00:00
// Last Update : 2010-05-20
2010-05-05 09:56:22 +00:00
//
2009-09-30 09:18:36 +00:00
// Description : Example 027 for TCPDF class
// 1D Barcodes
2010-05-05 09:56:22 +00:00
//
2009-09-30 09:18:36 +00:00
// Author: Nicola Asuni
2010-05-05 09:56:22 +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: 1D Barcodes.
* @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-05 09:56:22 +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 027');
$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.' 027', 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-05 09:56:22 +00:00
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
2009-09-30 09:18:36 +00:00
//set some language-dependent strings
2010-05-05 09:56:22 +00:00
$pdf->setLanguageArray($l);
2009-09-30 09:18:36 +00:00
// ---------------------------------------------------------
// set a barcode on the page footer
$pdf->setBarcode(date('Y-m-d H:i:s'));
// set font
2009-03-24 18:37:18 +00:00
$pdf->SetFont('helvetica', '', 10);
2009-09-30 09:18:36 +00:00
// add a page
$pdf->AddPage();
2010-05-05 09:56:22 +00:00
// define barcode style
2009-09-30 09:18:36 +00:00
$style = array(
'position' => 'S',
'border' => true,
2010-05-05 09:56:22 +00:00
'padding' => 'auto',
2009-09-30 09:18:36 +00:00
'fgcolor' => array(0,0,0),
'bgcolor' => false, //array(255,255,255),
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
2009-04-11 17:02:39 +00:00
// PRINT VARIOUS 1D BARCODES
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9.
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 39 - ANSI MH10.8M-1983 - USD-3 - 3 of 9', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 39', 'C39', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 39 + CHECKSUM
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 39 + CHECKSUM', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 39 +', 'C39+', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 39 EXTENDED
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 39 EXTENDED', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 39 E', 'C39E', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 39 EXTENDED + CHECKSUM
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 93 - USS-93
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 93 - USS-93', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('TEST93', 'C93', '', '', 80, 15, 0.4, $style, 'N');
2009-04-15 17:08:37 +00:00
$pdf->Ln();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// Standard 2 of 5
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'Standard 2 of 5', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567', 'S25', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
$pdf->Ln();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// Standard 2 of 5 + CHECKSUM
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'Standard 2 of 5 + CHECKSUM', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567', 'S25+', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
// add a page ----------
$pdf->AddPage();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// Interleaved 2 of 5
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'Interleaved 2 of 5', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567', 'I25', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// Interleaved 2 of 5 + CHECKSUM
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'Interleaved 2 of 5 + CHECKSUM', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567', 'I25+', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 128 A
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 128 A', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 128 A', 'C128A', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 128 B
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 128 B', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('CODE 128 B', 'C128B', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 128 C
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 128 C', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('0123456789', 'C128C', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
$pdf->Ln();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// EAN 8
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'EAN 8', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567', 'EAN8', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// EAN 13
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'EAN 13', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('1234567890128', 'EAN13', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
// add a page ----------
$pdf->AddPage();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// 2-Digits UPC-Based Extention
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, '2-Digits UPC-Based Extention', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('34', 'EAN2', '', '', 20, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// 5-Digits UPC-Based Extention
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, '5-Digits UPC-Based Extention', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('51234', 'EAN5', '', '', 40, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// UPC-A
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'UPC-A', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('12345678901', 'UPCA', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// UPC-E
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'UPC-E', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('04210000526', 'UPCE', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
$pdf->Ln();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// MSI
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'MSI', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('80523', 'MSI', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// MSI + CHECKSUM (module 11)
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'MSI + CHECKSUM (module 11)', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('80523', 'MSI+', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
2010-05-05 09:56:22 +00:00
// add a page ----------
$pdf->AddPage();
2009-09-30 09:18:36 +00:00
2009-04-15 17:08:37 +00:00
// IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'IMB - Intelligent Mail Barcode - Onecode - USPS-B-3200', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('01234567094987654321-01234567891', 'IMB', '', '', 130, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// POSTNET
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'POSTNET', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('98000', 'POSTNET', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// PLANET
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'PLANET', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('98000', 'PLANET', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'RMS4CC (Royal Mail 4-state Customer Code) - CBC (Customer Bar Code)', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('SN34RD1A', 'RMS4CC', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// KIX (Klant index - Customer index)
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'KIX (Klant index - Customer index)', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('SN34RDX1A', 'KIX', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
// add a page ----------
$pdf->AddPage();
2009-04-15 17:08:37 +00:00
// CODABAR
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODABAR', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('123456789', 'CODABAR', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// CODE 11
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'CODE 11', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('123-456-789', 'CODE11', '', '', 80, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// PHARMACODE
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'PHARMACODE', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('789', 'PHARMA', '', '', 30, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
$pdf->Ln();
2009-04-15 17:08:37 +00:00
// PHARMACODE TWO-TRACKS
2009-09-30 09:18:36 +00:00
$pdf->Cell(0, 0, 'PHARMACODE TWO-TRACKS', 0, 1);
2010-05-05 09:56:22 +00:00
$pdf->write1DBarcode('105', 'PHARMA2T', '', '', 20, 15, 0.4, $style, 'N');
2009-09-30 09:18:36 +00:00
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2010-05-05 09:56:22 +00:00
// TEST BARCODE ALIGNMENTS
2009-09-30 09:18:36 +00:00
// add a page
$pdf->AddPage();
// Left alignment
$style['position'] = 'L';
$pdf->write1DBarcode('LEFT', 'C128A', '', '', 180, 30, 0.4, $style, 'N');
$pdf->Ln();
// Center alignment
$style['position'] = 'C';
$pdf->write1DBarcode('CENTER', 'C128A', '', '', 180, 30, 0.4, $style, 'N');
$pdf->Ln();
// Right alignment
$style['position'] = 'R';
$pdf->write1DBarcode('RIGHT', 'C128A', '', '', 180, 30, 0.4, $style, 'N');
2010-05-05 09:56:22 +00:00
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// TEST BARCODE STYLES
// add a page
$pdf->AddPage();
// define barcode style
$style = array(
'position' => 'S',
'border' => true,
'padding' => 'auto',
'fgcolor' => array(0,0,128),
'bgcolor' => array(255,255,128),
'text' => true,
'font' => 'helvetica',
'fontsize' => 8,
'stretchtext' => 4
);
// CODE 39 EXTENDED + CHECKSUM
$pdf->Cell(0, 0, 'CODE 39 EXTENDED + CHECKSUM', 0, 1);
2010-05-21 16:47:01 +00:00
$pdf->write1DBarcode('CODE 39 E+', 'C39E+', '', '', 100, 15, 0.4, $style, 'N');
2010-05-05 09:56:22 +00:00
2009-09-30 09:18:36 +00:00
// ---------------------------------------------------------
//Close and output PDF document
$pdf->Output('example_027.pdf', 'I');
//============================================================+
2010-05-05 09:56:22 +00:00
// END OF FILE
2009-09-30 09:18:36 +00:00
//============================================================+
2009-03-24 18:37:18 +00:00
?>