Document Info and Metadata

Zend_Pdf module usage example

This section provides an example of module usage.

This example can be found in a demos/Zend/Pdf/demo.php file.

There are also test.pdf file, which can be used with this demo for test purposes.

Example #1 Zend_Pdf module usage demo

  1. /**
  2. * @package Zend_Pdf
  3. * @subpackage demo
  4. */"USAGE: php demo.php <pdf_file> [<output_pdf_file>]\n"'Can not open \'' . $argv[1] .
  5.                             '\' file for reading.') {
  6.         // Create new PDF if file doesn't exist
  7. // force complete file rewriting (instead of updating)
  8. // Throw an exception if it's not the "Can't open file
  9.         // exception
  10.         throw $e;
  11.     }
  12. }
  13.  
  14. //------------------------------------------------------------------------
  15. // Reverse page order
  16. // Create new Style
  17. // Create new image object
  18. '/stamp.jpg'// Example of operating with image loading exceptions.
  19. 'Image extension is not installed.' &&
  20.         $e->getMessage() != 'JPG support is not configured properly.'// Mark page as modified
  21. 'Modified by Zend Framework!', 150, 0)
  22.          ->restoreGS();
  23. }
  24.  
  25. // Add new page generated by Zend_Pdf object
  26. // (page is attached to the specified the document)
  27. 'A4'));
  28.  
  29. // Add new page generated by Zend_Pdf_Page object
  30. // (page is not attached to the document)
  31. // Create new font
  32. // Apply font and draw text
  33. '#9999cc'))
  34.       ->drawText('Helvetica 36 text string', 60, 500);
  35.  
  36. // Use font object for another page
  37. $page2->setFont($font, 24)
  38.       ->drawText('Helvetica 24 text string', 60, 500);
  39.  
  40. // Use another font
  41. 'Times-Roman 32 text string', 60, 450);
  42.  
  43. // Draw rectangle
  44. // Draw circle
  45. // Draw sectors
  46. // Draw ellipse
  47. // Draw and fill polygon
  48. // ----------- Draw figures in modified coordination system --------------
  49.  
  50. // Coordination system movement
  51. $page2->saveGS();
  52. $page2->translate(60, 250); // Shift coordination system
  53.  
  54. // Draw rectangle
  55. // Draw circle
  56. // Draw sectors
  57. // Draw ellipse
  58. // Draw and fill polygon
  59. // Draw line
  60. // Coordination system movement, skewing and scaling
  61. $page2->saveGS();
  62. $page2->translate(60, 150)     // Shift coordination system
  63. // Skew coordination system
  64.       ->scale(0.9, 0.9);       // Scale coordination system
  65.  
  66. // Draw rectangle
  67. // Draw circle
  68. // Draw sectors
  69. // Draw ellipse
  70. // Draw and fill polygon
  71. // Draw line
  72. //------------------------------------------------------------------------
  73. /* update */);
  74. }

Document Info and Metadata