Esempio n. 1
0
 /**
  * Write the current table
  */
 public function writeTable()
 {
     $table = 0;
     //initialize table with 0
     foreach ($this->currentTable as $rowId => $columns) {
         foreach ($columns as $columnId => $text) {
             $fontType = $rowId == 1 ? 'th' : 'td';
             $textFlow = $this->pdf->add_textflow(0, $text, $this->fontOptions($fontType));
             $table = $this->pdf->add_table_cell($table, $columnId + 1, $rowId, '', "rowheight={$this->fonts[$fontType]['rowheight']} fittextflow={verticalalign=top} textflow={$textFlow} margin=1");
         }
     }
     if ($table) {
         do {
             $continue = false;
             //If we are closer that one header row from the bottom of the page then create a new page and then place the table
             if ($this->fonts['th']['rowheight'] > $this->currentY - 50) {
                 //TOO CLOSE
                 $this->newPage();
             }
             $return = $this->pdf->fit_table($table, 25, 25, $this->pageWidth - 20, $this->currentY, 'stroke={{line=other}}');
             if ($return == '_boxfull') {
                 $this->newPage();
                 $continue = true;
             }
         } while ($continue);
         $height = $this->pdf->info_table($table, 'height');
         $this->currentY = $this->currentY - $height;
         if ($this->currentY < 25) {
             $this->newPage();
         }
         $this->pdf->delete_table($table, '');
         $this->currentTable = array();
         $this->tableRow = false;
     }
 }
Esempio n. 2
0
 public static function pdf_set_default_color(PDFLib $pdf, $type = '')
 {
     $color['r'] = hexdec(substr(self::$defaultColor, 0, 2)) / 255;
     $color['g'] = hexdec(substr(self::$defaultColor, 2, 2)) / 255;
     $color['b'] = hexdec(substr(self::$defaultColor, 4, 2)) / 255;
     if ($type != 'fill' && $type != 'stroke') {
         $type = 'both';
     }
     $pdf->setcolor($type, 'rgb', $color['r'], $color['g'], $color['b'], 0);
 }
Esempio n. 3
0
 /**
  * Edit a template
  */
 public function actionEdit($id)
 {
     if ($template = $this->_application->getTemplateById($id)) {
         $pdfLib = new PDFLib();
         $pdfLib->set_option("errorpolicy=exception");
         $tmpFile = tempnam($this->_config->getVarPath() . '/tmp/', 'pdftemplate');
         $document = $pdfLib->open_pdi_document($template->getTmpFilePath(), "");
         $pagecount = $pdfLib->pcos_get_number($document, "length:pages");
         $blocks = array();
         for ($pageNum = 0; $pageNum < $pagecount; $pageNum++) {
             $blockcount = $pdfLib->pcos_get_number($document, "length:pages[{$pageNum}]/blocks");
             for ($blockNum = 0; $blockNum < $blockcount; $blockNum++) {
                 $blocks[] = $pdfLib->pcos_get_string($document, "pages[{$pageNum}]/blocks[{$blockNum}]/Name");
             }
         }
         $blocks = array_unique($blocks);
         $form = new \Foundation\Form();
         $form->setCSRFToken($this->getCSRFToken());
         $form->setAction($this->path("setup/pdftemplates/edit/" . $template->getId()));
         $field = $form->newField();
         $field->setLegend('Edit Template Blocks');
         $element = $field->newElement('TextInput', 'title');
         $element->setLabel('Title');
         $element->setValue($template->getTitle());
         $element->addValidator(new \Foundation\Form\Validator\NotEmpty($element));
         $blockElements = array('applicant-firstName' => 'Applicant: First Name', 'applicant-lastName' => 'Applicant: Last Name', 'applicant-middleName' => 'Applicant: Middle Name', 'applicant-suffix' => 'Applicant: Suffix', 'applicant-fullName' => 'Applicant: Full Name', 'applicant-email' => 'Applicant: Email', 'applicant-id' => 'Applicant: ID', 'applicant-externalid' => 'Applicant: External ID');
         foreach ($this->_application->getApplicationPages() as $applicationPage) {
             if ($applicationPage->getJazzeePage() instanceof \Jazzee\Interfaces\PdfPage) {
                 foreach ($applicationPage->getJazzeePage()->listPdfTemplateElements() as $key => $title) {
                     $blockElements[$key] = $title;
                 }
             }
         }
         foreach ($blocks as $blockName) {
             $element = $field->newElement('SelectList', 'block_' . $blockName);
             $element->setLabel("Block {$blockName}");
             $element->newItem(null, '');
             foreach ($blockElements as $id => $title) {
                 $element->newItem($id, $title);
             }
             if ($template->hasBlock($blockName)) {
                 $blockData = $template->getBlock($blockName);
                 switch ($blockData['type']) {
                     case 'applicant':
                         $element->setValue('applicant-' . $blockData['element']);
                         break;
                     case 'page':
                         $element->setValue('page-' . $blockData['pageId'] . '-element-' . $blockData['elementId']);
                         break;
                 }
             }
         }
         if ($input = $form->processInput($this->post)) {
             $template->setTitle($input->get('title'));
             $template->clearBlocks();
             $matches = array();
             //initialize for use in preg_match
             foreach ($blocks as $blockName) {
                 if ($blockElement = $input->get('block_' . $blockName)) {
                     if (preg_match('#applicant-([a-z]+)#i', $blockElement, $matches)) {
                         $template->addBlock($blockName, array('type' => 'applicant', 'element' => $matches[1]));
                     } else {
                         if (preg_match('#page-([0-9]+)-element-([0-9]+)#i', $blockElement, $matches)) {
                             $template->addBlock($blockName, array('type' => 'page', 'pageId' => $matches[1], 'elementId' => $matches[2]));
                         }
                     }
                 }
             }
             $this->getEntityManager()->persist($template);
             $this->addMessage('success', 'Template Saved Successfully');
             $this->redirectPath('setup/pdftemplates');
         }
         $form->newButton('submit', 'Save');
         $this->setVar('form', $form);
     } else {
         $this->addMessage('error', 'Unable to edit template.  It is not associated with this application.');
         $this->redirectPath('setup/pdftemplates');
     }
 }