Skip to content

Commit d307f84

Browse files
committed
first commit
1 parent c1c5892 commit d307f84

39 files changed

+8530
-0
lines changed

PDF_Label.php

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?php
2+
////////////////////////////////////////////////////////////////////////////////////////////////
3+
// PDF_Label
4+
//
5+
// Class to print labels in Avery or custom formats
6+
//
7+
// Copyright (C) 2003 Laurent PASSEBECQ (LPA)
8+
// Based on code by Steve Dillon
9+
//
10+
//---------------------------------------------------------------------------------------------
11+
// VERSIONS:
12+
// 1.0: Initial release
13+
// 1.1: + Added unit in the constructor
14+
// + Now Positions start at (1,1).. then the first label at top-left of a page is (1,1)
15+
// + Added in the description of a label:
16+
// font-size : defaut char size (can be changed by calling Set_Char_Size(xx);
17+
// paper-size: Size of the paper for this sheet (thanx to Al Canton)
18+
// metric : type of unit used in this description
19+
// You can define your label properties in inches by setting metric to
20+
// 'in' and print in millimiters by setting unit to 'mm' in constructor
21+
// Added some formats:
22+
// 5160, 5161, 5162, 5163, 5164: thanks to Al Canton
23+
// 8600 : thanks to Kunal Walia
24+
// + Added 3mm to the position of labels to avoid errors
25+
// 1.2: = Bug of positioning
26+
// = Set_Font_Size modified -> Now, just modify the size of the font
27+
// 1.3: + Labels are now printed horizontally
28+
// = 'in' as document unit didn't work
29+
// 1.4: + Page scaling is disabled in printing options
30+
// 1.5: + Added 3422 format
31+
////////////////////////////////////////////////////////////////////////////////////////////////
32+
33+
/**
34+
* PDF_Label - PDF label editing
35+
* @package PDF_Label
36+
* @author Laurent PASSEBECQ
37+
* @copyright 2003 Laurent PASSEBECQ
38+
**/
39+
40+
require_once('fpdf.php');
41+
42+
class PDF_Label extends FPDF {
43+
44+
// Private properties
45+
var $_Margin_Left; // Left margin of labels
46+
var $_Margin_Top; // Top margin of labels
47+
var $_X_Space; // Horizontal space between 2 labels
48+
var $_Y_Space; // Vertical space between 2 labels
49+
var $_X_Number; // Number of labels horizontally
50+
var $_Y_Number; // Number of labels vertically
51+
var $_Width; // Width of label
52+
var $_Height; // Height of label
53+
var $_Line_Height; // Line height
54+
var $_Padding; // Padding
55+
var $_Metric_Doc; // Type of metric for the document
56+
var $_COUNTX; // Current x position
57+
var $_COUNTY; // Current y position
58+
59+
// List of label formats
60+
var $_Avery_Labels = array(
61+
'5160' => array('paper-size'=>'letter', 'metric'=>'mm', 'marginLeft'=>1.762, 'marginTop'=>10.7, 'NX'=>3, 'NY'=>10, 'SpaceX'=>3.175, 'SpaceY'=>0, 'width'=>66.675, 'height'=>25.4, 'font-size'=>8),
62+
'5161' => array('paper-size'=>'letter', 'metric'=>'mm', 'marginLeft'=>0.967, 'marginTop'=>10.7, 'NX'=>2, 'NY'=>10, 'SpaceX'=>3.967, 'SpaceY'=>0, 'width'=>101.6, 'height'=>25.4, 'font-size'=>8),
63+
'5162' => array('paper-size'=>'letter', 'metric'=>'mm', 'marginLeft'=>0.97, 'marginTop'=>20.224, 'NX'=>2, 'NY'=>7, 'SpaceX'=>4.762, 'SpaceY'=>0, 'width'=>100.807, 'height'=>35.72, 'font-size'=>8),
64+
'5163' => array('paper-size'=>'letter', 'metric'=>'mm', 'marginLeft'=>1.762, 'marginTop'=>10.7, 'NX'=>2, 'NY'=>5, 'SpaceX'=>3.175, 'SpaceY'=>0, 'width'=>101.6, 'height'=>50.8, 'font-size'=>8),
65+
'5164' => array('paper-size'=>'letter', 'metric'=>'in', 'marginLeft'=>0.148, 'marginTop'=>0.5, 'NX'=>2, 'NY'=>3, 'SpaceX'=>0.2031, 'SpaceY'=>0, 'width'=>4.0, 'height'=>3.33, 'font-size'=>12),
66+
'8600' => array('paper-size'=>'letter', 'metric'=>'mm', 'marginLeft'=>7.1, 'marginTop'=>19, 'NX'=>3, 'NY'=>10, 'SpaceX'=>9.5, 'SpaceY'=>3.1, 'width'=>66.6, 'height'=>25.4, 'font-size'=>8),
67+
'L7163'=> array('paper-size'=>'A4', 'metric'=>'mm', 'marginLeft'=>5, 'marginTop'=>15, 'NX'=>2, 'NY'=>7, 'SpaceX'=>25, 'SpaceY'=>0, 'width'=>99.1, 'height'=>38.1, 'font-size'=>9),
68+
'3422' => array('paper-size'=>'A4', 'metric'=>'mm', 'marginLeft'=>7, 'marginTop'=>12, 'NX'=>3, 'NY'=>8, 'SpaceX'=>3, 'SpaceY'=>0, 'width'=>63.5, 'height'=>33.9, 'font-size'=>9)
69+
);
70+
71+
// Constructor
72+
function PDF_Label($format, $unit='mm', $posX=1, $posY=1) {
73+
if (is_array($format)) {
74+
// Custom format
75+
$Tformat = $format;
76+
} else {
77+
// Built-in format
78+
if (!isset($this->_Avery_Labels[$format]))
79+
$this->Error('Unknown label format: '.$format);
80+
$Tformat = $this->_Avery_Labels[$format];
81+
}
82+
83+
parent::__construct('P', $unit, $Tformat['paper-size']);
84+
$this->_Metric_Doc = $unit;
85+
$this->_Set_Format($Tformat);
86+
$this->SetFont('Arial');
87+
$this->SetMargins(0,0);
88+
$this->SetAutoPageBreak(false);
89+
$this->_COUNTX = $posX-2;
90+
$this->_COUNTY = $posY-1;
91+
}
92+
93+
function _Set_Format($format) {
94+
$this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $format['metric']);
95+
$this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $format['metric']);
96+
$this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $format['metric']);
97+
$this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $format['metric']);
98+
$this->_X_Number = $format['NX'];
99+
$this->_Y_Number = $format['NY'];
100+
$this->_Width = $this->_Convert_Metric($format['width'], $format['metric']);
101+
$this->_Height = $this->_Convert_Metric($format['height'], $format['metric']);
102+
$this->Set_Font_Size($format['font-size']);
103+
$this->_Padding = $this->_Convert_Metric(3, 'mm');
104+
}
105+
106+
// convert units (in to mm, mm to in)
107+
// $src must be 'in' or 'mm'
108+
function _Convert_Metric($value, $src) {
109+
$dest = $this->_Metric_Doc;
110+
if ($src != $dest) {
111+
$a['in'] = 39.37008;
112+
$a['mm'] = 1000;
113+
return $value * $a[$dest] / $a[$src];
114+
} else {
115+
return $value;
116+
}
117+
}
118+
119+
// Give the line height for a given font size
120+
function _Get_Height_Chars($pt) {
121+
$a = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
122+
if (!isset($a[$pt]))
123+
$this->Error('Invalid font size: '.$pt);
124+
return $this->_Convert_Metric($a[$pt], 'mm');
125+
}
126+
127+
// Set the character size
128+
// This changes the line height too
129+
function Set_Font_Size($pt) {
130+
$this->_Line_Height = $this->_Get_Height_Chars($pt);
131+
$this->SetFontSize($pt);
132+
}
133+
134+
// Print a label
135+
function Add_Label($text) {
136+
$this->_COUNTX++;
137+
if ($this->_COUNTX == $this->_X_Number) {
138+
// Row full, we start a new one
139+
$this->_COUNTX=0;
140+
$this->_COUNTY++;
141+
if ($this->_COUNTY == $this->_Y_Number) {
142+
// End of page reached, we start a new one
143+
$this->_COUNTY=0;
144+
$this->AddPage();
145+
}
146+
}
147+
148+
$_PosX = $this->_Margin_Left + $this->_COUNTX*($this->_Width+$this->_X_Space) + $this->_Padding;
149+
$_PosY = $this->_Margin_Top + $this->_COUNTY*($this->_Height+$this->_Y_Space) + $this->_Padding;
150+
$this->SetXY($_PosX, $_PosY);
151+
152+
$this->MultiCell($this->_Width - $this->_Padding, $this->_Line_Height, $text, 0, 'L');
153+
}
154+
155+
function _putcatalog()
156+
{
157+
parent::_putcatalog();
158+
// Disable the page scaling option in the printing dialog
159+
$this->_out('/ViewerPreferences <</PrintScaling /None>>');
160+
}
161+
162+
}
163+
?>

