-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathCezpdf.php
More file actions
2392 lines (2234 loc) · 97.8 KB
/
Cezpdf.php
File metadata and controls
2392 lines (2234 loc) · 97.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
include_once 'Cpdf.php';
/*
* draw all lines to ezTable output
*/
define('EZ_GRIDLINE_ALL', 31);
/*
* draw default set of lines to ezTable output, so EZ_GRIDLINE_TABLE, EZ_GRIDLINE_HEADERONLY and EZ_GRIDLINE_COLUMNS
*/
define('EZ_GRIDLINE_DEFAULT', 29); // same as EZ_GRIDLINE_TABLE + EZ_GRIDLINE_HEADERONLY + EZ_GRIDLINE_COLUMNS
/*
* draw the outer lines of the ezTable
*/
define('EZ_GRIDLINE_TABLE', 24);
/*
* draw the outer horizontal lines of the ezTable
*/
define('EZ_GRIDLINE_TABLE_H', 16);
/*
* draw the outer vertical lines of the ezTable
*/
define('EZ_GRIDLINE_TABLE_V', 8);
/*
* draw a horizontal line between header and first data row
*/
define('EZ_GRIDLINE_HEADERONLY', 4);
/*
* draw a horizontal line for each row
*/
define('EZ_GRIDLINE_ROWS', 2);
/*
* draw a vertical line for each column
*/
define('EZ_GRIDLINE_COLUMNS', 1);
/**
* Helper class to create pdf documents via ROS PDF class called 'Cpdf'.
*
* This class will take the basic interaction facilities of the Cpdf class
* and make more useful functions so that the user does not have to
* know all the ins and outs of pdf presentation to produce something pretty.
*
* @category Documents
* @author Wayne Munro, R&OS Ltd, <http://www.ros.co.nz/pdf>
* @author Ole Koeckemann <ole.k@web.de>
* @author Lars Olesen <lars@legestue.net>
* @author Nicola Asuni <info@tecnick.com>
* @link https://github.com/rospdf/pdf-php
*/
class Cezpdf extends Cpdf
{
/**
* used to store most of the page configuration parameters.
*/
public $ez = ['fontSize' => 10];
/**
* stores the actual vertical position on the page of the writing point, very important.
*/
public $y;
/**
* keep an array of the ids of the pages, making it easy to go back and add page numbers etc.
*/
public $ezPages = [];
/**
* stores the number of pages used in this document.
*/
public $ezPageCount = 0;
/**
* background color/image information.
*/
protected $ezBackground = [];
/**
* Assuming that people don't want to specify the paper size using the absolute coordinates
* allow a couple of options:
* orientation can be 'portrait' or 'landscape'
* or, to actually set the coordinates, then pass an array in as the first parameter.
* the defaults are as shown
*
* 2002-07-24 - Nicola Asuni (info@tecnick.com)
* Added new page formats (45 standard ISO paper formats and 4 american common formats)
* paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
*
* **$options**<br>
* if $type equals to 'color'<br>
* $options[0] = red-component of backgroundcolour ( 0 <= r <= 1)<br>
* $options[1] = green-component of backgroundcolour ( 0 <= g <= 1)<br>
* $options[2] = blue-component of backgroundcolour ( 0 <= b <= 1)<br>
* if $type equals to 'image':<br>
* $options['img'] = location of image file; URI's are allowed if allow_url_open is enabled in php.ini<br>
* $options['width'] = width of background image; default is width of page<br>
* $options['height'] = height of background image; default is height of page<br>
* $options['xpos'] = horizontal position of background image; default is 0<br>
* $options['ypos'] = vertical position of background image; default is 0<br>
* $options['repeat'] = repeat image horizontally (1), repeat image vertically (2) or full in both directions (3); default is 0<br>
*
* highly recommend to set this->hashed to true when using repeat function<br>
*
* @since [0.11.3] added repeat option for images
*
* @param mixed $paper paper format as string ('A4', 'A5', 'B5', ...) or an array with two/four elements defining the size
* @param string $orientation either portrait or landscape
* @param string $type background type - 'none', 'image' or 'color'
* @param array $options see options from above
**/
public function __construct($paper = 'a4', $orientation = 'portrait', $type = 'none', $options = [])
{
if (!is_array($paper)) {
switch (strtoupper($paper)) {
case '4A0':
$size = [0, 0, 4767.87, 6740.79];
break;
case '2A0':
$size = [0, 0, 3370.39, 4767.87];
break;
case 'A0':
$size = [0, 0, 2383.94, 3370.39];
break;
case 'A1':
$size = [0, 0, 1683.78, 2383.94];
break;
case 'A2':
$size = [0, 0, 1190.55, 1683.78];
break;
case 'A3':
$size = [0, 0, 841.89, 1190.55];
break;
case 'A4':
default:
$size = [0, 0, 595.28, 841.89];
break;
case 'A5':
$size = [0, 0, 419.53, 595.28];
break;
case 'A6':
$size = [0, 0, 297.64, 419.53];
break;
case 'A7':
$size = [0, 0, 209.76, 297.64];
break;
case 'A8':
$size = [0, 0, 147.40, 209.76];
break;
case 'A9':
$size = [0, 0, 104.88, 147.40];
break;
case 'A10':
$size = [0, 0, 73.70, 104.88];
break;
case 'B0':
$size = [0, 0, 2834.65, 4008.19];
break;
case 'B1':
$size = [0, 0, 2004.09, 2834.65];
break;
case 'B2':
$size = [0, 0, 1417.32, 2004.09];
break;
case 'B3':
$size = [0, 0, 1000.63, 1417.32];
break;
case 'B4':
$size = [0, 0, 708.66, 1000.63];
break;
case 'B5':
$size = [0, 0, 498.90, 708.66];
break;
case 'B6':
$size = [0, 0, 354.33, 498.90];
break;
case 'B7':
$size = [0, 0, 249.45, 354.33];
break;
case 'B8':
$size = [0, 0, 175.75, 249.45];
break;
case 'B9':
$size = [0, 0, 124.72, 175.75];
break;
case 'B10':
$size = [0, 0, 87.87, 124.72];
break;
case 'C0':
$size = [0, 0, 2599.37, 3676.54];
break;
case 'C1':
$size = [0, 0, 1836.85, 2599.37];
break;
case 'C2':
$size = [0, 0, 1298.27, 1836.85];
break;
case 'C3':
$size = [0, 0, 918.43, 1298.27];
break;
case 'C4':
$size = [0, 0, 649.13, 918.43];
break;
case 'C5':
$size = [0, 0, 459.21, 649.13];
break;
case 'C6':
$size = [0, 0, 323.15, 459.21];
break;
case 'C7':
$size = [0, 0, 229.61, 323.15];
break;
case 'C8':
$size = [0, 0, 161.57, 229.61];
break;
case 'C9':
$size = [0, 0, 113.39, 161.57];
break;
case 'C10':
$size = [0, 0, 79.37, 113.39];
break;
case 'RA0':
$size = [0, 0, 2437.80, 3458.27];
break;
case 'RA1':
$size = [0, 0, 1729.13, 2437.80];
break;
case 'RA2':
$size = [0, 0, 1218.90, 1729.13];
break;
case 'RA3':
$size = [0, 0, 864.57, 1218.90];
break;
case 'RA4':
$size = [0, 0, 609.45, 864.57];
break;
case 'SRA0':
$size = [0, 0, 2551.18, 3628.35];
break;
case 'SRA1':
$size = [0, 0, 1814.17, 2551.18];
break;
case 'SRA2':
$size = [0, 0, 1275.59, 1814.17];
break;
case 'SRA3':
$size = [0, 0, 907.09, 1275.59];
break;
case 'SRA4':
$size = [0, 0, 637.80, 907.09];
break;
case 'LETTER':
$size = [0, 0, 612.00, 792.00];
break;
case 'LEGAL':
$size = [0, 0, 612.00, 1008.00];
break;
case 'EXECUTIVE':
$size = [0, 0, 521.86, 756.00];
break;
case 'FOLIO':
$size = [0, 0, 612.00, 936.00];
break;
}
switch (strtolower($orientation)) {
case 'landscape':
$a = $size[3];
$size[3] = $size[2];
$size[2] = $a;
break;
}
} else {
if (count($paper) > 2) {
// then an array was sent it to set the size
$size = $paper;
} else { //size in centimeters has been passed
$size[0] = 0;
$size[1] = 0;
$size[2] = ($paper[0] / 2.54) * 72;
$size[3] = ($paper[1] / 2.54) * 72;
}
}
parent::__construct($size);
$this->ez['pageWidth'] = $size[2];
$this->ez['pageHeight'] = $size[3];
// also set the margins to some reasonable defaults
$this->ez['topMargin'] = 30;
$this->ez['bottomMargin'] = 30;
$this->ez['leftMargin'] = 30;
$this->ez['rightMargin'] = 30;
// set the current writing position to the top of the first page
$this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
// and get the ID of the page that was created during the instancing process.
$this->ezPages[1] = $this->getFirstPageId();
$this->ezPageCount = 1;
switch ($type) {
case 'color':
case 'colour':
$this->ezBackground['type'] = 'color';
$this->ezBackground['color'] = $options;
break;
case 'image':
if (!isset($options['img'])) {
$errormsg = 'Background Image not set.';
break;
}
if (!file_exists($options['img'])) {
$errormsg = "Background Image does not exists: '".$options['img']."'";
break;
}
$im = getimagesize($options['img']);
if ($im === false) {
$errormsg = "Background Image is invalid: '".$options['img']."'";
break;
}
$this->ezBackground['type'] = 'image';
$this->ezBackground['image'] = $options['img'];
$this->ezBackground['format'] = $im[2];
$this->ezBackground['repeat'] = $options['repeat'];
if (isset($options['width']) && is_numeric($options['width'])) {
$this->ezBackground['width'] = $options['width'];
} else {
$this->ezBackground['width'] = $this->ez['pageWidth'];
}
if (isset($options['height']) && is_numeric($options['height'])) {
$this->ezBackground['height'] = $options['height'];
} else {
$this->ezBackground['height'] = $this->ez['pageHeight'];
}
if (isset($options['xpos']) && is_numeric($options['xpos'])) {
$this->ezBackground['xpos'] = $options['xpos'];
} else {
$this->ezBackground['xpos'] = 0;
}
if (isset($options['ypos']) && is_numeric($options['ypos'])) {
$this->ezBackground['ypos'] = $options['ypos'];
} else {
$this->ezBackground['ypos'] = 0;
}
break;
case 'none':
default:
$this->ezBackground['type'] = 'none';
break;
}
$this->setBackground();
}
/**
* set the background image or color on all pages
* gets executed in constructor and in ezNewPage.
*/
protected function setBackground()
{
if (isset($this->ezBackground['type'])) {
switch ($this->ezBackground['type']) {
case 'color':
if (isset($this->ezBackground['color']) && is_array($this->ezBackground['color']) && count($this->ezBackground['color']) == 3) {
$this->saveState();
$this->setColor($this->ezBackground['color'][0], $this->ezBackground['color'][1], $this->ezBackground['color'][2], 1);
$this->filledRectangle(0, 0, $this->ez['pageWidth'], $this->ez['pageHeight']);
$this->restoreState();
}
break;
case 'image':
$ypos = $this->ezBackground['ypos'];
$xpos = $this->ezBackground['xpos'];
if ($this->ezBackground['repeat'] == 1) {
$xpos = 0;
}
if ($this->ezBackground['repeat'] == 2) {
$ypos = 0;
}
$this->addBackgroundImage($xpos, $ypos);
if ($this->ezBackground['repeat'] & 1) { // repeat-x
$numX = ceil($this->ez['pageWidth'] / $this->ezBackground['width']);
for ($i = 0; $i < $numX; ++$i) {
$xpos = ($this->ezBackground['width'] * $i);
$this->addBackgroundImage($xpos, $ypos);
}
}
if ($this->ezBackground['repeat'] & 2) { // repeat-y
$numY = ceil($this->ez['pageHeight'] / $this->ezBackground['height']);
for ($i = 0; $i < $numY; ++$i) {
$ypos = ($this->ezBackground['height'] * $i);
$this->addBackgroundImage($xpos, $ypos);
}
}
if ($this->ezBackground['repeat'] == 3) { // repeat all
$numX = ceil($this->ez['pageWidth'] / $this->ezBackground['width']);
$numY = ceil($this->ez['pageHeight'] / $this->ezBackground['height']);
for ($i = 0; $i < $numX; ++$i) {
$xpos = ($this->ezBackground['width'] * $i);
for ($j = 0; $j < $numY; ++$j) {
$ypos = ($this->ezBackground['height'] * $j);
$this->addBackgroundImage($xpos, $ypos);
}
}
}
break;
case 'none':
default:
break;
}
}
}
/**
* add background image for JPEG and PNG file format
* Especially used for repeating function.
*
* @param float $xOffset horizontal offset
* @param float $yOffset vertical offset
*/
private function addBackgroundImage($xOffset = 0, $yOffset = 0)
{
switch ($this->ezBackground['format']) {
case IMAGETYPE_JPEG:
$this->addJpegFromFile($this->ezBackground['image'], $xOffset, $yOffset, $this->ezBackground['width'], $this->ezBackground['height']);
break;
case IMAGETYPE_PNG:
$this->addPngFromFile($this->ezBackground['image'], $xOffset, $yOffset, $this->ezBackground['width'], $this->ezBackground['height']);
break;
}
}
/**
* setup a margin on document page.
*
* **Example**<br>
* <pre>
* $pdf->ezSetMargins(50,50,50,50)
* </pre>
*
* @param float $top top margin
* @param float $bottom botom margin
* @param float $left left margin
* @param float $right right margin
*/
public function ezSetMargins($top, $bottom, $left, $right)
{
// sets the margins to new values
$this->ez['topMargin'] = $top;
$this->ez['bottomMargin'] = $bottom;
$this->ez['leftMargin'] = $left;
$this->ez['rightMargin'] = $right;
// check to see if this means that the current writing position is outside the
// writable area
if ($this->y > $this->ez['pageHeight'] - $top) {
// then move y down
$this->y = $this->ez['pageHeight'] - $top;
}
if ($this->y < $bottom) {
// then make a new page
$this->ezNewPage();
}
}
/**
* setup a margin on document page.
*
* @author 2002-07-24: Nicola Asuni (info@tecnick.com)
*
* @param float $top top margin in cm
* @param float $bottom botom margin in cm
* @param float $left left margin in cm
* @param float $right right margin in cm
*/
public function ezSetCmMargins($top, $bottom, $left, $right)
{
$top = ($top / 2.54) * 72;
$bottom = ($bottom / 2.54) * 72;
$left = ($left / 2.54) * 72;
$right = ($right / 2.54) * 72;
$this->ezSetMargins($top, $bottom, $left, $right);
}
/**
* create a new page.
*
* **Example**<br>
* <pre>
* $pdf->ezNewPage()
* </pre>
*/
public function ezNewPage()
{
$pageRequired = 1;
if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1) {
// check if this is just going to a new column
// increment the column number
//echo 'HERE<br>';
++$this->ez['columns']['colNum'];
//echo $this->ez['columns']['colNum'].'<br>';
if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num']) {
// then just reset to the top of the next column
$pageRequired = 0;
} else {
$this->ez['columns']['colNum'] = 1;
$this->ez['topMargin'] = $this->ez['columns']['margins'][2];
}
$width = $this->ez['columns']['width'];
$this->ez['leftMargin'] = $this->ez['columns']['margins'][0] + ($this->ez['columns']['colNum'] - 1) * ($this->ez['columns']['options']['gap'] + $width);
$this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
}
if ($pageRequired) {
// make a new page, setting the writing point back to the top
$this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
// make the new page with a call to the basic class.
++$this->ezPageCount;
if (isset($this->ez['insertMode']) && $this->ez['insertMode'] == 1) {
$id = $this->ezPages[$this->ezPageCount] = $this->newPage(1, $this->ez['insertOptions']['id'], $this->ez['insertOptions']['pos']);
// then manipulate the insert options so that inserted pages follow each other
$this->ez['insertOptions']['id'] = $id;
$this->ez['insertOptions']['pos'] = 'after';
} else {
$this->ezPages[$this->ezPageCount] = $this->newPage();
}
$this->setBackground();
} else {
$this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
}
}
/**
* starts to flow text into columns.
*
* @param $options array with option for gaps and number of columns - default: ['gap'=>10, 'num'=>2]
*/
public function ezColumnsStart($options = [])
{
// start from the current y-position, make the set number of columne
if (isset($this->ez['columns']) && $this->ez['columns'] == 1) {
// if we are already in a column mode then just return.
return;
}
$def = ['gap' => 10, 'num' => 2];
foreach ($def as $k => $v) {
if (!isset($options[$k])) {
$options[$k] = $v;
}
}
// setup the columns
$this->ez['columns'] = ['on' => 1, 'colNum' => 1];
// store the current margins
$this->ez['columns']['margins'] = array(
$this->ez['leftMargin'],
$this->ez['rightMargin'],
$this->ez['topMargin'],
$this->ez['bottomMargin'],
);
// and store the settings for the columns
$this->ez['columns']['options'] = $options;
// then reset the margins to suit the new columns
// safe enough to assume the first column here, but start from the current y-position
$this->ez['topMargin'] = $this->ez['pageHeight'] - $this->y;
$width = ($this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin'] - ($options['num'] - 1) * $options['gap']) / $options['num'];
$this->ez['columns']['width'] = $width;
$this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
}
/**
* stops the multi column mode.
*/
public function ezColumnsStop()
{
if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1) {
$this->ez['columns']['on'] = 0;
$this->ez['leftMargin'] = $this->ez['columns']['margins'][0];
$this->ez['rightMargin'] = $this->ez['columns']['margins'][1];
$this->ez['topMargin'] = $this->ez['columns']['margins'][2];
$this->ez['bottomMargin'] = $this->ez['columns']['margins'][3];
}
}
/**
* puts the document into insert mode. new pages are inserted until this is re-called with status=0
* by default pages will be inserted at the start of the document.
*
* @param $status
* @param $pageNum
* @param $pos
*/
public function ezInsertMode($status = 1, $pageNum = 1, $pos = 'before')
{
switch ($status) {
case '1':
if (isset($this->ezPages[$pageNum])) {
$this->ez['insertMode'] = 1;
$this->ez['insertOptions'] = ['id' => $this->ezPages[$pageNum], 'pos' => $pos];
}
break;
case '0':
$this->ez['insertMode'] = 0;
break;
}
}
/**
* sets the Y position of the document.
* If Y reaches the bottom margin a new page is generated.
*
* @param float $y Y position
*/
public function ezSetY($y)
{
// used to change the vertical position of the writing point.
$this->y = $y;
if ($this->y < $this->ez['bottomMargin']) {
// then make a new page
$this->ezNewPage();
}
}
/**
* changes the Y position of the document by writing positive or negative numbers.
* If Y reaches the bottom margin a new page is generated.
*
* @param $dy
* @param $mod
*/
public function ezSetDy($dy, $mod = '')
{
// used to change the vertical position of the writing point.
// changes up by a positive increment, so enter a negative number to go
// down the page
// if $mod is set to 'makeSpace' and a new page is forced, then the pointed will be moved
// down on the new page, this will allow space to be reserved for graphics etc.
$this->y += $dy;
if ($this->y < $this->ez['bottomMargin']) {
// then make a new page
$this->ezNewPage();
if ($mod == 'makeSpace') {
$this->y += $dy;
}
}
}
/**
* put page numbers on the pages from here.
* place then on the 'pos' side of the coordinates (x,y).
* use the given 'pattern' for display, where (PAGENUM} and {TOTALPAGENUM} are replaced
* as required.
* Adjust this function so that each time you 'start' page numbers then you effectively start a different batch
* return the number of the batch, so that they can be stopped in a different order if required.
*
* @param float $x X-coordinate
* @param float $y Y-coordinate
* @param $size
* @param string $pos use either right or left
* @param string $pattern pattern where {PAGENUM} is the current page number and {TOTALPAGENUM} is the page count in total
* @param int $num optional. make the first page this number, the number of total pages will be adjusted to account for this
*
* @return int count of ez['pageNumbering']
*/
public function ezStartPageNumbers($x, $y, $size, $pos = 'left', $pattern = '{PAGENUM} of {TOTALPAGENUM}', $num = 1)
{
if (!$pos || !strlen($pos)) {
$pos = 'left';
}
if (!$pattern || !strlen($pattern)) {
$pattern = '{PAGENUM} of {TOTALPAGENUM}';
}
if (!isset($this->ez['pageNumbering'])) {
$this->ez['pageNumbering'] = [];
}
$i = count($this->ez['pageNumbering']);
$this->ez['pageNumbering'][$i][$this->ezPageCount] = ['x' => $x, 'y' => $y, 'pos' => $pos, 'pattern' => $pattern, 'num' => $num, 'size' => $size];
return $i;
}
/**
* returns the number of a page within the specified page numbering system.
*
* @param $pageNum
* @param $i
*
* @return int page number
*/
public function ezWhatPageNumber($pageNum, $i = 0)
{
// given a particular generic page number (ie, document numbered sequentially from beginning),
// return the page number under a particular page numbering scheme ($i)
$num = 0;
$start = 1;
$startNum = 1;
if (!isset($this->ez['pageNumbering'])) {
$this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
return 0;
}
foreach ($this->ez['pageNumbering'][$i] as $k => $v) {
if ($k <= $pageNum) {
if (is_array($v)) {
// start block
if (strlen($v['num'])) {
// a start was specified
$start = $v['num'];
$startNum = $k;
$num = $pageNum - $startNum + $start;
}
} else {
// stop block
$num = 0;
}
}
}
return $num;
}
/**
* receive the current page number.
*
* @return int page number
*/
public function ezGetCurrentPageNumber()
{
// return the strict numbering (1,2,3,4..) number of the current page
return $this->ezPageCount;
}
/**
* stops the custom page numbering.
*
* @param $stopTotal
* @param $next
* @param $i
*/
public function ezStopPageNumbers($stopTotal = 0, $next = 0, $i = 0)
{
// if stopTotal=1 then the totalling of pages for this number will stop too
// if $next=1, then do this page, but not the next, else do not do this page either
// if $i is set, then stop that particular pagenumbering sequence.
if (!isset($this->ez['pageNumbering'])) {
$this->ez['pageNumbering'] = [];
}
if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array($this->ez['pageNumbering'][$i][$this->ezPageCount])) {
// then this has only just been started, this will over-write the start, and nothing will appear
// add a special command to the start block, telling it to stop as well
if ($stopTotal) {
$this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn'] = 1;
} else {
$this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn'] = 1;
}
} else {
if ($stopTotal) {
$this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stopt';
} else {
$this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stop';
}
if ($next) {
$this->ez['pageNumbering'][$i][$this->ezPageCount] .= 'n';
}
}
}
/**
* internal function to search the page number.
*
* @see Cezpdf::ezStartPageNumbers()
*
* @param $lbl
* @param $tmp
*
* @return int page number
*/
private function ezPageNumberSearch($lbl, &$tmp)
{
foreach ($tmp as $i => $v) {
if (is_array($v)) {
if (isset($v[$lbl])) {
return $i;
}
} else {
if ($v == $lbl) {
return $i;
}
}
}
return 0;
}
/**
* save page numbers for paging.
*
* @see Cezpdf::ezStartPageNumbers()
*/
private function addPageNumbers()
{
// this will go through the pageNumbering array and add the page numbers are required
if (isset($this->ez['pageNumbering'])) {
$totalPages1 = $this->ezPageCount;
$tmp1 = $this->ez['pageNumbering'];
$status = 0;
foreach ($tmp1 as $i => $tmp) {
// do each of the page numbering systems
// firstly, find the total pages for this one
$k = $this->ezPageNumberSearch('stopt', $tmp);
if ($k && $k > 0) {
$totalPages = $k - 1;
} else {
$l = $this->ezPageNumberSearch('stoptn', $tmp);
if ($l && $l > 0) {
$totalPages = $l;
} else {
$totalPages = $totalPages1;
}
}
foreach ($this->ezPages as $pageNum => $id) {
if (isset($tmp[$pageNum])) {
if (is_array($tmp[$pageNum])) {
// then this must be starting page numbers
$status = 1;
$info = $tmp[$pageNum];
$info['dnum'] = $info['num'] - $pageNum;
// also check for the special case of the numbering stopping and starting on the same page
if (isset($info['stopn']) || isset($info['stoptn'])) {
$status = 2;
}
} elseif ($tmp[$pageNum] == 'stop' || $tmp[$pageNum] == 'stopt') {
// then we are stopping page numbers
$status = 0;
} elseif ($status == 1 && ($tmp[$pageNum] == 'stoptn' || $tmp[$pageNum] == 'stopn')) {
// then we are stopping page numbers
$status = 2;
}
}
if ($status) {
// then add the page numbering to this page
if (strlen($info['num'])) {
$num = $pageNum + $info['dnum'];
} else {
$num = $pageNum;
}
$total = $totalPages + $num - $pageNum;
$pat = str_replace('{PAGENUM}', $num, $info['pattern']);
$pat = str_replace('{TOTALPAGENUM}', $total, $pat);
$this->reopenObject($id);
switch ($info['pos']) {
case 'left':
$this->addText($info['x'], $info['y'], $info['size'], $pat);
break;
case 'center':
$w = $this->getTextWidth($info['size'], $pat);
$this->addText($info['x'] - ($w / 2), $info['y'], $info['size'], $pat);
break;
default:
$w = $this->getTextWidth($info['size'], $pat);
$this->addText($info['x'] - $w, $info['y'], $info['size'], $pat);
break;
}
$this->closeObject();
}
if ($status == 2) {
$status = 0;
}
}
}
}
}
/**
* some clean up function (especially used after paging).
*/
private function cleanUp()
{
$this->addPageNumbers();
}
/**
* internal method to draw different table lines
* called by ezTable() method.
*
* @param array $pos start position of each column
* @param float $gap column gap defined in ezTable()
* @param float $rowGap row gap defined in ezTable()
* @param float $x0 some coordinates
* @param $x1 some X coordinates
* @param $y0 some Y coordinates
* @param $y1 some Y coordinates
* @param $y2 some Y coordinates
* @param array $col line color as array
* @param float $inner inner line thickness
* @param float $outer outer line thickness
* @param int $gridlines - what gridlines to display
*/
protected function ezTableDrawLines($pos, $gap, $rowGap, $x0, $x1, $y0, $y1, $y2, $col, $inner, $outer, $gridlines)
{
$x0 = 1000;
$x1 = 0;
$this->setStrokeColor($col[0], $col[1], $col[2]);
// Vertical gridlines (including outline)
$cnt = 0;
$n = count($pos);
foreach ($pos as $x) {
if ($x > $x1) {
$x1 = $x;
}
if ($x < $x0) {
$x0 = $x;
}
++$cnt;
if ($cnt == 1 || $cnt == $n) {
if (!($gridlines & EZ_GRIDLINE_TABLE_V)) {
continue;
}
$this->setLineStyle($outer);
} else {
if (!($gridlines & EZ_GRIDLINE_COLUMNS)) {
continue;
}
$this->setLineStyle($inner);
}
$this->line($x - $gap / 2, $y0, $x - $gap / 2, $y2);
}
// Top and bottom outline
$this->setLineStyle($outer);
if ($gridlines & EZ_GRIDLINE_TABLE_H) {
$this->line($x0 - $gap / 2 - $outer / 2, $y0, $x1 - $gap / 2 + $outer / 2, $y0);
$this->line($x0 - $gap / 2 - $outer / 2, $y2, $x1 - $gap / 2 + $outer / 2, $y2);
}
// Header / data separator
if ($y0 != $y1 && ($gridlines & EZ_GRIDLINE_HEADERONLY)) {
$this->line($x0 - $gap / 2, $y1 + $rowGap * 2, $x1 - $gap / 2, $y1 + $rowGap * 2);
}
}
/**
* used to display the headline of a table
* called by ezTable() method.
*
* @param array $cols column array from ezTable option parameter
* @param $pos
* @param float $maxWidth maximum width
* @param float $height height of the heading
* @param $descender
* @param float $gap
* @param float $size font size
* @param float $y actual Y position
* @param $optionsAll
*/
protected function ezTableColumnHeadings($cols, $pos, $maxWidth, $height, $descender, $gap, $size, &$y, $optionsAll = [])
{
// uses ezText to add the text, and returns the height taken by the largest heading
// this page will move the headings to a new page if they will not fit completely on this one
// transaction support will be used to implement this
if (isset($optionsAll['cols'])) {
$options = $optionsAll['cols'];
} else {
$options = [];
}
$mx = 0;
$startPage = $this->ezPageCount;
$secondGo = 0;
// $y is the position at which the top of the table should start, so the base
// of the first text, is $y-$height-$gap-$descender, but ezText starts by dropping $height
// the return from this function is the total cell height, including gaps, and $y is adjusted
// to be the postion of the bottom line
// begin the transaction
$this->transaction('start');
$ok = 0;
//$y-=$gap+$descender;
$y -= $gap;
while ($ok == 0) {
$col = $optionsAll['textCol'];
$this->setColor($col[0], $col[1], $col[2], true);
foreach ($cols as $colName => $colHeading) {
$this->ezSetY($y);
if (!empty($optionsAll['alignHeadings'])) {
$justification = $optionsAll['alignHeadings'];
} elseif (isset($options[$colName]) && isset($options[$colName]['justification'])) {
$justification = $options[$colName]['justification'];
} else {