/** * keep compatible with the Zend_Pdf way of doing things * collect input for later processing with render() * * @param array $input array of items to print * @param array $orderIds array of order ids * * @return Fooman_PdfCustomiser_Model_Abstract | Zend_Pdf */ public function getPdf($input = array(), $orderIds = null) { if (self::COMPAT_MODE) { try { $newPdf = new Zend_Pdf(); $extractor = new Zend_Pdf_Resource_Extractor(); if (!empty($orderIds)) { $origPdf = $this->renderPdf(null, $orderIds, null, true); } else { $origPdf = $this->renderPdf($input, $orderIds, null, true); } if ($origPdf->getPdfAnyOutput()) { $pdfString = $origPdf->Output('output.pdf', 'S'); $tcpdf = Zend_Pdf::parse($pdfString); foreach ($tcpdf->pages as $p) { $newPdf->pages[] = $extractor->clonePage($p); } } return $newPdf; } catch (Exception $e) { Mage::logException($e); } } else { $this->pages[] = array('instance' => $this, 'objectArray' => $input, 'orderIds' => $orderIds); return $this; } }
/** * test to combine Zend_Pdf content with tcpdf pdfs * * @param $observer */ public function adjustPdf($observer) { $extractor = new Zend_Pdf_Resource_Extractor(); $pdf = $observer->getEvent()->getPdf(); $counter = false; foreach ($pdf->pages as $key => &$page) { if ($page instanceof Fooman_PdfCustomiser_Model_Abstract) { $counter = 1; $instance = $page; $firstKey = $key; unset($pdf->pages[$key]); } elseif ($counter == 1) { $objectArray = $page; $counter++; unset($pdf->pages[$key]); } elseif ($counter == 2) { $orderIds = $page; $tcpdf = Zend_Pdf::parse($instance->renderPdf($objectArray, $orderIds, null, true)); foreach ($tcpdf->pages as $p) { $pdf->pages[$firstKey] = $extractor->clonePage($p); } $counter = 0; } } }
/** * Object constructor * * @param string $data * @param boolean $storeContent */ private function __construct($data, $storeContent) { try { $zendpdf = \Zend_Pdf::parse($data); // Store meta data properties if (isset($zendpdf->properties['Title'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title'])); } if (isset($zendpdf->properties['Author'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author'])); } if (isset($zendpdf->properties['Subject'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject'])); } if (isset($zendpdf->properties['Keywords'])) { $this->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords'])); } //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata() //do the content extraction $pdfParse = new \App_Search_Helper_PdfParser(); $body = $pdfParse->pdf2txt($zendpdf->render()); if ($body != '') { // Store contents if ($storeContent) { $this->addField(\Zend_Search_Lucene_Field::Text('body', $body, 'UTF-8')); } else { $this->addField(\Zend_Search_Lucene_Field::UnStored('body', $body, 'UTF-8')); } } } catch (\Exception $e) { Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR); } }
/** * Combine array of labels as instance PDF * * @param array $labelsContent * @return \Zend_Pdf */ public function combineLabelsPdf(array $labelsContent) { $outputPdf = new \Zend_Pdf(); foreach ($labelsContent as $content) { if (stripos($content, '%PDF-') !== false) { $pdfLabel = \Zend_Pdf::parse($content); foreach ($pdfLabel->pages as $page) { $outputPdf->pages[] = clone $page; } } else { $page = $this->createPdfPageFromImageString($content); if ($page) { $outputPdf->pages[] = $page; } } } return $outputPdf; }
/** * extract the metadata from a file * * uses getid3 to extract metadata. * if possible also adds content (currently only for plain text files) * hint: use OC\Files\Filesystem::getFileInfo($path) to get metadata for the last param * * @author Jörn Dreyer <*****@*****.**> * * @param Zend_Search_Lucene_Document $doc to add the metadata to * @param string $path path of the file to extract metadata from * @param string $mimetype depending on the mimetype different extractions are performed * * @return void */ private static function extractMetadata(\Zend_Search_Lucene_Document $doc, $path, \OC\Files\View $view, $mimetype) { $file = $view->getLocalFile($path); if (is_dir($file)) { // Don't lose time analizing a directory for file-specific metadata return; } $getID3 = new \getID3(); $getID3->encoding = 'UTF-8'; $data = $getID3->analyze($file); // TODO index meta information from media files? //show me what you got /*foreach ($data as $key => $value) { Util::writeLog('search_lucene', 'getid3 extracted '.$key.': '.$value, Util::DEBUG); if (is_array($value)) { foreach ($value as $k => $v) { Util::writeLog('search_lucene', ' ' . $value .'-' .$k.': '.$v, Util::DEBUG); } } }*/ if ('application/pdf' === $mimetype) { try { $zendpdf = \Zend_Pdf::parse($view->file_get_contents($path)); //we currently only display the filename, so we only index metadata here if (isset($zendpdf->properties['Title'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('title', $zendpdf->properties['Title'])); } if (isset($zendpdf->properties['Author'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('author', $zendpdf->properties['Author'])); } if (isset($zendpdf->properties['Subject'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('subject', $zendpdf->properties['Subject'])); } if (isset($zendpdf->properties['Keywords'])) { $doc->addField(\Zend_Search_Lucene_Field::UnStored('keywords', $zendpdf->properties['Keywords'])); } //TODO handle PDF 1.6 metadata Zend_Pdf::getMetadata() //do the content extraction $pdfParse = new \App_Search_Helper_PdfParser(); $body = $pdfParse->pdf2txt($zendpdf->render()); } catch (Exception $e) { Util::writeLog('search_lucene', $e->getMessage() . ' Trace:\\n' . $e->getTraceAsString(), Util::ERROR); } } if ($body != '') { $doc->addField(\Zend_Search_Lucene_Field::UnStored('body', $body)); } if (isset($data['error'])) { Util::writeLog('search_lucene', 'failed to extract meta information for ' . $view->getAbsolutePath($path) . ': ' . $data['error']['0'], Util::WARN); return; } }
public function unipdfimport() { $s3Accesskey = Mage::getStoreConfig('imagecdn/amazons3/access_key_id'); $s3Secretkey = Mage::getStoreConfig('imagecdn/amazons3/secret_access_key'); // AWS access info if (!defined('awsAccessKey')) { define('awsAccessKey', $s3Accesskey); } if (!defined('awsSecretKey')) { define('awsSecretKey', $s3Secretkey); } // Check for CURL if (!extension_loaded('curl') && !@dl(PHP_SHLIB_SUFFIX == 'so' ? 'curl.so' : 'php_curl.dll')) { exit("\nERROR: CURL extension not loaded\n\n"); } $resource = Mage::getSingleton('core/resource'); $readConnection = $resource->getConnection('core_read'); $writeConnection = $resource->getConnection('core_write'); $query = 'SELECT * FROM `unicom_invoice` WHERE pdf_complete = "No"'; $orders = $readConnection->fetchAll($query); foreach ($orders as $order) { if ($order['ship_code']) { $del = 'DEL'; $locpos = strpos($order['ship_code'], $del); if ($locpos === false) { $username = '******'; $password = '******'; } else { $username = '******'; $password = '******'; } $cookie = '/tmp/curl-session'; $postdata = "j_username="******"&j_password="******"{$username}:{$password}"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); /*$agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt ($ch, CURLOPT_USERAGENT, $agent);*/ $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); if ($output) { $pdf = new Zend_Pdf(); $pdf = Zend_Pdf::parse($output); $fs_path = Mage::getBaseDir() . '/media/sales/order/pdf/' . $order['ship_code'] . '.pdf'; $pdf->save($fs_path); $uploadFile = $fs_path; // File to upload, we'll use the S3 class since it exists $bucketName = 'zoffio.invoices'; // Temporary bucket $morders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('increment_id', $order['order_id']); foreach ($morders as $morder) { $orderDate = $morder->getCreatedAt(); } $year = date('Y', strtotime($orderDate)); $month = date('m', strtotime($orderDate)); $day = date('d', strtotime($orderDate)); $pdfFile = $year . "/" . $month . "/" . $day . "/" . baseName($uploadFile); // Put our file (also with public read access) $s3->putObjectFile($uploadFile, $bucketName, $pdfFile, S3::ACL_PUBLIC_READ); unlink($uploadFile); if ($order['state_complete'] == 'Yes') { $insertquery = "UPDATE `unicom_invoice` SET pdf_complete = 'Yes' WHERE ship_code = '" . $order['ship_code'] . "'"; $writeConnection->query($insertquery); } } } } }
/** * Retrieve document in specified format * * @param string $format * * @throws Tis_Service_LiveDocx_Exception * @return binary */ public function retrieveDocument($format) { $ret = null; $format = strtolower($format); try { $result = $this->liveDocx->RetrieveDocument(array('format' => $format)); } catch (Exception $e) { self::throwException($e, 'Cannot retrieve document - call setLocalTemplate() or setRemoteTemplate() first'); } $ret = base64_decode($result->RetrieveDocumentResult); if ('pdf' === $format) { $pdf = Zend_Pdf::parse($ret); $pdf->properties = $this->getDocumentProperties(); $ret = $pdf->render(); } return $ret; }
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $loginUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); /*$agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt ($ch, CURLOPT_USERAGENT, $agent);*/ $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); if ($output) { $pdf = new Zend_Pdf(); $pdf = Zend_Pdf::parse($output); $fs_path = Mage::getBaseDir() . '/media/sales/order/pdf/' . $order['ship_code'] . '.pdf'; $pdf->save($fs_path); $uploadFile = $fs_path; // File to upload, we'll use the S3 class since it exists $bucketName = 'zoffio.invoices'; // Temporary bucket $morders = Mage::getModel('sales/order')->getCollection()->addAttributeToFilter('increment_id', $order['order_id']); foreach ($morders as $morder) { $orderDate = $morder->getCreatedAt(); } $year = date('Y', strtotime($orderDate)); $month = date('m', strtotime($orderDate)); $day = date('d', strtotime($orderDate)); $pdfFile = $year . "/" . $month . "/" . $day . "/" . baseName($uploadFile); // Put our file (also with public read access)
public function getPdf($invoices = array()) { foreach ($invoices as $invoice) { if ($invoice->getOrder()->getPayment()->getMethod() != 'sofortrechnung') { return parent::getPdf($invoices); } break; } $this->_beforeGetPdf(); $this->_initRenderer('invoice'); $pdf = new Zend_Pdf(); $this->_setPdf($pdf); $style = new Zend_Pdf_Style(); $this->_setFontBold($style, 10); foreach ($invoices as $invoice) { if ($invoice->getStoreId()) { Mage::app()->getLocale()->emulate($invoice->getStoreId()); Mage::app()->setCurrentStore($invoice->getStoreId()); } $page = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $pdf->pages[] = $page; $order = $invoice->getOrder(); $tid = $order->getPayment()->getPnSuTransactionId(); if (!empty($tid)) { $sObj = new SofortLib_TransactionData(Mage::getStoreConfig('payment/sofort/configkey')); $sObj->setTransaction($tid)->sendRequest(); if ($sObj->isError()) { Mage::throwException(Mage::helper('sales')->__($sObj->getError())); return; } else { $url = $sObj->getInvoiceUrl(); $pdf = file_get_contents($url); return Zend_Pdf::parse($pdf); } } /* Add image */ $this->insertLogo($page, $invoice->getStore()); /* Add address */ $this->insertAddress($page, $invoice->getStore()); /* Add head */ $this->insertOrder($page, $order, Mage::getStoreConfigFlag(self::XML_PATH_SALES_PDF_INVOICE_PUT_ORDER_ID, $order->getStoreId())); $page->setFillColor(new Zend_Pdf_Color_GrayScale(1)); $this->_setFontRegular($page); $page->drawText(Mage::helper('sales')->__('Invoice # ') . $invoice->getIncrementId(), 35, 780, 'UTF-8'); /* Add table */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.93, 0.92, 0.92)); $page->setLineColor(new Zend_Pdf_Color_GrayScale(0.5)); $page->setLineWidth(0.5); $page->drawRectangle(25, $this->y, 570, $this->y - 15); $this->y -= 10; /* Add table head */ $page->setFillColor(new Zend_Pdf_Color_RGB(0.4, 0.4, 0.4)); $page->drawText(Mage::helper('sales')->__('Products'), 35, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('SKU'), 255, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Price'), 380, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Qty'), 430, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Tax'), 480, $this->y, 'UTF-8'); $page->drawText(Mage::helper('sales')->__('Subtotal'), 535, $this->y, 'UTF-8'); $this->y -= 15; $page->setFillColor(new Zend_Pdf_Color_GrayScale(0)); /* Add body */ foreach ($invoice->getAllItems() as $item) { if ($item->getOrderItem()->getParentItem()) { continue; } if ($this->y < 15) { $page = $this->newPage(array('table_header' => true)); } /* Draw item */ $page = $this->_drawItem($item, $page, $order); } /* Add totals */ $page = $this->insertTotals($page, $invoice); if ($invoice->getStoreId()) { Mage::app()->getLocale()->revert(); } } $this->_afterGetPdf(); return $pdf; }
/** * Extract selected pages from PDF files using Zend_Pdf library. * @param object $pdfparts * @param object $file * @return string extracted pages in one PDF file (suitable for direct output to browser or saveing to disk) */ function pdfparse_pdf_zend_extract($pdfparts, $file) { global $CFG; try { require_once "{$CFG->dirroot}/mod/pdfparts/Zend/Pdf.php"; // load PDF document from file contents $pdf = Zend_Pdf::parse(trim($file->get_content())); $pdfpagecount = count($pdf->pages); // parse page range $pagerange = pdfparts_parse_page_range($pdfparts, $pdfpagecount); // new PDF for output $outpdf = new Zend_Pdf(); // new PDF page extractor $extractor = new Zend_Pdf_Resource_Extractor(); // good example: http://framework.zend.com/manual/1.12/en/zend.pdf.pages.html#zend.pdf.pages.cloning foreach ($pagerange as $value) { if (is_int($value)) { $outpdf->pages[] = $extractor->clonePage($pdf->pages[$value - 1]); } elseif (is_array($value)) { for ($k = $value[0]; $k <= $value[1]; $k++) { $outpdf->pages[] = $extractor->clonePage($pdf->pages[$k - 1]); } } } // get PDF document as a string $pdfdata = $outpdf->render(); return $pdfdata; } catch (Zend_Pdf_Exception $e) { print_error("Could not process the PDF file aosciated with this instance of the PDFParts module."); } catch (Exception $e) { print_error("Unknown error while processing the PDF file aosciated with this instance of the PDFParts module."); return null; } }
public function unipdfimport() { $username = '******'; $password = '******'; $cookie = '/tmp/curl-session'; $postdata = "j_username="******"&j_password="******"complete","canceled","pending")'; $query = 'SELECT * FROM `unicom_invoice` WHERE pdf_complete = "No"'; $orders = $readConnection->fetchAll($query); foreach ($orders as $order) { if ($order['ship_code']) { $loginUrl = 'https://zoffio.unicommerce.com/oms/invoice/show/' . $order['ship_code']; /*$ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $loginUrl); curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, true); $agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt ($ch, CURLOPT_USERAGENT, $agent); curl_setopt ($ch, CURLOPT_TIMEOUT, 60); curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata); $result = curl_exec ($ch); curl_close($ch); */ $output = ''; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $loginUrl); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_USERPWD, "{$username}:{$password}"); curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie); curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie); curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata); /*$agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt ($ch, CURLOPT_USERAGENT, $agent);*/ $output = curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); if ($output) { $pdf = new Zend_Pdf(); $pdf = Zend_Pdf::parse($output); $pdf->save(Mage::getBaseDir() . '/media/sales/order/pdf/' . $order['ship_code'] . '.pdf'); if ($order['state_complete'] == 'Yes') { $insertquery = "UPDATE `unicom_invoice` SET pdf_complete = 'Yes' WHERE ship_code = '" . $order['ship_code'] . "'"; $writeConnection->query($insertquery); } } } } }