font/courier.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Courier';
4+
$up = -100;
5+
$ut = 50;
6+
for($i=0;$i<=255;$i++)
7+
$cw[chr($i)] = 600;
8+
$enc = 'cp1252';
9+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
10+
?>

font/courierb.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Courier-Bold';
4+
$up = -100;
5+
$ut = 50;
6+
for($i=0;$i<=255;$i++)
7+
$cw[chr($i)] = 600;
8+
$enc = 'cp1252';
9+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
10+
?>

font/courierbi.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Courier-BoldOblique';
4+
$up = -100;
5+
$ut = 50;
6+
for($i=0;$i<=255;$i++)
7+
$cw[chr($i)] = 600;
8+
$enc = 'cp1252';
9+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
10+
?>

font/courieri.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Courier-Oblique';
4+
$up = -100;
5+
$ut = 50;
6+
for($i=0;$i<=255;$i++)
7+
$cw[chr($i)] = 600;
8+
$enc = 'cp1252';
9+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
10+
?>

font/helvetica.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Helvetica';
4+
$up = -100;
5+
$ut = 50;
6+
$cw = array(
7+
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
8+
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>278,'"'=>355,'#'=>556,'$'=>556,'%'=>889,'&'=>667,'\''=>191,'('=>333,')'=>333,'*'=>389,'+'=>584,
9+
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>278,';'=>278,'<'=>584,'='=>584,'>'=>584,'?'=>556,'@'=>1015,'A'=>667,
10+
'B'=>667,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>500,'K'=>667,'L'=>556,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944,
11+
'X'=>667,'Y'=>667,'Z'=>611,'['=>278,'\\'=>278,']'=>278,'^'=>469,'_'=>556,'`'=>333,'a'=>556,'b'=>556,'c'=>500,'d'=>556,'e'=>556,'f'=>278,'g'=>556,'h'=>556,'i'=>222,'j'=>222,'k'=>500,'l'=>222,'m'=>833,
12+
'n'=>556,'o'=>556,'p'=>556,'q'=>556,'r'=>333,'s'=>500,'t'=>278,'u'=>556,'v'=>500,'w'=>722,'x'=>500,'y'=>500,'z'=>500,'{'=>334,'|'=>260,'}'=>334,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>222,chr(131)=>556,
13+
chr(132)=>333,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>222,chr(146)=>222,chr(147)=>333,chr(148)=>333,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000,
14+
chr(154)=>500,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>260,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333,
15+
chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>556,chr(182)=>537,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>667,chr(193)=>667,chr(194)=>667,chr(195)=>667,chr(196)=>667,chr(197)=>667,
16+
chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722,
17+
chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>500,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>556,chr(241)=>556,
18+
chr(242)=>556,chr(243)=>556,chr(244)=>556,chr(245)=>556,chr(246)=>556,chr(247)=>584,chr(248)=>611,chr(249)=>556,chr(250)=>556,chr(251)=>556,chr(252)=>556,chr(253)=>500,chr(254)=>556,chr(255)=>500);
19+
$enc = 'cp1252';
20+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
21+
?>

