Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezpdf.php
Go to the documentation of this file.
1 <?php
21 class eZPDF
22 {
28 public function __construct( $name = "pdf" )
29 {
30 $this->Operators = array( $name );
31 $this->Config = eZINI::instance( 'pdf.ini' );
32 }
33
37 function operatorList()
38 {
39 return $this->Operators;
40 }
41
45 function namedParameterList()
46 {
47 return array( 'operation' => array( 'type' => 'string',
48 'required' => true,
49 'default' => '' ) );
50 }
51
55 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement )
56 {
57 $config = eZINI::instance( 'pdf.ini' );
58
59 switch ( $namedParameters['operation'] )
60 {
61 case 'toc':
62 {
63 $operatorValue = '<C:callTOC';
64
65 if ( count( $operatorParameters ) > 1 )
66 {
67 $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
68
69 $operatorValue .= isset( $params['size'] ) ? ':size:'. implode(',', $params['size'] ) : '';
70 $operatorValue .= isset( $params['dots'] ) ? ':dots:'. $params['dots'] : '';
71 $operatorValue .= isset( $params['contentText'] ) ? ':contentText:'. $params['contentText'] : '';
72 $operatorValue .= isset( $params['indent'] ) ? ':indent:'. implode(',', $params['indent'] ) : '';
73
74 }
75
76 $operatorValue .= '>';
77 eZDebug::writeNotice( 'PDF: Generating TOC', __METHOD__ );
78 } break;
79
80 case 'set_font':
81 {
82 $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
83
84 $operatorValue = '<ezCall:callFont';
85
86 foreach ( $params as $key => $value )
87 {
88 if ( $key == 'colorCMYK' )
89 {
90 $operatorValue .= ':cmyk:' . implode( ',', $value );
91 }
92 else if ( $key == 'colorRGB' )
93 {
94 $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $value[0]/255,
95 $value[1]/255,
96 $value[2]/255 ) );
97 }
98 else
99 {
100 $operatorValue .= ':' . $key . ':' . $value;
101 }
102 }
103 $operatorValue .= '>';
104
105 eZDebug::writeNotice( 'PDF: Changed font.' );
106 } break;
107
108 case 'table':
109 {
110 $operatorValue = '<ezGroup:callTable';
111
112 if ( count( $operatorParameters > 2 ) )
113 {
114 $tableSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
115
116 if ( is_array( $tableSettings ) )
117 {
118 foreach( array_keys( $tableSettings ) as $key )
119 {
120 switch( $key )
121 {
122 case 'headerCMYK':
123 case 'cellCMYK':
124 case 'textCMYK':
125 case 'titleCellCMYK':
126 case 'titleTextCMYK':
127 {
128 $operatorValue .= ':' . $key . ':' . implode( ',', $tableSettings[$key] );
129 } break;
130
131 default:
132 {
133 $operatorValue .= ':' . $key . ':' . $tableSettings[$key];
134 } break;
135 }
136 }
137 }
138 }
139
140 $operatorValue .= '>';
141
142 $rows = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
143
144 $rows = str_replace( array( ' ', "\t", "\r\n", "\n" ),
145 '',
146 $rows );
147 $httpCharset = eZTextCodec::internalCharset();
148 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
149 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
150 : 'iso-8859-1';
151 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
152 // Convert current text to $outputCharset (by default iso-8859-1)
153 $rows = $codec->convertString( $rows );
154
155 $operatorValue .= urlencode( $rows );
156
157 $operatorValue .= '</ezGroup:callTable><C:callNewLine>';
158
159 eZDebug::writeNotice( 'PDF: Added table to PDF', __METHOD__ );
160 } break;
161
162 case 'header':
163 {
164 $header = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
165
166 $header['text'] = str_replace( array( ' ', "\t", "\r\n", "\n" ),
167 '',
168 $header['text'] );
169
170 $operatorValue = '<ezCall:callHeader:level:'. $header['level'] .':size:'. $header['size'];
171
172 if ( isset( $header['align'] ) )
173 {
174 $operatorValue .= ':justification:'. $header['align'];
175 }
176
177 if ( isset( $header['font'] ) )
178 {
179 $operatorValue .= ':fontName:'. $header['font'];
180 }
181
182 $operatorValue .= ':label:'. rawurlencode( $header['text'] );
183
184 $operatorValue .= '><C:callNewLine>'. $header['text'] .'</ezCall:callHeader><C:callNewLine>';
185
186 eZDebug::writeNotice( 'PDF: Added header: '. $header['text'] .', size: '. $header['size'] .
187 ', align: '. $header['align'] .', level: '. $header['level'],
188 __METHOD__ );
189 } break;
190
191 case 'create':
192 {
193 $this->createPDF();
194 } break;
195
196 case 'new_line':
197 case 'newline': // Deprecated
198 {
199 $operatorValue = '<C:callNewLine>';
200 } break;
201
202 case 'new_page':
203 case 'newpage': // Deprecated
204 {
205 $operatorValue = '<C:callNewPage><C:callNewLine>';
206
207 eZDebug::writeNotice( 'PDF: New page', __METHOD__ );
208 } break;
209
210 case 'image':
211 {
212 $image = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
213
214 $width = isset( $image['width'] ) ? $image['width']: 100;
215 $height = isset( $image['height'] ) ? $image['height']: 100;
216
217 $operatorValue = '<C:callImage:src:'. rawurlencode( $image['src'] ) .':width:'. $width .':height:'. $height;
218
219 if ( isset( $image['static'] ) )
220 {
221 $operatorValue .= ':static:' . $image['static'];
222 }
223
224 if ( isset ( $image['x'] ) )
225 {
226 $operatorValue .= ':x:' . $image['x'];
227 }
228
229 if ( isset( $image['y'] ) )
230 {
231 $operatorValue .= ':y:' . $image['y'];
232 }
233
234 if ( isset( $image['dpi'] ) )
235 {
236 $operatorValue .= ':dpi:' . $image['dpi'];
237 }
238
239 if ( isset( $image['align'] ) ) // left, right, center, full
240 {
241 $operatorValue .= ':align:' . $image['align'];
242 }
243
244 $operatorValue .= '>';
245
246 eZDebug::writeNotice( 'PDF: Added Image '.$image['src'].' to PDF file', __METHOD__ );
247 } break;
248
249 case 'anchor':
250 {
251 $name = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
252
253 $operatorValue = '<C:callAnchor:'. $name['name'] .':FitH:>';
254 eZDebug::writeNotice( 'PDF: Added anchor: '.$name['name'], __METHOD__ );
255 } break;
256
257 case 'link': // external link
258 {
259 $link = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
260
261 $link['text'] = str_replace( '&quot;',
262 '"',
263 $link['text'] );
264
265 $operatorValue = '<c:alink:'. rawurlencode( $link['url'] ) .'>'. $link['text'] .'</c:alink>';
266 eZDebug::writeNotice( 'PDF: Added link: '. $link['text'] .', url: '.$link['url'], __METHOD__ );
267 } break;
268
269 case 'stream':
270 {
271 $this->PDF->ezStream();
272 }
273
274 case 'close':
275 {
276 $filename = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
277
278 eZDir::mkdir( eZDir::dirpath( $filename ), false, true );
279
280 $file = eZClusterFileHandler::instance( $filename );
281 $file->storeContents( $this->PDF->ezOutput(), 'viewcache', 'pdf' );
282
283 eZDebug::writeNotice( 'PDF file closed and saved to '. $filename, __METHOD__ );
284 } break;
285
286 case 'strike':
287 {
288 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
289 $operatorValue = '<c:strike>'. $text .'</c:strike>';
290 eZDebug::writeNotice( 'Striked text added to PDF: "'. $text .'"', __METHOD__ );
291 } break;
292
293 /* usage : execute/add text to pdf file, pdf(execute,<text>) */
294 case 'execute':
295 {
296 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
297
298 if ( count ( $operatorParameters ) > 2 )
299 {
300 $options = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
301
302 $size = isset( $options['size'] ) ? $options['size'] : $config->variable( 'PDFGeneral', 'Format' );
303 $orientation = isset( $options['orientation'] ) ? $options['orientation'] : $config->variable( 'PDFGeneral', 'Orientation' );
304
305 $this->createPDF( $size, $orientation );
306 }
307 else
308 {
309 $this->createPDF( $config->variable( 'PDFGeneral', 'Format' ), $config->variable( 'PDFGeneral', 'Orientation' ) );
310 }
311
312 $text = str_replace( array( ' ', "\n", "\t" ), '', $text );
313 $httpCharset = eZTextCodec::internalCharset();
314 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
315 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
316 : 'iso-8859-1';
317 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
318 // Convert current text to $outputCharset (by default iso-8859-1)
319 $text = $codec->convertString( $text );
320
321 $this->PDF->ezText( $text );
322 eZDebug::writeNotice( 'Execute text in PDF, length: "'. strlen( $text ) .'"', __METHOD__ );
323 } break;
324
325 case 'page_number':
326 case 'pageNumber':
327 {
328 $numberDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
329
330 if ( isset( $numberDesc['identifier'] ) )
331 {
332 $identifier = $numberDesc['identifier'];
333 }
334 else
335 {
336 $identifier = 'main';
337 }
338
339 if ( isset( $numberDesc['start'] ) )
340 {
341 $operatorValue = '<C:callStartPageCounter:start:'. $numberDesc['start'] .':identifier:'. $identifier .'>';
342 }
343 else if ( isset( $numberDesc['stop'] ) )
344 {
345 $operatorValue = '<C:callStartPageCounter:stop:1:identifier:'. $identifier .'>';
346 }
347 } break;
348
349 /* usage {pdf( line, hash( x1, <x>, y1, <y>, x2, <x2>, y2, <y2>, pages, <all|current>, thickness, <1..100>, ) )} */
350 case 'line':
351 {
352 $lineDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
353
354 if ( isset( $lineDesc['pages']) and
355 $lineDesc['pages'] == 'all' )
356 {
357 $operatorValue = '<ezGroup:callLine';
358 }
359 else
360 {
361 $operatorValue = '<C:callDrawLine';
362 }
363
364 $operatorValue .= ':x1:' . $lineDesc['x1'];
365 $operatorValue .= ':x2:' . $lineDesc['x2'];
366 $operatorValue .= ':y1:' . $lineDesc['y1'];
367 $operatorValue .= ':y2:' . $lineDesc['y2'];
368
369 $operatorValue .= ':thickness:' . ( isset( $lineDesc['thickness'] ) ? $lineDesc['thickness'] : '1' );
370
371 $operatorValue .= '>';
372
373 if ( $lineDesc['pages'] == 'all' )
374 {
375 $operatorValue .= '___</ezGroup:callLine>';
376 }
377
378 return $operatorValue;
379 } break;
380
381 case 'footer_block':
382 case 'header_block':
383 {
384 $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
385
386 $operatorValue = '<ezGroup:callBlockFrame';
387 $operatorValue .= ':location:'. $namedParameters['operation'];
388 $operatorValue .= '>';
389
390 if ( isset( $frameDesc['block_code'] ) )
391 {
392 $httpCharset = eZTextCodec::internalCharset();
393 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
394 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
395 : 'iso-8859-1';
396 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
397 // Convert current text to $outputCharset (by default iso-8859-1)
398 $frameDesc['block_code'] = $codec->convertString( $frameDesc['block_code'] );
399 $operatorValue .= urlencode( $frameDesc['block_code'] );
400 }
401
402 $operatorValue .= '</ezGroup:callBlockFrame>';
403
404 eZDebug::writeNotice( 'PDF: Added Block '.$namedParameters['operation'] .': '.$operatorValue, __METHOD__ );
405 return $operatorValue;
406
407 } break;
408
409 /* deprecated */
410 case 'footer':
411 case 'frame_header':
412 {
413 $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
414
415 $operatorValue = '<ezGroup:callFrame';
416 $operatorValue .= ':location:'. $namedParameters['operation'];
417
418 if ( $namedParameters['operation'] == 'footer' )
419 {
420 $frameType = 'Footer';
421 }
422 else if( $namedParameters['operation'] == 'frame_header' )
423 {
424 $frameType = 'Header';
425 }
426
427 if ( isset( $frameDesc['align'] ) )
428 {
429 $operatorValue .= ':justification:'. $frameDesc['align'];
430 }
431
432 if ( isset( $frameDesc['page'] ) )
433 {
434 $operatorValue .= ':page:'. $frameDesc['page'];
435 }
436 else
437 {
438 $operatorValue .= ':page:all';
439 }
440
441 $operatorValue .= ':newline:' . ( isset( $frameDesc['newline'] ) ? $frameDesc['newline'] : 0 );
442
443 $operatorValue .= ':pageOffset:';
444 if ( isset( $frameDesc['pageOffset'] ) )
445 {
446 $operatorValue .= $frameDesc['pageOffset'];
447 }
448 else
449 {
450 $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' );
451 }
452
453 if ( isset( $frameDesc['size'] ) )
454 {
455 $operatorValue .= ':size:'. $frameDesc['size'];
456 }
457
458 if ( isset( $frameDesc['font'] ) )
459 {
460 $operatorValue .= ':font:'. $frameDesc['font'];
461 }
462
463 $operatorValue .= '>';
464
465 if ( isset( $frameDesc['text'] ) )
466 {
467 $httpCharset = eZTextCodec::internalCharset();
468 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
469 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
470 : 'iso-8859-1';
471 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
472 // Convert current text to $outputCharset (by default iso-8859-1)
473 $frameDesc['text'] = $codec->convertString( $frameDesc['text'] );
474 $operatorValue .= urlencode( $frameDesc['text'] );
475 }
476
477 $operatorValue .= '</ezGroup:callFrame>';
478
479 if ( isset( $frameDesc['margin'] ) )
480 {
481 $operatorValue .= '<C:callFrameMargins';
482
483 $operatorValue .= ':identifier:'. $namedParameters['operation'];
484
485 $operatorValue .= ':topMargin:';
486 if ( isset( $frameDesc['margin']['top'] ) )
487 {
488 $operatorValue .= $frameDesc['margin']['top'];
489 }
490 else
491 {
492 $operatorValue .= $this->Config->variable( $frameType, 'TopMargin' );
493 }
494
495 $operatorValue .= ':bottomMargin:';
496 if ( isset( $frameDesc['margin']['bottom'] ) )
497 {
498 $operatorValue .= $frameDesc['margin']['bottom'];
499 }
500 else
501 {
502 $operatorValue .= $this->Config->variable( $frameType, 'BottomMargin' );
503 }
504
505 $operatorValue .= ':leftMargin:';
506 if ( isset( $frameDesc['margin']['left'] ) )
507 {
508 $operatorValue .= $frameDesc['margin']['left'];
509 }
510 else
511 {
512 $operatorValue .= $this->Config->variable( $frameType, 'LeftMargin' );
513 }
514
515 $operatorValue .= ':rightMargin:';
516 if ( isset( $frameDesc['margin']['right'] ) )
517 {
518 $operatorValue .= $frameDesc['margin']['right'];
519 }
520 else
521 {
522 $operatorValue .= $this->Config->variable( $frameType, 'RightMargin' );
523 }
524
525 $operatorValue .= ':height:';
526 if ( isset( $frameDesc['margin']['height'] ) )
527 {
528 $operatorValue .= $frameDesc['margin']['height'];
529 }
530 else
531 {
532 $operatorValue .= $this->Config->variable( $frameType, 'Height' );
533 }
534
535 $operatorValue .= '>';
536 }
537
538 if ( isset( $frameDesc['line'] ) )
539 {
540 $operatorValue .= '<C:callFrameLine';
541 $operatorValue .= ':location:'. $namedParameters['operation'];
542
543 $operatorValue .= ':margin:';
544 if( isset( $frameDesc['line']['margin'] ) )
545 {
546 $operatorValue .= $frameDesc['line']['margin'];
547 }
548 else
549 {
550 $operatorValue .= $this->Config->variable( $frameType, 'LineMargin' );
551 }
552
553 if ( isset( $frameDesc['line']['leftMargin'] ) )
554 {
555 $operatorValue .= ':leftMargin:'. $frameDesc['line']['leftMargin'];
556 }
557 if ( isset( $frameDesc['line']['rightMargin'] ) )
558 {
559 $operatorValue .= ':rightMargin:'. $frameDesc['line']['rightMargin'];
560 }
561
562 $operatorValue .= ':pageOffset:';
563 if ( isset( $frameDesc['line']['pageOffset'] ) )
564 {
565 $operatorValue .= $frameDesc['line']['pageOffset'];
566 }
567 else
568 {
569 $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' );
570 }
571
572 $operatorValue .= ':page:';
573 if ( isset( $frameDesc['line']['page'] ) )
574 {
575 $operatorValue .= $frameDesc['line']['page'];
576 }
577 else
578 {
579 $operatorValue .= $this->Config->variable( $frameType, 'Page' );
580 }
581
582 $operatorValue .= ':thickness:';
583 if ( isset( $frameDesc['line']['thickness'] ) )
584 {
585 $operatorValue .= $frameDesc['line']['thickness'];
586 }
587 else
588 {
589 $operatorValue .= $this->Config->variable( $frameType, 'LineThickness' );
590 }
591 $operatorValue .= '>';
592 }
593
594 eZDebug::writeNotice( 'PDF: Added frame '.$frameType .': '.$operatorValue, __METHOD__ );
595 } break;
596
597 case 'frontpage':
598 {
599 $pageDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
600
601 $align = isset( $pageDesc['align'] ) ? $pageDesc['align'] : 'center';
602 $text = isset( $pageDesc['text'] ) ? $pageDesc['text'] : '';
603 $top_margin = isset( $pageDesc['top_margin'] ) ? $pageDesc['top_margin'] : 100;
604
605 $operatorValue = '<ezGroup:callFrontpage:justification:'. $align .':top_margin:'. $top_margin;
606
607 if ( isset( $pageDesc['size'] ) )
608 {
609 $operatorValue .= ':size:'. $pageDesc['size'];
610 }
611
612 $text = str_replace( array( ' ', "\t", "\r\n", "\n" ),
613 '',
614 $text );
615 $httpCharset = eZTextCodec::internalCharset();
616 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
617 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
618 : 'iso-8859-1';
619 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
620 // Convert current text to $outputCharset (by default iso-8859-1)
621 $text = $codec->convertString( $text );
622
623 $operatorValue .= '>'. urlencode( $text ) .'</ezGroup:callFrontpage>';
624
625 eZDebug::writeNotice( 'Added content to frontpage: '. $operatorValue, __METHOD__ );
626 } break;
627
628 /* usage: pdf(set_margin( hash( left, <left_margin>,
629 right, <right_margin>,
630 x, <x offset>,
631 y, <y offset> )))
632 */
633 case 'set_margin':
634 {
635 $operatorValue = '<C:callSetMargin';
636 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
637
638 foreach( array_keys( $options ) as $key )
639 {
640 $operatorValue .= ':' . $key . ':' . $options[$key];
641 }
642
643 $operatorValue .= '>';
644
645 eZDebug::writeNotice( 'Added new margin/offset setup: ' . $operatorValue );
646
647 return $operatorValue;
648 } break;
649
650 /* add keyword to pdf document */
651 case 'keyword':
652 {
653 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
654
655 $text = str_replace( array( ' ', "\n", "\t" ), '', $text );
656 $httpCharset = eZTextCodec::internalCharset();
657 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
658 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
659 : 'iso-8859-1';
660 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
661 // Convert current text to $outputCharset (by default iso-8859-1)
662 $text = $codec->convertString( $text );
663
664 $operatorValue = '<C:callKeyword:'. rawurlencode( $text ) .'>';
665 } break;
666
667 /* add Keyword index to pdf document */
668 case 'createIndex':
669 case 'create_index':
670 {
671 $operatorValue = '<C:callIndex>';
672
673 eZDebug::writeNotice( 'Adding Keyword index to PDF', __METHOD__ );
674 } break;
675
676 case 'ul':
677 {
678 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
679 if ( count( $operatorParameters ) > 2 )
680 {
681 $params = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
682 }
683 else
684 {
685 $params = array();
686 }
687
688 if ( isset( $params['rgb'] ) )
689 {
690 $params['rgb'] = eZMath::normalizeColorArray( $params['rgb'] );
691 $params['cmyk'] = eZMath::rgbToCMYK2( $params['rgb'][0]/255,
692 $params['rgb'][1]/255,
693 $params['rgb'][2]/255 );
694 }
695
696 if ( !isset( $params['cmyk'] ) )
697 {
698 $params['cmyk'] = eZMath::rgbToCMYK2( 0, 0, 0 );
699 }
700 if ( !isset( $params['radius'] ) )
701 {
702 $params['radius'] = 2;
703 }
704 if ( !isset ( $params['pre_indent'] ) )
705 {
706 $params['pre_indent'] = 0;
707 }
708 if ( !isset ( $params['indent'] ) )
709 {
710 $params['indent'] = 2;
711 }
712 if ( !isset ( $params['yOffset'] ) )
713 {
714 $params['yOffset'] = -1;
715 }
716
717 $operatorValue = '<C:callCircle' .
718 ':pages:current' .
719 ':x:-1' .
720 ':yOffset:' . $params['yOffset'] .
721 ':y:-1' .
722 ':indent:' . $params['indent'] .
723 ':pre_indent:' . $params['pre_indent'] .
724 ':radius:' . $params['radius'] .
725 ':cmyk:' . implode( ',', $params['cmyk'] ) .
726 '>';
727
728 $operatorValue .= '<C:callSetMargin' .
729 ':delta_left:' . ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) .
730 '>';
731
732 $operatorValue .= $text;
733
734 $operatorValue .= '<C:callSetMargin' .
735 ':delta_left:' . -1 * ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) .
736 '>';
737 } break;
738
739 case 'filled_circle':
740 {
741 $operatorValue = '';
742 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
743
744 if ( !isset( $options['pages'] ) )
745 {
746 $options['pages'] = 'current';
747 }
748
749 if ( !isset( $options['x'] ) )
750 {
751 $options['x'] = -1;
752 }
753
754 if ( !isset( $options['y'] ) )
755 {
756 $options['y'] = -1;
757 }
758
759 if ( isset( $options['rgb'] ) )
760 {
761 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] );
762 $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255,
763 $options['rgb'][1]/255,
764 $options['rgb'][2]/255 );
765 }
766
767 $operatorValue = '<C:callCircle' .
768 ':pages:' . $options['pages'] .
769 ':x:' . $options['x'] .
770 ':y:' . $options['y'] .
771 ':radius:' . $options['radius'];
772
773 if ( isset( $options['cmyk'] ) )
774 {
775 $operatorValue .= ':cmyk:' . implode( ',', $options['cmyk'] );
776 }
777
778 $operatorValue .= '>';
779
780 eZDebug::writeNotice( 'PDF Added circle: ' . $operatorValue );
781
782 return $operatorValue;
783 } break;
784
785 case 'rectangle':
786 {
787 $operatorValue = '';
788 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
789
790 if ( !isset( $options['pages'] ) )
791 {
792 $options['pages'] = 'current';
793 }
794 if ( !isset( $options['line_width'] ) )
795 {
796 $options['line_width'] = 1;
797 }
798 if ( !isset( $options['round_corner'] ) )
799 {
800 $options['round_corner'] = false;
801 }
802
803 $operatorValue = '<C:callRectangle';
804 foreach ( $options as $key => $value )
805 {
806 if ( $key == 'rgb' )
807 {
808 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] );
809 $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $options['rgb'][0]/255,
810 $options['rgb'][1]/255,
811 $options['rgb'][2]/255 ) );
812 }
813 else if ( $key == 'cmyk' )
814 {
815 $operatorValue .= ':cmyk:' . implode( ',', $value );
816 }
817 else
818 {
819 $operatorValue .= ':' . $key . ':' . $value;
820 }
821 }
822 $operatorValue .= '>';
823
824 eZDebug::writeNotice( 'PDF Added rectangle: ' . $operatorValue );
825
826 return $operatorValue;
827 } break;
828
829 /* usage: pdf( filled_rectangle, hash( 'x', <x offset>, 'y' => <y offset>, 'width' => <width>, 'height' => <height>,
830 'pages', <'all'|'current'|odd|even>, (supported, current)
831 'rgb', array( <r>, <g>, <b> ),
832 'cmyk', array( <c>, <m>, <y>, <k> ),
833 'rgbTop', array( <r>, <b>, <g> ),
834 'rgbBottom', array( <r>, <b>, <g> ),
835 'cmykTop', array( <c>, <m>, <y>, <k> ),
836 'cmykBottom', array( <c>, <m>, <y>, <k> ) ) ) */
837 case 'filled_rectangle':
838 {
839 $operatorValue = '';
840 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
841
842 if ( !isset( $options['pages'] ) )
843 {
844 $options['pages'] = 'current';
845 }
846
847 if ( isset( $options['rgb'] ) )
848 {
849 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] );
850 $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255,
851 $options['rgb'][1]/255,
852 $options['rgb'][2]/255 );
853 }
854
855 if ( isset( $options['cmyk'] ) )
856 {
857 $options['cmykTop'] = $options['cmyk'];
858 $options['cmykBottom'] = $options['cmyk'];
859 }
860
861 if ( !isset( $options['cmykTop'] ) )
862 {
863 if ( isset( $options['rgbTop'] ) )
864 {
865 $options['rgbTop'] = eZMath::normalizeColorArray( $options['rgbTop'] );
866 $options['cmykTop'] = eZMath::rgbToCMYK2( $options['rgbTop'][0]/255,
867 $options['rgbTop'][1]/255,
868 $options['rgbTop'][2]/255 );
869 }
870 else
871 {
872 $options['cmykTop'] = eZMath::rgbToCMYK2( 0, 0, 0 );
873 }
874 }
875
876 if ( !isset( $options['cmykBottom'] ) )
877 {
878 if ( isset( $options['rgbBottom'] ) )
879 {
880 $options['rgbBottom'] = eZMath::normalizeColorArray( $options['rgbBottom'] );
881 $options['cmykBottom'] = eZMath::rgbToCMYK2( $options['rgbBottom'][0]/255,
882 $options['rgbBottom'][1]/255,
883 $options['rgbBottom'][2]/255 );
884 }
885 else
886 {
887 $options['cmykBottom'] = eZMath::rgbToCMYK2( 0, 0, 0 );
888 }
889 }
890
891 if ( !isset( $options['pages'] ) )
892 {
893 $options['pages'] = 'current';
894 }
895
896 $operatorValue = '<C:callFilledRectangle' .
897 ':pages:' . $options['pages'] .
898 ':x:' . $options['x'] .
899 ':y:' . $options['y'] .
900 ':width:' . $options['width'] .
901 ':height:' . $options['height'] .
902 ':cmykTop:' . implode( ',', $options['cmykTop'] ) .
903 ':cmykBottom:' . implode( ',', $options['cmykBottom'] ) .
904 '>';
905
906 eZDebug::writeNotice( 'Added rectangle: ' . $operatorValue );
907 } break;
908
909 /* usage : pdf(text, <text>, array( 'font' => <fontname>, 'size' => <fontsize> )) */
910 case 'text':
911 {
912 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
913
914 $operatorValue = '';
915 $changeFont = false;
916
917 if ( count( $operatorParameters ) >= 3)
918 {
919 $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
920
921 if ( isset( $textSettings ) )
922 {
923 $operatorValue .= '<ezCall:callText';
924 $changeFont = true;
925
926 if ( isset( $textSettings['font'] ) )
927 {
928 $operatorValue .= ':font:'. $textSettings['font'];
929 }
930
931 if ( isset( $textSettings['size'] ) )
932 {
933 $operatorValue .= ':size:'. $textSettings['size'];
934 }
935
936 if ( isset( $textSettings['align'] ) )
937 {
938 $operatorValue .= ':justification:'. $textSettings['align'];
939 }
940
941 if ( isset( $textSettings['rgb'] ) )
942 {
943 $textSettings['cmyk'] = eZMath::rgbToCMYK2( $textSettings['rgb'][0]/255,
944 $textSettings['rgb'][1]/255,
945 $textSettings['rgb'][2]/255 );
946 }
947
948 if ( isset( $textSettings['cmyk'] ) )
949 {
950 $operatorValue .= ':cmyk:' . implode( ',', $textSettings['cmyk'] );
951 }
952
953 $operatorValue .= '>';
954 }
955 }
956
957 $operatorValue .= $text;
958 if ( $changeFont )
959 {
960 $operatorValue .= '</ezCall:callText>';
961 }
962
963 } break;
964
965 case 'text_box':
966 {
967 $parameters = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
968
969 $operatorValue = '<ezGroup:callTextBox';
970
971 foreach( array_keys( $parameters ) as $key )
972 {
973 if ( $key != 'text' )
974 {
975 $operatorValue .= ':' . $key . ':' . urlencode( $parameters[$key] );
976 }
977 }
978
979 $httpCharset = eZTextCodec::internalCharset();
980 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
981 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
982 : 'iso-8859-1';
983 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
984 // Convert current text to $outputCharset (by default iso-8859-1)
985 $parameters['text'] = $codec->convertString( $parameters['text'] );
986
987 $operatorValue .= '>';
988 $operatorValue .= urlencode( $parameters['text'] );
989 $operatorValue .= '</ezGroup:callTextBox>';
990
991 return $operatorValue;
992 } break;
993
994 case 'text_frame':
995 {
996 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace );
997
998 $operatorValue = '';
999 $changeFont = false;
1000
1001 if ( count( $operatorParameters ) >= 3)
1002 {
1003 $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace );
1004
1005 if ( isset( $textSettings ) )
1006 {
1007 $operatorValue .= '<ezGroup:callTextFrame';
1008 $changeFont = true;
1009
1010 foreach ( array_keys( $textSettings ) as $key ) //settings, padding (left, right, top, bottom), textcmyk, framecmyk
1011 {
1012 if ( $key == 'frameCMYK' )
1013 {
1014 $operatorValue .= ':frameCMYK:' . implode( ',', $textSettings['frameCMYK'] );
1015 }
1016 else if ( $key == 'frameRGB' )
1017 {
1018 $operatorValue .= ':frameCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['frameRGB'][0]/255,
1019 $textSettings['frameRGB'][1]/255,
1020 $textSettings['frameRGB'][2]/255 ) );
1021 }
1022 else if ( $key == 'textCMYK' )
1023 {
1024 $operatorValue .= ':textCMYK:' . implode( ',', $textSettings['textCMYK'] );
1025 }
1026 else if ( $key == 'textRGB' )
1027 {
1028 $operatorValue .= ':textCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['textRGB'][0]/255,
1029 $textSettings['textRGB'][1]/255,
1030 $textSettings['textRGB'][2]/255 ) );
1031 }
1032 else
1033 {
1034 $operatorValue .= ':' . $key . ':' . $textSettings[$key];
1035 }
1036 }
1037
1038 $httpCharset = eZTextCodec::internalCharset();
1039 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' )
1040 ? $config->variable( 'PDFGeneral', 'OutputCharset' )
1041 : 'iso-8859-1';
1042 $codec = eZTextCodec::instance( $httpCharset, $outputCharset );
1043 // Convert current text to $outputCharset (by default iso-8859-1)
1044 $text = $codec->convertString( $text );
1045
1046 $operatorValue .= '>' . urlencode( $text ) . '</ezGroup::callTextFrame>';
1047
1048 }
1049 }
1050
1051 eZDebug::writeNotice( 'Added TextFrame: ' . $operatorValue );
1052 } break;
1053
1054 default:
1055 {
1056 eZDebug::writeError( 'PDF operation "'. $namedParameters['operation'] .'" undefined', __METHOD__ );
1057 }
1058
1059 }
1060
1061 }
1062
1063 /*
1064 \private
1065 Create PDF object
1066 */
1067 function createPDF( $paper = 'a4', $orientation = 'portrait' )
1068 {
1069 $this->PDF = new eZPDFTable( $paper, $orientation );
1070 $this->PDF->selectFont( 'lib/ezpdf/classes/fonts/Helvetica' );
1071 eZDebug::writeNotice( 'PDF: File created' );
1072 }
1073
1075 public $Operators;
1076 public $PDF;
1077 public $Config;
1078 }
1079
1080
1081 ?>
eZClusterFileHandler\instance
static instance( $filename=false)
Definition: ezclusterfilehandler.php:21
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeNotice
static writeNotice( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:459
eZDir\mkdir
static mkdir( $dir, $perm=false, $recursive=false)
Definition: ezdir.php:73
eZDir\dirpath
static dirpath( $filepath)
Definition: ezdir.php:129
eZMath\rgbToCMYK2
static rgbToCMYK2( $r, $g, $b)
Definition: ezmath.php:81
eZMath\normalizeColorArray
static normalizeColorArray( $array)
Definition: ezmath.php:31
eZPDFTable
eZPDFTable adds extra support for tables
Definition: class.ezpdftable.php:18
eZPDF
eZPDF provides template operators for dealing with pdf generation
Definition: ezpdf.php:22
eZPDF\createPDF
createPDF( $paper='a4', $orientation='portrait')
Definition: ezpdf.php:1067
eZPDF\$Config
$Config
Definition: ezpdf.php:1077
eZPDF\$PDF
$PDF
Definition: ezpdf.php:1076
eZPDF\operatorList
operatorList()
Definition: ezpdf.php:37
eZPDF\$Operators
$Operators
The array of operators, used for registering operators.
Definition: ezpdf.php:1075
eZPDF\namedParameterList
namedParameterList()
Definition: ezpdf.php:45
eZPDF\modify
modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement)
Definition: ezpdf.php:55
eZPDF\__construct
__construct( $name="pdf")
Definition: ezpdf.php:28
eZTextCodec\internalCharset
static internalCharset()
Definition: eztextcodec.php:546
eZTextCodec\instance
static instance( $inputCharsetCode, $outputCharsetCode=false, $alwaysReturn=true)
Definition: eztextcodec.php:446
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.