The best IT partner for your business English version

Framework docs

Presentation > Reports > PDF Document

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. The goal of this sample is to demonstrate how to create a Brazilian Fiscal Document, supported by the Adianti Studio PDF Design tool. In the Adianti Studio PDF designer, we have created all the structure of the document using rectangles and texts. The rest of the document data is dynamically shown.

When the document 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 writeAtAnchor() method to write each data field of the document at one pre-defined position (defined by the anchor name). This anchor name was defined by the graphical interface (PDF Designer) when the document was designed. We also use the method Cell() from FPDF to show the product data many times. 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 Customer report
  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 PDFDesignNFEView 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 and a inner table
  24.         $this->form = new TForm('form_pdf_nfe');
  25.         $table = new TTable;
  26.         $this->form->add($table);
  27.         // creates an action button
  28.         $save_button=new TButton('generate');
  29.         $save_button->setAction(new TAction(array($this'onGenerate')), 'Generate');
  30.         $save_button->setImage('ico_save.png');
  31.         // add a row for the form action
  32.         $table->addRowSet($save_button);
  33.         // define wich are the form fields
  34.         $this->form->setFields(array($save_button));
  35.         
  36.         // wrap the page content using vertical box
  37.         $vbox = new TVBox;
  38.         $vbox->add(new TXMLBreadCrumb('menu.xml'__CLASS__));
  39.         $vbox->add($this->form);
  40.         parent::add($vbox);
  41.     }
  42.     /**
  43.      * method onGenerate()
  44.      * Executed whenever the user clicks at the generate button
  45.      */
  46.     function onGenerate()
  47.     {
  48.         try
  49.         {
  50.             $designer = new TPDFDesigner;
  51.             $designer->fromXml('app/reports/nfe.pdf.xml');
  52.             $designer->generate();
  53.             
  54.             $designer->SetFont('Arial''B'8);
  55.             $designer->setFontColorRGB'#4C4491' );
  56.             $designer->writeAtAnchor('for_ie',        '23234234234');
  57.             $designer->writeAtAnchor('for_cnpj',      '001.111.222.0001/00');
  58.             $designer->writeAtAnchor('nome',          utf8_decode('Cliente demonstração da silva'));
  59.             $designer->writeAtAnchor('endereco',      utf8_decode('Rua das demonstrações'));
  60.             $designer->writeAtAnchor('bairro',        'Centro');
  61.             $designer->writeAtAnchor('municipio',     'Cidade teste');
  62.             $designer->writeAtAnchor('fone',          '(11) 1234-5678');
  63.             $designer->writeAtAnchor('uf',            'RS');
  64.             $designer->writeAtAnchor('ie',            '45645645656');
  65.             $designer->writeAtAnchor('cep',           '00.0000-000');
  66.             $designer->writeAtAnchor('cnpjcpf',       '000.000.000-00');
  67.             $designer->writeAtAnchor('dataemissao',   '12/12/1912');
  68.             $designer->writeAtAnchor('dataentrada',   '12/12/1912');
  69.             $designer->writeAtAnchor('datasaida',     '12/12/1912');
  70.             $designer->writeAtAnchor('protocolo',     '1234567890');
  71.             $designer->writeAtAnchor('valor_produtos','1.000,00');
  72.             $designer->writeAtAnchor('frete',         '100,00');
  73.             $designer->writeAtAnchor('desconto',      '50,00');
  74.             $designer->writeAtAnchor('valor_nota',    '1.050,00');
  75.             $designer->writeAtAnchor('complementares',utf8_decode('Obs: Esta é a observação.'));
  76.             
  77.             $designer->gotoAnchorXY('details');
  78.             $designer->SetFont('Arial'''8);
  79.             $designer->Cell6210'12121212'10'C');
  80.             $designer->Cell(14010utf8_decode('Guaraná'), 10'L');
  81.             $designer->Cell3010'999'10'C');
  82.             $designer->Cell1510''10'C');
  83.             $designer->Cell2010''10'C');
  84.             $designer->Cell2010'PC'10'C');
  85.             $designer->Cell3510'100'10'C');
  86.             $designer->Cell3010'5,00'10'R');
  87.             $designer->Cell2410'0,25'10'R');
  88.             $designer->Cell2410'500'10'R');
  89.             $designer->Cell2410''10'L');
  90.             $designer->Cell2410''10'L');
  91.             $designer->Cell2410''10'L');
  92.             $designer->Cell2410''10'L');
  93.             $designer->Cell2410'0'10'R');
  94.             $designer->Cell2010'0'10'R');
  95.             $designer->Cell2010'0'10'R');
  96.             
  97.             $designer->Ln(10);
  98.             $designer->gotoAnchorX('details');
  99.             $designer->Cell6210'12121212'10'C');
  100.             $designer->Cell(14010utf8_decode('Chocolate'), 10'L');
  101.             $designer->Cell3010'999'10'C');
  102.             $designer->Cell1510''10'C');
  103.             $designer->Cell2010''10'C');
  104.             $designer->Cell2010'PC'10'C');
  105.             $designer->Cell3510'100'10'C');
  106.             $designer->Cell3010'5,00'10'R');
  107.             $designer->Cell2410'0,25'10'R');
  108.             $designer->Cell2410'500'10'R');
  109.             $designer->Cell2410''10'L');
  110.             $designer->Cell2410''10'L');
  111.             $designer->Cell2410''10'L');
  112.             $designer->Cell2410''10'L');
  113.             $designer->Cell2410'0'10'R');
  114.             $designer->Cell2010'0'10'R');
  115.             $designer->Cell2010'0'10'R');
  116.             
  117.             $file 'app/output/nfe.pdf';
  118.             
  119.             if (!file_exists($file) OR is_writable($file))
  120.             {
  121.                 $designer->save($file);
  122.                 parent::openFile($file);
  123.             }
  124.             else
  125.             {
  126.                 throw new Exception(_t('Permission denied') . ': ' $file);
  127.             }
  128.             
  129.             new TMessage('info''Report generated. Please, enable popups in the browser (just in the web).');
  130.         }
  131.         catch (Exception $e// in case of exception
  132.         {
  133.             new TMessage('error''<b>Error</b> ' $e->getMessage());
  134.         }
  135.     }
  136. }
  137. ?>