getParam('bootstrap'); if ($bootstrap) { $options = $bootstrap->getOptions(); } else { // just for testing :( $options = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', APPLICATION_ENV); $options = $options->toArray(); } if ($key) { return $options[$key]; } return $options; } function init() { $this->pdf_path = $this->get_config('products_pdfpath'); $this->stylesheet = file_get_contents(APPLICATION_PATH . "/data/pdf_stylesheet.xml"); $this->xml_template = file_get_contents(APPLICATION_PATH . "/data/pdf_template.xml"); $this->products = new Roth_Model_DbTable_Produkte(); //if you want to generate graphic files //PHPPdf\Autoloader::register('sciezka/do/biblioteki/lib/vendor/Imagine/lib'); $loader = new PHPPdf\Core\Configuration\LoaderImpl(); $loader->setFontFile(APPLICATION_PATH . '/data/pdf_fonts.xml'); $this->pdf_builder = PHPPdf\Core\FacadeBuilder::create($loader) ->setEngineType('pdf') // ->setDocumentParserType(PHPPdf\Core\FacadeBuilder::PARSER_MARKDOWN) // ->setEngineOptions(array( // 'format' => 'jpg', // 'quality' => 70, // 'engine' => 'imagick', // )) ->build(); } function getVersions() { $select = $this->products->select()->from('produkte', array('count(*) as counter', 'pdf_version'))->group('pdf_version'); $versions = array(); foreach ($this->products->fetchAll($select) as $row) { $versions[$row->pdf_version] = $row->counter; } return $versions; } function parse_content($content) { $patterns = array( '||', '||', '||', '||', ); $replacements = array( '', '', '', '' ); return preg_replace($patterns, $replacements, $content); } function generate_all($version, $limit = 10) { $counter = 0; $select = $this->products->select()->where("pdf_version != ?", $version)->limit($limit); foreach ($this->products->fetchAll($select) as $product) { gc_collect_cycles(); // ini_set('memory_limit', '45M'); foreach (array('de', 'en', 'es', 'fr', 'it') as $language) { $pdf = $this->generate($product, $language, $version); $filename = $this->pdf_path . '/' . $language . '_' . strtr($product['artnr'], '/', '_') . '.pdf'; file_put_contents($filename, $pdf); $counter++; // $this->warnings[] = sprintf("Zeile %s: Keine artnr!", $counter); } $product->pdf_version = $version; $product->save(); } // $product = $products->fetchRow("artnr = 'RE460'")->toArray(); return $counter; } function combine_languages($languages) { $select = $this->products->select(); // ->limit(2); $products_to_pdfs = array(); $gs = $this->get_config('path_to_ghostscript'); foreach ($this->products->fetchAll($select) as $product) { foreach ($languages as $language) { $filename = $this->pdf_path . '/' . $language . '_' . strtr($product['artnr'], '/', '_') . '.pdf'; if (file_exists($filename)) { // queue up file $key = strtr($product['artnr'], '/', '_'); if (array_key_exists($key, $products_to_pdfs)) { $products_to_pdfs[$key][] = $filename; } else { $products_to_pdfs[$key] = array($filename); } } else { $this->warnings[] = $language . '_' . strtr($product['artnr'], '/', '_') . '.pdf'; } } } if (!empty($this->warnings)) { return false; } else { $outpath = $this->get_config('products_pdf_multilang_path'); $files = glob($outpath . '/*.pdf'); if (is_array($files) && !empty($files)) { foreach($files as $file) { unlink($file); } } foreach ($products_to_pdfs as $key => $pdfs) { $pdf_files = join(' ', $pdfs); $cmd = "$gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=$outpath/$key.pdf $pdf_files"; exec($cmd, $output, $error); if ($error) { $this->warnings[] = "Konnte pdf nicht zusammenf├╝hren:"; $this->warnings[] = $cmd; $this->warnings[] = join("
", $output); return false; } } return $outpath; } } function generate($product, $language, $version) { $document = $this->xml_template; $content = $this->parse_content($product['beschreibung_' . $language]); $patterns = array( '||', '||', '||', '|{language}|', '|{image}|' ); $replacements = array( $product['artnr'], $content, $version, $language, $product['bild'] ); $document = preg_replace($patterns, $replacements, $document); $content = $this->pdf_builder->render($document, $this->stylesheet); return $content; } }