removed unused css classes
[openemr.git] / library / classes / PDF_Label.php
blob2934c32a2778f04871b88d426c4a3dade24971c3
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 // VERSIONS:
11 // 1.0: Initial release
12 // 1.1: + Added unit in the constructor
13 // + Now Positions start at (1,1).. then the first label at top-left of a page is (1,1)
14 // + Added in the description of a label:
15 // font-size : defaut char size (can be changed by calling Set_Char_Size(xx);
16 // paper-size: Size of the paper for this sheet (thanx to Al Canton)
17 // metric : type of unit used in this description
18 // You can define your label properties in inches by setting metric to
19 // 'in' and print in millimiters by setting unit to 'mm' in constructor
20 // Added some formats:
21 // 5160, 5161, 5162, 5163, 5164: thanks to Al Canton
22 // 8600 : thanks to Kunal Walia
23 // + Added 3mm to the position of labels to avoid errors
24 // 1.2: = Bug of positioning
25 // = Set_Font_Size modified -> Now, just modify the size of the font
26 // 1.3: + Labels are now printed horizontally
27 // = 'in' as document unit didn't work
28 // 1.4: + Page scaling is disabled in printing options
29 // 1.5: + Added 3422 format
30 ////////////////////////////////////////////////////////////////////////////////////////////////
32 // Modified to function in Open-emr 8-19-2014 Terry Hill terry@lillysystems.com
34 /**
35 * PDF_Label - PDF label editing
36 * @package PDF_Label
37 * @author Laurent PASSEBECQ
38 * @copyright 2003 Laurent PASSEBECQ
39 **/
41 require_once("$srcdir/fpdf/fpdf.php");
44 class eFPDF extends FPDF{
45 function TextWithRotation($x, $y, $txt, $txt_angle, $font_angle=0)
47 $font_angle+=90+$txt_angle;
48 $txt_angle*=M_PI/180;
49 $font_angle*=M_PI/180;
51 $txt_dx=cos($txt_angle);
52 $txt_dy=sin($txt_angle);
53 $font_dx=cos($font_angle);
54 $font_dy=sin($font_angle);
56 $s=sprintf('BT %.2F %.2F %.2F %.2F %.2F %.2F Tm (%s) Tj ET',$txt_dx,$txt_dy,$font_dx,$font_dy,$x*$this->k,($this->h-$y)*$this->k,$this->_escape($txt));
57 if ($this->ColorFlag)
58 $s='q '.$this->TextColor.' '.$s.' Q';
59 $this->_out($s);
64 class PDF_Label extends FPDF {
66 // Private properties
67 var $_Margin_Left; // Left margin of labels
68 var $_Margin_Top; // Top margin of labels
69 var $_X_Space; // Horizontal space between 2 labels
70 var $_Y_Space; // Vertical space between 2 labels
71 var $_X_Number; // Number of labels horizontally
72 var $_Y_Number; // Number of labels vertically
73 var $_Width; // Width of label
74 var $_Height; // Height of label
75 var $_Line_Height; // Line height
76 var $_Padding; // Padding
77 var $_Metric_Doc; // Type of metric for the document
78 var $_COUNTX; // Current x position
79 var $_COUNTY; // Current y position
81 // List of label formats
82 var $_Avery_Labels = array(
83 '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'=>10),
84 '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'=>10),
85 '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'=>10),
86 '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),
87 '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),
88 '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),
89 '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),
90 '3422' => array('paper-size'=>'A4', 'metric'=>'mm', 'marginLeft'=>0, 'marginTop'=>8.5, 'NX'=>3, 'NY'=>8, 'SpaceX'=>0, 'SpaceY'=>0, 'width'=>70, 'height'=>35, 'font-size'=>9)
93 // Constructor
94 function __construct($format, $unit='mm', $posX=1, $posY=1) {
95 if (is_array($format)) {
96 // Custom format
97 $Tformat = $format;
98 } else {
99 // Built-in format
100 if (!isset($this->_Avery_Labels[$format]))
101 $this->Error('Unknown label format: '.$format);
102 $Tformat = $this->_Avery_Labels[$format];
105 parent::__construct('P', $unit, $Tformat['paper-size']);
106 $this->_Metric_Doc = $unit;
107 $this->_Set_Format($Tformat);
108 $this->SetFont('Arial');
109 $this->SetMargins(0,0);
110 $this->SetAutoPageBreak(false);
111 $this->_COUNTX = $posX-2;
112 $this->_COUNTY = $posY-1;
115 function _Set_Format($format) {
116 $this->_Margin_Left = $this->_Convert_Metric($format['marginLeft'], $format['metric']);
117 $this->_Margin_Top = $this->_Convert_Metric($format['marginTop'], $format['metric']);
118 $this->_X_Space = $this->_Convert_Metric($format['SpaceX'], $format['metric']);
119 $this->_Y_Space = $this->_Convert_Metric($format['SpaceY'], $format['metric']);
120 $this->_X_Number = $format['NX'];
121 $this->_Y_Number = $format['NY'];
122 $this->_Width = $this->_Convert_Metric($format['width'], $format['metric']);
123 $this->_Height = $this->_Convert_Metric($format['height'], $format['metric']);
124 $this->Set_Font_Size($format['font-size']);
125 $this->_Padding = $this->_Convert_Metric(3, 'mm');
128 // convert units (in to mm, mm to in)
129 // $src must be 'in' or 'mm'
130 function _Convert_Metric($value, $src) {
131 $dest = $this->_Metric_Doc;
132 if ($src != $dest) {
133 $a['in'] = 39.37008;
134 $a['mm'] = 1000;
135 return $value * $a[$dest] / $a[$src];
136 } else {
137 return $value;
141 // Give the line height for a given font size
142 function _Get_Height_Chars($pt) {
143 $a = array(6=>2, 7=>2.5, 8=>3, 9=>4, 10=>5, 11=>6, 12=>7, 13=>8, 14=>9, 15=>10);
144 if (!isset($a[$pt]))
145 $this->Error('Invalid font size: '.$pt);
146 return $this->_Convert_Metric($a[$pt], 'mm');
149 // Set the character size
150 // This changes the line height too
151 function Set_Font_Size($pt) {
152 $this->_Line_Height = $this->_Get_Height_Chars($pt);
153 $this->SetFontSize($pt);
156 // Print a label
157 function Add_Label($text) {
158 $this->_COUNTX++;
159 if ($this->_COUNTX == $this->_X_Number) {
160 // Row full, we start a new one
161 $this->_COUNTX=0;
162 $this->_COUNTY++;
163 if ($this->_COUNTY == $this->_Y_Number) {
164 // End of page reached, we start a new one
165 $this->_COUNTY=0;
166 $this->AddPage();
170 $_PosX = $this->_Margin_Left + $this->_COUNTX*($this->_Width+$this->_X_Space) + $this->_Padding;
171 $_PosY = $this->_Margin_Top + $this->_COUNTY*($this->_Height+$this->_Y_Space) + $this->_Padding;
172 $this->SetXY($_PosX, $_PosY);
173 $this->MultiCell($this->_Width - $this->_Padding, $this->_Line_Height, $text, 0, 'L');
176 function _putcatalog()
178 parent::_putcatalog();
179 // Disable the page scaling option in the printing dialog
180 $this->_out('/ViewerPreferences <</PrintScaling /None>>');