The best IT partner for your business English version

Framework docs

Presentation > Reports > PDF Shapes

More productivity with Adianti Studio Pro

  • Forms designer;
  • Automatic form generation;
  • Automatic datagrid generation;
  • Create DB from your UML;
Ver detalhes...

This sample demonstrates the usage of a document created in Adianti Studio PDF Designer. This sample demonstrates how we can use different shapes (Rectangles, ellipses), and texts in a document. In this sample, we are creating a form, where the user will type its name.

When the report is generated (onGenerate()), the TPDFDesigner class is used to load the pdf design through fromXml() method. The document is created in memory by generate(). After this, we use gotoAnchorXY() to change the position at the document, and methods of FPDF like Write() to write content in the document. At the end, we use the save() method to write the document in the filesystem.

Important: Adianti PDF Designer is a tool that allows you to draw reports and documents that will be later generated in PDF. This "design" can be manipulated and completed with dynamic data from your database through your PHP code, using the methods from the traditional FPDF library.


Click here for
live demonstration

Example

  1. <?php
  2. /**
  3.  * PDF Designed Shapes
  4.  *
  5.  * @version    1.0
  6.  * @package    samples
  7.  * @subpackage tutor
  8.  * @author     Pablo Dall'Oglio
  9.  * @copyright  Copyright (c) 2006 Adianti Solutions Ltd. (http://www.adianti.com.br)
  10.  * @license    http://www.adianti.com.br/framework-license
  11.  */
  12. class PDFDesignShapesView extends TPage
  13. {
  14.     private $form// form
  15.     
  16.     /**
  17.      * Class constructor
  18.      */
  19.     function __construct()
  20.     {
  21.         parent::__construct();
  22.         
  23.         // creates the form
  24.         $this->form = new TForm('form_pdf_shapes');
  25.         
  26.         // creates a table
  27.         $table = new TTable;
  28.         
  29.         // add the table inside the form
  30.         $this->form->add($table);
  31.         // create the form fields
  32.         $name = new TEntry('name');
  33.         $name->addValidation'Name', new TRequiredValidator );
  34.         $label = new TLabel('Name' ': ');
  35.         $label->setFontColor('red');
  36.         $table->addRowSet($label$name);
  37.         
  38.         $save_button=new TButton('generate');
  39.         $save_button->setAction(new TAction(array($this'onGenerate')), 'Generate');
  40.         $save_button->setImage('ico_save.png');
  41.         // add a row for the form action
  42.         $table->addRowSet($save_button);
  43.         // define wich are the form fields
  44.         $this->form->setFields(array($name,$save_button));
  45.         
  46.         // wrap the page content using vertical box
  47.         $vbox = new TVBox;
  48.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  49.         $vbox->add($this->form);
  50.         parent::add($vbox);
  51.     }
  52.     /**
  53.      * method onGenerate()
  54.      * Executed whenever the user clicks at the generate button
  55.      */
  56.     function onGenerate()
  57.     {
  58.         try
  59.         {
  60.             $data $this->form->getData();
  61.             $this->form->validate();
  62.             
  63.             $designer = new TPDFDesigner;
  64.             $designer->fromXml('app/reports/forms.pdf.xml');
  65.             $designer->replace('{name}'$data->name );
  66.             $designer->generate();
  67.             
  68.             $designer->gotoAnchorXY('anchor1');
  69.             $designer->SetFontColorRGB('#FF0000');
  70.             $designer->SetFont('Arial''B'18);
  71.             $designer->Write(20'Dynamic text !');
  72.             
  73.             $file 'app/output/pdf_shapes.pdf';
  74.             
  75.             if (!file_exists($file) OR is_writable($file))
  76.             {
  77.                 $designer->save($file);
  78.                 parent::openFile($file);
  79.             }
  80.             else
  81.             {
  82.                 throw new Exception(_t('Permission denied') . ': ' $file);
  83.             }
  84.             
  85.             new TMessage('info''Report generated. Please, enable popups in the browser (just in the web).');
  86.         }
  87.         catch (Exception $e// in case of exception
  88.         {
  89.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  90.         }
  91.     }
  92. }
  93. ?>