public function testRender() { $pdf = \Zend_Pdf::load(__DIR__ . '/MSWord.pdf'); $expected = \Zend_Pdf::load(__DIR__ . '/MSWordExpected.pdf'); $gemsPdf = $this->loader->getPdf(); // Start code to expose protected method $addTokenToDocument = function (\Zend_Pdf $pdf, $tokenId, $surveyId) { return $this->addTokenToDocument($pdf, $tokenId, $surveyId); }; $testObject = $addTokenToDocument->bindTo($gemsPdf, $gemsPdf); // End code to expose protected method $testObject($pdf, "abcd-efgh", 1); // fix the date to prevent differences $pdf->properties['ModDate'] = 'D:' . str_replace(':', "'", date('YmdHisP', 1458048768)) . "'"; // Uncomment to update the test pdf /* $stream = fopen(__DIR__ . '/MSWordExpected.pdf', 'w'); $pdf->render(false, $stream); fclose($stream); */ // This will trigger the warning in #812: Warning when printing a survey pdf that was created using Word // This warning will cause the test to fail $pdf->render(); $this->assertEquals($expected->getMetadata(), $pdf->getMetadata()); $this->assertEquals($expected->properties, $pdf->properties); }
public function verPdfAction() { $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); $producto = $this->_producto->getDetalle($this->_getParam('id')); // var_dump($producto);exit; $pdf = new Zend_Pdf(); $pdf1 = Zend_Pdf::load(APPLICATION_PATH . '/../templates/producto.pdf'); // $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // 595 x842 $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA); // $pdf->pages[] = $page; // $page->setFont($font, 20);$page->drawText('Zend: PDF', 10, 822); // $page->setFont($font, 12);$page->drawText('Comentarios', 10, 802); // $pdfData = $pdf->render(); $page = $pdf1->pages[0]; $page->setFont($font, 12); $page->drawText($producto['producto'], 116, 639); $page->drawText($producto['precio'], 116, 607); $page->drawText($producto['categoria'], 116, 575); $page->drawText($producto['fabricante'], 116, 543); $page->drawText('zEND', 200, 200); $pdfData = $pdf1->render(); header("Content-type: application/x-pdf"); header("Content-Disposition: inline; filename=result.pdf"); $this->_response->appendBody($pdfData); }
/** * Extract data from a PDF document and add this to the Lucene index. * * @param string $pdfPath The path to the PDF document. * @param Zend_Search_Lucene_Proxy $luceneIndex The Lucene index object. * @return Zend_Search_Lucene_Proxy */ public static function index($pdfPath, $luceneIndex) { // Load the PDF document. $pdf = Zend_Pdf::load($pdfPath); $key = md5($pdfPath); /** * Set up array to contain the document index data. * The Filename will be used to retrive the document if it is found in * the search resutls. * The Key will be used to uniquely identify the document so we can * delete it from the search index. */ $indexValues = array('Filename' => $pdfPath, 'Key' => $key, 'Title' => '', 'Author' => '', 'Subject' => '', 'Keywords' => '', 'Creator' => '', 'Producer' => '', 'CreationDate' => '', 'ModDate' => '', 'Contents' => ''); // Go through each meta data item and add to index array. foreach ($pdf->properties as $meta => $metaValue) { switch ($meta) { case 'Title': $indexValues['Title'] = $pdf->properties['Title']; break; case 'Subject': $indexValues['Subject'] = $pdf->properties['Subject']; break; case 'Author': $indexValues['Author'] = $pdf->properties['Author']; break; case 'Keywords': $indexValues['Keywords'] = $pdf->properties['Keywords']; break; case 'CreationDate': $dateCreated = $pdf->properties['CreationDate']; $distance = substr($dateCreated, 16, 2); if (!is_long($distance)) { $distance = null; } // Convert date from the PDF format of D:20090731160351+01'00' $dateCreated = mktime(substr($dateCreated, 10, 2), substr($dateCreated, 12, 2), substr($dateCreated, 14, 2), substr($dateCreated, 6, 2), substr($dateCreated, 8, 2), substr($dateCreated, 2, 4), $distance); //distance $indexValues['CreationDate'] = date('Ymd', $dateCreated); break; case 'Date': $indexValues['Date'] = $pdf->properties['Date']; break; } } /** * Parse the contents of the PDF document and pass the text to the * contents item in the $indexValues array. */ $pdfParse = new App_Search_Helper_PdfParser(); $indexValues['Contents'] = $pdfParse->pdf2txt($pdf->render()); // Create the document using the values $doc = new App_Search_Lucene_Document($indexValues); if ($doc !== false) { // If the document creation was sucessful then add it to our index. $luceneIndex->addDocument($doc); } // Return the Lucene index object. return $luceneIndex; }
/** extract metadata */ public function extract($revision) { /** @var ItemRevisionModel $itemRevisionModel */ $itemRevisionModel = MidasLoader::loadModel('ItemRevision'); $revision = $itemRevisionModel->load($revision['itemrevision_id']); if (!$revision) { return; } $bitstreams = $revision->getBitstreams(); if (count($bitstreams) != 1) { return; } $bitstream = $bitstreams[0]; $ext = strtolower(substr(strrchr($bitstream->getName(), '.'), 1)); /** @var MetadataModel $metadataModel */ $metadataModel = MidasLoader::loadModel('Metadata'); if ($ext == 'pdf') { $pdf = Zend_Pdf::load($bitstream->getFullPath()); foreach ($pdf->properties as $name => $property) { $name = strtolower($name); try { $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'misc', $name); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'misc', $name, ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'misc', $name, $property); } catch (Zend_Exception $exc) { echo $exc->getMessage(); } } } else { /** @var SettingModel $settingModel */ $settingModel = MidasLoader::loadModel('Setting'); $command = $settingModel->getValueByName(METADATAEXTRACTOR_HACHOIR_METADATA_COMMAND_KEY, $this->moduleName); exec(str_replace("'", '"', $command) . ' "' . $bitstream->getFullPath() . '"', $output); if (!isset($output[0]) || $output[0] != 'Metadata:') { return; } unset($output[0]); foreach ($output as $out) { $out = substr($out, 2); $pos = strpos($out, ': '); $name = strtolower(substr($out, 0, $pos)); $value = substr($out, $pos + 2); try { $metadataDao = $metadataModel->getMetadata(MIDAS_METADATA_TEXT, 'misc', $name); if (!$metadataDao) { $metadataModel->addMetadata(MIDAS_METADATA_TEXT, 'misc', $name, ''); } $metadataModel->addMetadataValue($revision, MIDAS_METADATA_TEXT, 'misc', $name, $value); } catch (Zend_Exception $exc) { echo $exc->getMessage(); } } } }
public function editmetaAction() { // Get the form and send to the view. $form = new Form_PdfMeta(); $this->view->form = $form; // Get the file and send the location to the view. $pdfPath = urldecode($this->_request->getParam('file')); $file = substr($pdfPath, strrpos($pdfPath, SLASH) + 1); $this->view->file = $file; // Define what meta data we are looking at. $metaValues = array('Title' => '', 'Author' => '', 'Subject' => '', 'Keywords' => ''); if ($this->_request->isPost()) { // Get the current form values. $formData = $this->_request->getPost(); if ($form->isValid($formData)) { // Form values are valid. // Save the contents of the form to the associated meta data fields in the PDF. $pdf = Zend_Pdf::load($pdfPath); foreach ($metaValues as $meta => $metaValue) { if (isset($formData[$meta])) { $pdf->properties[$meta] = $formData[$meta]; } else { $pdf->properties[$meta] = ''; } } $pdf->save($pdfPath); // Add to/update index. $config = Zend_Registry::get('config'); $appLucene = App_Search_Lucene::open($config->luceneIndex); $index = App_Search_Lucene_Index_Pdfs::index($pdfPath, $appLucene); // Redirect the user to the list action of this controller. return $this->_helper->redirector('list', 'pdf', '', array())->setCode(301); } else { // Form values are not valid send the current values to the form. $form->populate($formData); } } else { // Make sure the file exists before we start doing anything with it. if (file_exists($pdfPath)) { // Extract any current meta data values from the PDF document $pdf = Zend_Pdf::load($pdfPath); foreach ($metaValues as $meta => $metaValue) { if (isset($pdf->properties[$meta])) { $metaValues[$meta] = $pdf->properties[$meta]; } else { $metaValues[$meta] = ''; } } // Populate the form with out metadata values. $form->populate($metaValues); } else { // File doesn't exist. } } }
/** * Returns true if and only if $value meets the validation requirements * * If $value fails validation, then this method returns false, and * getMessages() will return an array of messages that explain why the * validation failed. * * @param mixed $value * @return boolean * @throws \Zend_Valid_Exception If validation of $value is impossible */ public function isValid($value, $context = array()) { // Only fail when file really can't be loaded. try { \Zend_Pdf::load($value); return true; } catch (\Zend_Pdf_Exception $e) { $this->_error(self::ERROR_INVALID_VERSION, $e->getMessage()); return false; } }
/** * * @return Zend_Pdf * */ public function createPdfTemplate() { if ($this->getDi()->config->get('invoice_custom_template') && ($upload = $this->getDi()->uploadTable->load($this->getDi()->config->get('invoice_custom_template')))) { $pdf = Zend_Pdf::load($upload->getFullPath()); $this->pointer = $this->getPaperHeight() - $this->getDi()->config->get('invoice_skip', 150); } else { $pdf = new Zend_Pdf(); $pdf->pages[0] = $pdf->newPage($this->getDi()->config->get('invoice_format', Zend_Pdf_Page::SIZE_LETTER)); $this->pointer = $this->drawDefaultTemplate($pdf); } return $pdf; }
public function init() { //On récupère l'id du document que l'on doit afficher à partir de l'indexController $request = $this->getRequest(); //Comme nous n'avons pas Active Directory, on suppose que l'ID utilisateur est de 6 $this->user_ID = 6; // Etat concernant les documents que nous avons utilis� dans la base de donn�e oracle $this->etat_encours = 1; $this->etat_surtablette = 2; $this->etat_valide = 3; $this->etat_refuse = 4; $this->etat_enattente = 5; $this->etat_demandeur = 6; //On récupère l'ID du document que nous souhaitons afficher à partir de l'indexController $request = $this->getRequest(); $this->id_document = $request->getParam('COURRIER_ID'); $db = Zend_Db_Table::getDefaultAdapter(); //Si l'utilisateur n'est pas habilit� � voir le document, il est renvoy� � la page d'acceuil. // On r�cup�re le lien entre l'utilisateur et le document. $sqlhabilitated = 'SELECT * FROM LIENINTERNE WHERE ID_COURRIER =' . $this->id_document . 'AND ID_ENTITEDESTINATAIRE = ' . $this->user_ID; $stmthabilitated = $db->query($sqlhabilitated); while ($rowhabilitated = $stmthabilitated->fetch()) { $etat_habilitated[] = $rowhabilitated['ID_ETATDESTINATAIRE']; } if ($etat_habilitated[0] == null || $etat_habilitated[0] == 0) { //Il n'existe de lien entre l'utilisateur et le document. $this->_helper->redirector('index', 'index'); } else { if ($etat_habilitated[0] != $this->etat_encours && $etat_habilitated[0] != $this->etat_surtablette && $etat_habilitated[0] != $this->etat_demandeur) { //Le lien entre la personne et le document n'est plus valide. $this->_helper->redirector('index', 'index'); } } //URL utilisé pour récupérer le document pour la liseuse $url = 'http://' . $_SERVER['HTTP_HOST'] . '/pdf/' . $this->id_document . '.pdf'; //Fichier PDF qui est utilisé = useful for signature and images $this->filePath = APPLICATION_PATH . '/../public/pdf/' . $this->id_document . '.pdf'; $this->view->pdfurl = $url; $this->pdf = new Zend_Pdf(); $this->pdf = Zend_Pdf::load($this->filePath, null, true); }
public function testPageCloning() { $pdf = Zend_Pdf::load(dirname(__FILE__) . '/_files/pdfarchiving.pdf'); $srcPageCount = count($pdf->pages); try { $newPage = clone reset($pdf->pages); } catch (Zend_Pdf_Exception $e) { if (strpos($e->getMessage(), 'Cloning Zend_Pdf_Page object using \'clone\' keyword is not supported.') !== 0) { throw $e; } // Exception is thrown } $outputPageSet = array(); foreach ($pdf->pages as $srcPage) { $page = new Zend_Pdf_Page($srcPage); $outputPageSet[] = $srcPage; $outputPageSet[] = $page; $page->saveGS(); // Create new Style $page->setFillColor(new Zend_Pdf_Color_Rgb(0, 0, 0.9))->setLineColor(new Zend_Pdf_Color_GrayScale(0.2))->setLineWidth(3)->setLineDashingPattern(array(3, 2, 3, 4), 1.6)->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD), 32); $page->rotate(0, 0, M_PI_2 / 3); $page->drawText('Modified by Zend Framework!', 150, 0); $page->restoreGS(); } // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages = $outputPageSet; $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); $this->assertEquals($srcPageCount * 2, count($pdf1->pages)); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
public static function user_order_receipt() { return function ($request, $response) { $user_id = $request->session('id'); if ($user_id) { $response->header('Content-Type', 'application/pdf'); $id = $request->id; $order = Order::findById($id); $report = Zend_Pdf::load('../pdf/trustrec.pdf'); $page = $report->pages[0]; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $page->setFont($font, 11); $page->drawText(Time::unixToDate(time()), 460, 900); $page->drawText(Time::unixToDate(time()), 460, 455); $page->drawText('Order#: ' . $order->id, 400, 910); $page->drawText('Order#: ' . $order->id, 400, 465); $page->drawText($order->user->profile->fullname, 100, 900); $page->drawText($order->user->profile->fullname, 100, 455); $page->drawText($order->user->profile->address, 440, 530); $page->drawText($order->user->profile->address, 440, 85); $page->drawText($order->user->profile->fullname, 445, 555); $page->drawText($order->user->profile->fullname, 445, 109); $row = 850; foreach ($order->items as $item) { # code... $page->drawText($item->product->name, 80, $row); $page->drawText($item->product->name, 80, $row - 446); $page->drawText($item->quantity, 45, $row); $page->drawText($item->quantity, 45, $row - 446); $page->drawText(money_format('%5.2n', $item->product->price), 315, $row); $page->drawText(money_format('Php %5.2n', $item->subtotal), 370, $row); $page->drawText(money_format('%5.2n', $item->product->price), 315, $row - 446); $page->drawText(money_format('Php %5.2n', $item->subtotal), 370, $row - 446); $row -= 17; } $page->drawText(money_format('Php %5.2n', $order->total), 370, 562); $page->drawText(money_format('Php %5.2n', $order->total), 370, 118); #$page->drawText( money_format('Php %5.2n', $order->total * 0.30),450,485); echo $report->render(); } else { $response->code(403); } }; }
<?php header('Content-Type: application/x-pdf'); header("Content-Disposition: inline; filename=invoice-" . date("Y-m-d-H-i") . ".pdf"); header("Cache-Control: no-cache, must-revalidate"); $path = dirname(dirname(__FILE__)) . '/library'; set_include_path(get_include_path() . PATH_SEPARATOR . $path); require_once "Zend/Pdf.php"; $daily = Zend_Pdf::load('Daily.pdf'); $page = $daily->pages[0]; $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $page->setFont($font, 11); //echo "Height = {$page->getHeight()} \n"; //echo "Width = {$page->getWidth()} \n"; $date = 'Date: 9/19/2012'; $name = 'Jellene Q. Pastoral'; $name2 = 'Rosemarie C. Villacorta'; $name3 = 'Florefie A. Remedios'; $page->drawText($date, 460, 720); $page->drawText($name, 54, 684); // diff 14 pt $page->drawText($name2, 54, 670); $page->drawText($name3, 54, 656); $daily->save('wewe.pdf');
/** * @group ZF-8462 */ public function testPhpVersionBug() { try { $file = dirname(__FILE__) . '/_files/ZF-8462.pdf'; $pdf = Zend_Pdf::load($file); } catch (Zend_Pdf_Exception $e) { if (strpos($e->getMessage(), 'Cross-reference streams are not supported yet.') !== false) { // Skip expected exception return; } throw $e; } }
public static function load($source = null, $revision = null) { self::$file = $source; self::$_pdf = parent::load($source); }
public function pdfAction() { require_once '/Zend/Pdf.php'; require_once '/PS/utils.php'; if (!$this->_hasParam('id')) { return $this->_redirect('/analysis/index/page/1'); } $datos = new Application_Model_Analysis(); $row = $datos->getRow($this->_getParam('id')); if ($row) { $data = $row->toArray(); $contact = new Application_Model_Contacts(); $results = new Application_Model_Results(); $exa = $datos->BySpecialties($this->_getParam('id')); $customer = $contact->getRow($data['applicant_id'])->toArray(); $medico = $contact->getRow($data['medic_id'])->toArray(); $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(); //$pdf = new Zend_Pdf(); if ($data['name'] == 1) { $pdf = Zend_Pdf::load('img/2.pdf'); } else { $pdf = Zend_Pdf::load('img/1.pdf'); } $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); //$pdf->pages[] = $page; $page = $pdf->pages[0]; /* //specify color $color = new Zend_Pdf_Color_HTML("navy"); $page->setFillColor($color); */ $fontT = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_TIMES); $page->setFont(Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA), 10); $page->drawText($customer['first_name'] . ' ' . $customer['last_name'], 125, 712); $page->drawText(date('Y-m-d', strtotime($data['date_entered'])), 455, 712); $page->drawText(birthday($customer['birthdate']), 125, 700); $page->drawText($customer['gender'], 455, 700); $page->drawText($medico['first_name'] . ' ' . $medico['last_name'], 125, 685); $posY = 670; foreach ($exa as $key) { $posY -= 50; $page->setLineWidth(0.5); $page->drawLine(50, $posY + 15, 530, $posY + 15); $page->setLineWidth(0.5); $page->drawLine(50, $posY - 10, 530, $posY - 10); $page->drawText('Examen', 50, $posY); $page->drawText('Resultado', 280, $posY); $page->drawText('U.M.', 360, $posY); $page->drawText('Valores de Referencia', 400, $posY); $page->drawText($key['name'], 50, $posY - 25); $res = $results->getBy(array('analysis_id =?' => $key['analysis_id'], 'test_id =?' => $key['itest_id']))->toArray(); $posY -= 38.4; foreach ($res as $keyd) { $page->drawText($keyd['item_name'], 60, $posY); $page->drawText($keyd['result'], 280, $posY); $page->drawText($keyd['ref_val_unit'], 350, $posY); $page->drawText($keyd['ref_val_value'], 420, $posY); $posY -= 14.2; } $posY -= 20.2; $page->drawText('MUESTRA:', 280, $posY); $page->drawText('METODO DE PROCESO:', 280, $posY - 14); } if ($posY < 400) { $page2 = new Zend_Pdf_Page($page); $pdf->pages[] = $page2; } $page->drawText('OBSERVACIONES:', 50, 170); $page->drawText($data['note'], 50, 155); $this->getResponse()->setHeader('Content-Disposition', 'attachment; filename=result.pdf')->setHeader('Content-type', 'application/x-pdf'); echo $pdf->render(); } }
<?php ini_set('include_path', '/www/PHP-Library'); require_once "Zend/Exception.php"; require_once "Zend/Pdf.php"; require_once "Zend/Pdf/Exception.php"; $testPDF = 'Monte Carlo Model of Background Glutamate Spillover in the Hippocampus 2004-3291.pdf'; $ZendPDF = Zend_Pdf::load($testPDF); print_r($ZendPDF->properties); $ZendPDF->properties['foo'] = 'bar'; $ZendPDF->save($testPDF);
require_once 'Zend/Pdf/Style.php'; require_once 'Zend/Pdf/Color/Cmyk.php'; require_once 'Zend/Pdf/Color/Html.php'; require_once 'Zend/Pdf/Color/GrayScale.php'; require_once 'Zend/Pdf/Color/Rgb.php'; require_once 'Zend/Pdf/Page.php'; require_once 'Zend/Pdf/Font.php'; if (!isset($argv[1])) { echo "USAGE: php demo.php <pdf_file> [<output_pdf_file>]\n"; exit; } try { $pdf = Zend_Pdf::load($argv[1]); } catch (Zend_Pdf_Exception $e) { if ($e->getMessage() == 'Can not open \'' . $argv[1] . '\' file for reading.') { // Create new PDF if file doesn't exist $pdf = new Zend_Pdf(); if (!isset($argv[2])) { // force complete file rewriting (instead of updating) $argv[2] = $argv[1]; } } else { // Throw an exception if it's not the "Can't open file" exception throw $e; } }
<?php //Change this to the path where your 1.9.3 library/Zend folder lives ini_set('include_path', '/www/PHP-Library'); require_once "Zend/Exception.php"; require_once "Zend/Pdf.php"; require_once "Zend/Pdf/Exception.php"; $doesnotCrash = 'doesnotcrash.pdf'; $crashPDF = 'Makeig.IntJNeuropharm.09.pdf'; $NormalLoad = Zend_Pdf::load($doesnotCrash); $CrashLoad = Zend_Pdf::load($crashPDF);
/** * method to load the pdf document in zend_framework * @param void * @return void */ public function load() { $this->pdf = Zend_Pdf::load($this->version->getPath()); }
/** * * @param integer $surveyId * @return \Zend_Pdf */ protected function getSurveyPdf($surveyId) { $filename = $this->db->fetchOne('SELECT gsu_survey_pdf FROM gems__surveys WHERE gsu_id_survey = ?', $surveyId); if (!$filename) { $filename = $surveyId . '.pdf'; } $filepath = $this->getSurveysDir() . '/' . $filename; if (!file_exists($filepath)) { // \MUtil_Echo::r($filepath); $this->throwLastError(sprintf($this->translate->_("PDF Source File '%s' not found!"), $filename)); } return \Zend_Pdf::load($filepath); }
public function divineFileFormat($ps_filepath) { if ($ps_filepath == '') { return ''; } if (!$this->opo_config->get('dont_use_graphicsmagick_to_identify_pdfs') && caMediaPluginGraphicsMagickInstalled($this->ops_graphicsmagick_path)) { if (is_array($va_info = $this->_graphicsMagickIdentify($ps_filepath)) && sizeof($va_info)) { $vn_width = $va_info['width']; $vn_height = $va_info['height']; $vn_res = 72; $vn_pages = $va_info['pages']; } else { return null; } } else { if (!$this->opo_config->get('dont_use_imagemagick_to_identify_pdfs') && caMediaPluginImageMagickInstalled($this->ops_imagemagick_path)) { if (is_array($va_info = $this->_imageMagickIdentify($ps_filepath)) && sizeof($va_info)) { $vn_width = $va_info['width']; $vn_height = $va_info['height']; $vn_res = 72; $vn_pages = $va_info['pages']; } else { return null; } } else { try { include_once __CA_LIB_DIR__ . "/core/Zend/Pdf.php"; $o_pdf = Zend_Pdf::load($ps_filepath); if (sizeof($o_pdf->pages) == 0) { return ''; } } catch (Exception $e) { return null; } $o_page = $o_pdf->pages[0]; $vn_width = $o_page->getWidth(); $vn_height = $o_page->getHeight(); $vn_res = 72; $vn_pages = sizeof($o_pdf->pages); } } $vs_mimetype = "application/pdf"; if ($vs_mimetype && $this->info["IMPORT"][$vs_mimetype]) { $this->handle = $this->ohandle = array("filepath" => $ps_filepath, "width" => $vn_width, "height" => $vn_height, "mimetype" => $vs_mimetype, "resolution" => $vn_res, "pages" => $vn_pages, "page" => 1, "quality" => 75, "filesize" => filesize($ps_filepath), "content" => '', "content_by_location" => array()); $this->properties = array("width" => $this->handle["width"], "height" => $this->handle["height"], "mimetype" => $vs_mimetype, "quality" => 75, "pages" => $this->handle["pages"], "page" => 1, "resolution" => 72, "filesize" => $this->handle["filesize"], "typename" => "PDF"); return $vs_mimetype; } else { return ''; } }
public function setTemplate($template) { return Zend_Pdf::load('library/' . $template); }
public function testFontDrawing() { $pdf = new Zend_Pdf(); $fontsList = array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_COURIER_BOLD, Zend_Pdf_Font::FONT_COURIER_BOLD_ITALIC, Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE, Zend_Pdf_Font::FONT_COURIER_ITALIC, Zend_Pdf_Font::FONT_COURIER_OBLIQUE, Zend_Pdf_Font::FONT_HELVETICA, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_HELVETICA_BOLD_ITALIC, Zend_Pdf_Font::FONT_HELVETICA_BOLD_OBLIQUE, Zend_Pdf_Font::FONT_HELVETICA_ITALIC, Zend_Pdf_Font::FONT_HELVETICA_OBLIQUE, Zend_Pdf_Font::FONT_TIMES, Zend_Pdf_Font::FONT_TIMES_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, Zend_Pdf_Font::FONT_TIMES_ITALIC, Zend_Pdf_Font::FONT_TIMES_ROMAN); $titleFont = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_COURIER_BOLD_OBLIQUE); foreach ($fontsList as $fontName) { // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); $font = Zend_Pdf_Font::fontWithName($fontName); $this->assertTrue($font instanceof Zend_Pdf_Resource_Font); $page->setFont($titleFont, 10); $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400); $page->setFont($font, 20); $page->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360); $ascent = $font->getAscent(); $this->assertTrue(abs(1 - $font->getCoveredPercentage('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz')) < 1.0E-5); $descent = $font->getDescent(); $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en'); $type = $font->getFontType(); $lineGap = $font->getLineGap(); $lineHeight = $font->getLineHeight(); $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object); $font->getStrikePosition(); $font->getStrikeThickness(); $font->getUnderlinePosition(); $font->getUnitsPerEm(); $font->widthForGlyph(10); } $nonAlphabeticalPhonts = array(Zend_Pdf_Font::FONT_SYMBOL => " !\"#\"%&\"\v()\"+,\"./0123456789:;<=>?\"E‘’§\"•¦", Zend_Pdf_Font::FONT_ZAPFDINGBATS => " ''''&''''\t&&'\f'\r'''''''''''''"); foreach ($nonAlphabeticalPhonts as $fontName => $example) { // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); $font = Zend_Pdf_Font::fontWithName($fontName); $this->assertTrue($font instanceof Zend_Pdf_Resource_Font); $page->setFont($titleFont, 10); $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400); $page->setFont($font, 20); $page->drawText($example, 100, 360, 'UTF-16BE'); $ascent = $font->getAscent(); $this->assertTrue(abs(1 - $font->getCoveredPercentage($example, 'UTF-16BE')) < 1.0E-5); $descent = $font->getDescent(); $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en'); $type = $font->getFontType(); $lineGap = $font->getLineGap(); $lineHeight = $font->getLineHeight(); $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object); $font->getStrikePosition(); $font->getStrikeThickness(); $font->getUnderlinePosition(); $font->getUnitsPerEm(); $font->widthForGlyph(10); } $TTFFontsList = array('VeraBd.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMoBd.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraMono.ttf', 'VeraSeBd.ttf', 'VeraSe.ttf', 'Vera.ttf'); foreach ($TTFFontsList as $fontName) { // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); $font = Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/_fonts/' . $fontName); $this->assertTrue($font instanceof Zend_Pdf_Resource_Font); $page->setFont($titleFont, 10); $page->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400); $page->setFont($font, 20); $page->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360); $ascent = $font->getAscent(); $this->assertTrue(abs(1 - $font->getCoveredPercentage('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxwz')) < 1.0E-5); $descent = $font->getDescent(); $font->getFontName(Zend_Pdf_Font::NAME_FULL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_FAMILY, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_PREFERRED_STYLE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESCRIPTION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_SAMPLE_TEXT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_ID, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VERSION, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_CID_NAME, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_DESIGNER_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_MANUFACTURER, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_VENDOR_URL, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_COPYRIGHT, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_TRADEMARK, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE, 'en'); $font->getFontName(Zend_Pdf_Font::NAME_LICENSE_URL, 'en'); $type = $font->getFontType(); $lineGap = $font->getLineGap(); $lineHeight = $font->getLineHeight(); $this->assertTrue($font->getResource() instanceof Zend_Pdf_Element_Object); $font->getStrikePosition(); $font->getStrikeThickness(); $font->getUnderlinePosition(); $font->getUnitsPerEm(); $font->widthForGlyph(10); } $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
/** * Generates and saves the instructions pdf with shoplogo and returnid. * * @param $orderId * @param $returnId * @return string */ public function generateInstructionsPdf($orderId, $returnId) { $returnlabel = Mage::getModel('dpd/returnlabels')->load($returnId); $pdf = Zend_Pdf::load(Mage::getBaseDir('skin') . DS . 'adminhtml' . DS . 'default' . DS . 'default' . DS . 'dpd' . DS . 'returnlabel' . DS . 'instructions.pdf'); $font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA_BOLD); $page = $pdf->pages[0]; $page->setFont($font, 15); if (Mage::getStoreConfig('design/email/logo') && strpos(Mage::getStoreConfig('design/email/logo'), '.gif') === false && Mage::getVersion() >= "1.7") { $uploadDir = Mage_Adminhtml_Model_System_Config_Backend_Email_Logo::UPLOAD_DIR; $fullFileName = Mage::getBaseDir('media') . DS . $uploadDir . DS . Mage::getStoreConfig('design/email/logo'); $image = Zend_Pdf_Image::imageWithPath($fullFileName); $imgWidthPts = $image->getPixelWidth() * 72 / 96; $imgHeightPts = $image->getPixelHeight() * 72 / 96; $x1 = 50; $y1 = 687; $page->drawImage($image, $x1, $y1, $x1 + $imgWidthPts, $y1 + $imgHeightPts); } elseif (Mage::getVersion() < "1.7") { try { $fullFileName = Mage::getBaseDir('skin') . DS . 'frontend' . DS . 'default' . DS . 'default' . DS . Mage::getStoreConfig('design/header/logo_src'); $image = Zend_Pdf_Image::imageWithPath($fullFileName); $imgWidthPts = $image->getPixelWidth() * 72 / 96; $imgHeightPts = $image->getPixelHeight() * 72 / 96; $x1 = 50; $y1 = 687; $page->drawImage($image, $x1, $y1, $x1 + $imgWidthPts, $y1 + $imgHeightPts); } catch (Exception $e) { Mage::helper('dpd')->log('Instructions PDF: No logo found or incorrect file format', Zend_Log::INFO); } } else { Mage::helper('dpd')->log('Instructions PDF: No logo found or incorrect file format', Zend_Log::INFO); } $page->drawText(implode(' ', str_split($returnlabel->getLabelNumber(), 4)), '321', '215'); $order = Mage::getResourceModel('sales/order_collection')->addAttributeToSelect('increment_id')->addAttributeToFilter('entity_id', array('eq' => $orderId))->getFirstItem(); Mage::helper('dpd')->generatePdfAndSave($pdf->render(), 'returnlabel', $order->getIncrementId() . '-' . $returnlabel->getLabelNumber() . "-instructions"); }
/** * This is the default 'index' action that is invoked * when an action is not explicitly requested by users. */ public function actionZendPdf() { set_include_path( '/home/asaap/src/protected/extensions/' ); require_once 'Zend/Pdf.php'; require_once 'Zend/Pdf/Style.php'; require_once 'Zend/Pdf/Color/Cmyk.php'; require_once 'Zend/Pdf/Color/Html.php'; require_once 'Zend/Pdf/Color/GrayScale.php'; require_once 'Zend/Pdf/Color/Rgb.php'; require_once 'Zend/Pdf/Page.php'; require_once 'Zend/Pdf/Font.php'; //$argv[1]='/home/asaap/src/protected/data/Pdf/test.pdf'; $argv[1]='/home/asaap/src/protected/data/Pdf/document1.pdf'; $argv[2]='/home/asaap/src/protected/data/Pdf/test_new.pdf'; if (!isset($argv[1])) { echo "USAGE: php demo.php <pdf_file> [<output_pdf_file>]\n"; exit; } try { $pdf = Zend_Pdf::load($argv[1]); } catch (Zend_Pdf_Exception $e) { if ($e->getMessage() == 'Can not open \'' . $argv[1] . '\' file for reading.') { // Create new PDF if file doesn't exist $pdf = new Zend_Pdf(); if (!isset($argv[2])) { // force complete file rewriting (instead of updating) $argv[2] = $argv[1]; } } else { // Throw an exception if it's not the "Can't open file" exception throw $e; } } //$pdf->pages = array_reverse($pdf->pages); // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = ($page1 = $pdf->newPage('A4')); //saving here $pdf->save($argv[2]); // $pdf->save($argv[1], true /* update */); }
public function testFontExtracting() { if (PHP_OS == 'AIX') { $this->markTestSkipped('Not supported on AIX'); } $pdf = new Zend_Pdf(); $fontsList = array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC); foreach ($fontsList as $fontName) { // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); $font = Zend_Pdf_Font::fontWithName($fontName); $page->setFont($font, 10)->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en') . ':', 100, 400); $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360); $type = $font->getFontType(); } $TTFFontsList = array('VeraBd.ttf', 'VeraBI.ttf', 'VeraIt.ttf', 'VeraMoBd.ttf', 'VeraMoBI.ttf', 'VeraMoIt.ttf', 'VeraMono.ttf', 'VeraSeBd.ttf', 'VeraSe.ttf', 'Vera.ttf'); foreach ($TTFFontsList as $fontName) { // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4_LANDSCAPE); $font = Zend_Pdf_Font::fontWithPath(dirname(__FILE__) . '/_fonts/' . $fontName); $page->setFont($font, 10)->drawText($font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'CP1252') . ':', 100, 400); $page->setFont($font, 20)->drawText("'The quick brown fox jumps over the lazy dog'", 100, 360); $type = $font->getFontType(); } $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $newPages = array(); $fontList = array(); $fontNames = array(); foreach ($pdf1->pages as $page) { $pageFonts = $page->extractFonts(); foreach ($pageFonts as $font) { $fontList[] = $font; $fontNames[] = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8'); } } $this->assertEquals(array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames); $pdf1->pages[] = $page = $pdf1->newPage(Zend_Pdf_Page::SIZE_A4); $yPosition = 700; foreach ($fontList as $font) { $page->setFont($font, 15)->drawText("The quick brown fox jumps over the lazy dog", 100, $yPosition); $yPosition -= 30; } $fontNames1 = array(); foreach ($pdf1->extractFonts() as $font) { $fontNames1[] = $font->getFontName(Zend_Pdf_Font::NAME_POSTSCRIPT, 'en', 'UTF-8'); } $this->assertEquals(array(Zend_Pdf_Font::FONT_COURIER, Zend_Pdf_Font::FONT_HELVETICA_BOLD, Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC, 'BitstreamVeraSans-Bold', 'BitstreamVeraSans-BoldOblique', 'BitstreamVeraSans-Oblique', 'BitstreamVeraSansMono-Bold', 'BitstreamVeraSansMono-BoldOb', 'BitstreamVeraSansMono-Oblique', 'BitstreamVeraSansMono-Roman', 'BitstreamVeraSerif-Bold', 'BitstreamVeraSerif-Roman', 'BitstreamVeraSans-Roman'), $fontNames1); $page = reset($pdf1->pages); $font = $page->extractFont(Zend_Pdf_Font::FONT_COURIER); $this->assertTrue($font instanceof Zend_Pdf_Resource_Font_Extracted); $font = $page->extractFont(Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC); $this->assertNull($font); $font = $pdf1->extractFont(Zend_Pdf_Font::FONT_TIMES_BOLD_ITALIC); $this->assertTrue($font instanceof Zend_Pdf_Resource_Font_Extracted); $font = $pdf1->extractFont(Zend_Pdf_Font::FONT_TIMES_ROMAN); $this->assertNull($font); $pdf1->save(dirname(__FILE__) . '/_files/output1.pdf'); unset($pdf1); $pdf2 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output1.pdf'); $this->assertTrue($pdf2 instanceof Zend_Pdf); unset($pdf2); unlink(dirname(__FILE__) . '/_files/output.pdf'); unlink(dirname(__FILE__) . '/_files/output1.pdf'); }
$author = $_POST['author']; $issue = $_POST['issue']; // 1. Init $now = time(); $timestamp = strtoupper(date('Y M d g:i A', $now)); $name1 = $display_name; $deck = $author; $body = $_SERVER['REMOTE_ADDR']; $notes = $source_name; $created = $modified = date('Y-m-d H:i:s', $now); // 2. Write database record $sql = "INSERT INTO\n\t\t\tdownloads\n\t\t\t(\n\t\t\t\tname1,\n\t\t\t\tdeck,\n\t\t\t\tbody,\n\t\t\t\tcreated,\n\t\t\t\tmodified,\n\t\t\t\tnotes\n\t\t\t)\n\t\tVALUES\n\t\t(\n\t\t\t'{$name1}',\n\t\t\t'{$deck}',\n\t\t\t'{$body}',\n\t\t\t'{$created}',\n\t\t\t'{$created}',\n\t\t\t'{$notes}'\n\t\t)"; $db->query($sql); // 3. Load PDF (Zend_PDF) $source_filename = $media_root . $source_name . ".pdf"; $pdf = Zend_Pdf::load($source_filename); // 4. Set metadata (Zend_PDF) $pdf->properties['Title'] = $display_name; $pdf->properties['Author'] = $author; $gmt_offset = explode(":", date("P", $now)); $pdf->properties["ModDate"] = "D:" . date("YmdHis", $now) . $gmt_offset[0] . "'" . $gmt_offset[1] . "'"; // 5. Time stamp pages (Zend_PDF) $black = new Zend_Pdf_Color_Html('#000000'); $blue = new Zend_Pdf_Color_Html('#0000FF'); $white = new Zend_Pdf_Color_Html('#FFFFFF'); $stamp = "BoTSL#" . $issue . " " . $timestamp; $bulletin_style = new Zend_Pdf_Style(); $bulletin_style->setFillColor($white); $bulletin_style->setLineColor($white); $bulletin_style->setFont(Zend_Pdf_Font::fontWithPath($font_path), $font_size); if ($smallformat == true) {
/** * Finish currently generating book * Add product indexes pages * * @var int $page Current page */ public function finishbookAction() { if (!Zend_Auth::getInstance()->hasIdentity()) { throw new Zend_Exception("Page not found", 404); } $this->_helper->layout->disableLayout(); $page = $this->getRequest()->getParam("page"); $startPage = $this->getRequest()->getParam("startPage"); $pageFormat = $this->getRequest()->getParam("pageFormat"); $print = $this->getRequest()->getParam("print"); $pdfBook = new Model_Static_PdfBook($pageFormat, $print); //если формат А4 то мы добавляем дополнительные файлы в конечный архив и также рендерим страници " наше предложение" с нужной номерацией if ($pageFormat == "A4") { $bookOurProduction = $pdfBook->generateOurProduction($page, $print); $page += 2; $saveFilenameOurProduction = "ourProduction.pdf"; $bookOurProduction->save(APPLICATION_ROOT . $this::PDFBOOK_DIR . '/' . $saveFilenameOurProduction); $dir = APPLICATION_ROOT . $this::PDFCOVER_DIR; $files = scandir($dir); //перебераем все файлы которые числяться как добавочные и добавляем их в архив foreach ($files as $file) { if (is_dir($file)) { continue; } $front = Zend_Pdf::load(APPLICATION_ROOT . $this::PDFCOVER_DIR . '/' . $file); $front->save(APPLICATION_ROOT . $this::PDFBOOK_DIR . '/' . $file); } } $book = $pdfBook->IndexPages($page); $this->view->nextpage = $page + count($book->pages); $saveFilename = str_repeat("0", 4 - strlen($page)) . $page . '-' . $this->view->nextpage . '.pdf'; $book->save(APPLICATION_ROOT . $this::PDFBOOK_DIR . '/' . $saveFilename); if ($this->secondTime == 0) { $this->generateContents($startPage, $pageFormat, $print); } $this->view->page = $this->contentPages + $startPage; $this->zipResults(); }
public function testFontDrawing() { $pdf = new Zend_Pdf(); // Add new page generated by Zend_Pdf object (page is attached to the specified the document) $pdf->pages[] = $page = $pdf->newPage('A4'); $stampImagePNG = Zend_Pdf_Image::imageWithPath(dirname(__FILE__) . '/_files/stamp.png'); $this->assertTrue($stampImagePNG instanceof Zend_Pdf_Resource_Image); $page->saveGS(); $page->clipCircle(250, 500, 50); $page->drawImage($stampImagePNG, 200, 450, 300, 550); $page->restoreGS(); $stampImageTIFF = Zend_Pdf_Image::imageWithPath(dirname(__FILE__) . '/_files/stamp.tif'); $this->assertTrue($stampImageTIFF instanceof Zend_Pdf_Resource_Image); $page->saveGS(); $page->clipCircle(325, 500, 50); $page->drawImage($stampImagePNG, 275, 450, 375, 550); $page->restoreGS(); if (function_exists('gd_info') && array_key_exists('JPG Support', gd_info())) { $stampImageJPG = Zend_Pdf_Image::imageWithPath(dirname(__FILE__) . '/_files/stamp.jpg'); $this->assertTrue($stampImageJPG instanceof Zend_Pdf_Resource_Image); $page->saveGS(); $page->clipCircle(287.5, 440, 50); $page->drawImage($stampImageJPG, 237.5, 390, 337.5, 490); $page->restoreGS(); $page->saveGS(); $page->clipCircle(250, 500, 50); $page->clipCircle(287.5, 440, 50); $page->drawImage($stampImagePNG, 200, 450, 300, 550); $page->restoreGS(); } $pdf->save(dirname(__FILE__) . '/_files/output.pdf'); unset($pdf); $pdf1 = Zend_Pdf::load(dirname(__FILE__) . '/_files/output.pdf'); $this->assertTrue($pdf1 instanceof Zend_Pdf); unset($pdf1); unlink(dirname(__FILE__) . '/_files/output.pdf'); }
/** * Object constructor * * @param string $fileName * @param boolean $storeContent * @param string $fileEncoding * @param string $internalEncoding * @throws Zend_Search_Lucene_Exception */ private function __construct($fileName, $storeContent, $fileEncoding = null, $internalEncoding = null) { if (!is_null($fileEncoding)) { $this->_fileEncoding = $fileEncoding; } if (!is_null($internalEncoding)) { $this->_internalEncoding = $internalEncoding; } // Load the PDF document. $pdf = Zend_Pdf::load($fileName); // Data holders $coreProperties = array('Key' => md5_file($fileName)); // Go through each meta data item and add to meta data properties foreach ($pdf->properties as $meta => $metaValue) { switch ($meta) { case 'Title': if (trim($pdf->properties['Title']) != '') { $coreProperties['title'] = $pdf->properties['Title']; } break; case 'Subject': if (trim($pdf->properties['Subject']) != '') { $coreProperties['subject'] = $pdf->properties['Subject']; } break; case 'Author': if (trim($pdf->properties['Author']) != '') { $coreProperties['author'] = $pdf->properties['Author']; } break; case 'Keywords': if (trim($pdf->properties['Keywords']) != '') { $coreProperties['keywords'] = $pdf->properties['Keywords']; } break; case 'CreationDate': $dateCreated = $pdf->properties['CreationDate']; $distance = substr($dateCreated, 16, 2); if (!is_long($distance)) { $distance = null; } // Convert date from the PDF format of D:20090731160351+01'00' // @todo this should probably be a function in Zend_PDF to convert from this format $dateCreated = mktime(substr($dateCreated, 10, 2), substr($dateCreated, 12, 2), substr($dateCreated, 14, 2), substr($dateCreated, 6, 2), substr($dateCreated, 8, 2), substr($dateCreated, 2, 4), $distance); //distance $coreProperties['CreationDate'] = date('Ymd', $dateCreated); break; case 'Date': $coreProperties['date'] = $pdf->properties['Date']; break; } } // Read core properties $documentBody = $this->pdf2txt($pdf->render()); // Store filename $this->addField(Zend_Search_Lucene_Field::Text('filename', basename($fileName), $this->_internalEncoding)); // Store contents if ($storeContent) { $this->addField(Zend_Search_Lucene_Field::Text('body', $documentBody, $this->_internalEncoding)); } else { $this->addField(Zend_Search_Lucene_Field::UnStored('body', $documentBody, $this->_internalEncoding)); } // Store meta data properties foreach ($coreProperties as $key => $value) { if ($value) { $this->addField(Zend_Search_Lucene_Field::Text($key, $value, $this->_internalEncoding)); } } // Store title (if not present in meta data) if (!isset($coreProperties['title'])) { $this->addField(Zend_Search_Lucene_Field::Text('title', basename($fileName), $this->_internalEncoding)); } }
public function testSetAndSaveLoadAndResetAndSaveLoadAndGetJavaScript() { $tempFile = tempnam(sys_get_temp_dir(), 'PdfUnitFile'); $javaScript = array('print();', 'alert();'); $pdf = new Zend_Pdf(); $pdf->setJavaScript($javaScript); $pdf->save($tempFile); unset($pdf); $pdf = Zend_Pdf::load($tempFile); unlink($tempFile); $pdf->resetJavaScript(); $pdf->save($tempFile); unset($pdf); $pdf = Zend_Pdf::load($tempFile); unlink($tempFile); $this->assertNull($pdf->getJavaScript()); }