示例#1
0
 /**
  * Constructor
  * @param string $key the PDFLib license key we are using
  * @param int $pageType the type and size of the output
  */
 public function __construct($key, $pageType, \Jazzee\Controller $controller)
 {
     $this->pdf = new \PDFlib();
     if ($key) {
         try {
             $this->pdf->set_option("license={$key}");
         } catch (PDFlibException $e) {
             throw new Exception("Unable to validate PDFLib license key, check that your PDFLib version is compatible with your key: " . $e->getMessage());
         }
     }
     //This means we must check return values of load_font() etc.
     $this->pdf->set_option("errorpolicy=exception");
     $this->pdf->set_option("hypertextencoding=unicode");
     $this->fonts = array('h1' => array('face' => 'Helvetica-Bold', 'size' => '16.0', 'leading' => '100%', 'color' => array(207, 102, 0)), 'h3' => array('face' => 'Helvetica-Bold', 'size' => 12.0, 'leading' => '100%', 'color' => array(119, 153, 187)), 'h5' => array('face' => 'Helvetica-Bold', 'size' => 10.0, 'leading' => '100%', 'color' => array(119, 153, 187)), 'p' => array('face' => 'Helvetica', 'size' => 10.0, 'leading' => '100%', 'color' => array(0, 0, 0)), 'b' => array('face' => 'Helvetica-Bold', 'size' => 10.0, 'leading' => '100%', 'color' => array(0, 0, 0)), 'th' => array('face' => 'Helvetica-Bold', 'size' => 9.0, 'leading' => '100%', 'rowheight' => '10', 'color' => array(0, 0, 0)), 'td' => array('face' => 'Helvetica', 'size' => 8.0, 'leading' => '100%', 'rowheight' => '9', 'color' => array(0, 0, 0)));
     switch ($pageType) {
         case self::USLETTER_PORTRAIT:
             $this->pageWidth = 612;
             $this->pageHeight = 792;
             break;
         case self::USLETTER_LANDSCAPE:
             $this->pageWidth = 792;
             $this->pageHeight = 612;
             break;
         default:
             throw new Jazzee_Exception('Invalid page type supplied for ApplicantPDF constructor');
     }
     //  open new PDF file in memory
     $this->pdf->begin_document("", "");
     //add the first page
     $this->pdf->begin_page_ext($this->pageWidth, $this->pageHeight, "");
     $this->currentY = $this->pageHeight - 20;
     $this->setFont('p');
     $this->pdf->set_info("Creator", "Jazzee");
     $this->pdf->set_info("Author", "Jazzee Open Application Platform");
     $this->currentText = $this->pdf->create_textflow('', '');
     $this->_controller = $controller;
 }
示例#2
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');
     }
 }