font/helveticab.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
$type = 'Core';
3+
$name = 'Helvetica-Bold';
4+
$up = -100;
5+
$ut = 50;
6+
$cw = array(
7+
chr(0)=>278,chr(1)=>278,chr(2)=>278,chr(3)=>278,chr(4)=>278,chr(5)=>278,chr(6)=>278,chr(7)=>278,chr(8)=>278,chr(9)=>278,chr(10)=>278,chr(11)=>278,chr(12)=>278,chr(13)=>278,chr(14)=>278,chr(15)=>278,chr(16)=>278,chr(17)=>278,chr(18)=>278,chr(19)=>278,chr(20)=>278,chr(21)=>278,
8+
chr(22)=>278,chr(23)=>278,chr(24)=>278,chr(25)=>278,chr(26)=>278,chr(27)=>278,chr(28)=>278,chr(29)=>278,chr(30)=>278,chr(31)=>278,' '=>278,'!'=>333,'"'=>474,'#'=>556,'$'=>556,'%'=>889,'&'=>722,'\''=>238,'('=>333,')'=>333,'*'=>389,'+'=>584,
9+
','=>278,'-'=>333,'.'=>278,'/'=>278,'0'=>556,'1'=>556,'2'=>556,'3'=>556,'4'=>556,'5'=>556,'6'=>556,'7'=>556,'8'=>556,'9'=>556,':'=>333,';'=>333,'<'=>584,'='=>584,'>'=>584,'?'=>611,'@'=>975,'A'=>722,
10+
'B'=>722,'C'=>722,'D'=>722,'E'=>667,'F'=>611,'G'=>778,'H'=>722,'I'=>278,'J'=>556,'K'=>722,'L'=>611,'M'=>833,'N'=>722,'O'=>778,'P'=>667,'Q'=>778,'R'=>722,'S'=>667,'T'=>611,'U'=>722,'V'=>667,'W'=>944,
11+
'X'=>667,'Y'=>667,'Z'=>611,'['=>333,'\\'=>278,']'=>333,'^'=>584,'_'=>556,'`'=>333,'a'=>556,'b'=>611,'c'=>556,'d'=>611,'e'=>556,'f'=>333,'g'=>611,'h'=>611,'i'=>278,'j'=>278,'k'=>556,'l'=>278,'m'=>889,
12+
'n'=>611,'o'=>611,'p'=>611,'q'=>611,'r'=>389,'s'=>556,'t'=>333,'u'=>611,'v'=>556,'w'=>778,'x'=>556,'y'=>556,'z'=>500,'{'=>389,'|'=>280,'}'=>389,'~'=>584,chr(127)=>350,chr(128)=>556,chr(129)=>350,chr(130)=>278,chr(131)=>556,
13+
chr(132)=>500,chr(133)=>1000,chr(134)=>556,chr(135)=>556,chr(136)=>333,chr(137)=>1000,chr(138)=>667,chr(139)=>333,chr(140)=>1000,chr(141)=>350,chr(142)=>611,chr(143)=>350,chr(144)=>350,chr(145)=>278,chr(146)=>278,chr(147)=>500,chr(148)=>500,chr(149)=>350,chr(150)=>556,chr(151)=>1000,chr(152)=>333,chr(153)=>1000,
14+
chr(154)=>556,chr(155)=>333,chr(156)=>944,chr(157)=>350,chr(158)=>500,chr(159)=>667,chr(160)=>278,chr(161)=>333,chr(162)=>556,chr(163)=>556,chr(164)=>556,chr(165)=>556,chr(166)=>280,chr(167)=>556,chr(168)=>333,chr(169)=>737,chr(170)=>370,chr(171)=>556,chr(172)=>584,chr(173)=>333,chr(174)=>737,chr(175)=>333,
15+
chr(176)=>400,chr(177)=>584,chr(178)=>333,chr(179)=>333,chr(180)=>333,chr(181)=>611,chr(182)=>556,chr(183)=>278,chr(184)=>333,chr(185)=>333,chr(186)=>365,chr(187)=>556,chr(188)=>834,chr(189)=>834,chr(190)=>834,chr(191)=>611,chr(192)=>722,chr(193)=>722,chr(194)=>722,chr(195)=>722,chr(196)=>722,chr(197)=>722,
16+
chr(198)=>1000,chr(199)=>722,chr(200)=>667,chr(201)=>667,chr(202)=>667,chr(203)=>667,chr(204)=>278,chr(205)=>278,chr(206)=>278,chr(207)=>278,chr(208)=>722,chr(209)=>722,chr(210)=>778,chr(211)=>778,chr(212)=>778,chr(213)=>778,chr(214)=>778,chr(215)=>584,chr(216)=>778,chr(217)=>722,chr(218)=>722,chr(219)=>722,
17+
chr(220)=>722,chr(221)=>667,chr(222)=>667,chr(223)=>611,chr(224)=>556,chr(225)=>556,chr(226)=>556,chr(227)=>556,chr(228)=>556,chr(229)=>556,chr(230)=>889,chr(231)=>556,chr(232)=>556,chr(233)=>556,chr(234)=>556,chr(235)=>556,chr(236)=>278,chr(237)=>278,chr(238)=>278,chr(239)=>278,chr(240)=>611,chr(241)=>611,
18+
chr(242)=>611,chr(243)=>611,chr(244)=>611,chr(245)=>611,chr(246)=>611,chr(247)=>584,chr(248)=>611,chr(249)=>611,chr(250)=>611,chr(251)=>611,chr(252)=>611,chr(253)=>556,chr(254)=>611,chr(255)=>556);
19+
$enc = 'cp1252';
20+
$uv = array(0=>array(0,128),128=>8364,130=>8218,131=>402,132=>8222,133=>8230,134=>array(8224,2),136=>710,137=>8240,138=>352,139=>8249,140=>338,142=>381,145=>array(8216,2),147=>array(8220,2),149=>8226,150=>array(8211,2),152=>732,153=>8482,154=>353,155=>8250,156=>339,158=>382,159=>376,160=>array(160,96));
21+
?>

0 commit comments

Comments
 (0)