setOptions() public method

Set global option(s)
public setOptions ( array $options = [] ) : static
$options array list of global PDF options to set as name/value pairs
return static the Pdf instance for method chaining
Ejemplo n.º 1
1
 /**
  * Settings of document and WkHtmlToPdf.
  *
  * @param array $options
  * @link https://github.com/mikehaertl/phpwkhtmltopdf
  * @link http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
  */
 public function setOptions(array $options)
 {
     $wkhtmltopdf_global = array('page-size' => 'a4', 'margin-top' => 20, 'margin-bottom' => 20, 'margin-left' => 12, 'margin-right' => 12, 'header-spacing' => 6, 'footer-spacing' => 6);
     $wkhtmltopdf_page = array('header-line', 'footer-line', 'header-left' => '[title]', 'header-right' => '[section]', 'footer-center' => '[page]/[topage]');
     $wkhtmltopdf_cover = array('no-header-line', 'no-footer-line', 'header-left' => '', 'header-right' => '', 'footer-center' => '');
     $wkhtmltopdf_toc = array();
     $resolver = new OptionsResolver();
     $resolver->setRequired(array('dummy_pdf_url', 'display_url', 'download_url', 'remote_url', 'pluginDetect_PDFReader_url', 'waiting_view_path', 'queue_db_path'));
     $resolver->setDefaults(array('wkhtmltopdf_global' => array(), 'wkhtmltopdf_page' => array(), 'wkhtmltopdf_cover' => array(), 'wkhtmltopdf_toc' => array()));
     $resolver->setAllowedTypes('wkhtmltopdf_global', 'array');
     $resolver->setAllowedTypes('wkhtmltopdf_page', 'array');
     $resolver->setAllowedTypes('wkhtmltopdf_cover', 'array');
     $resolver->setAllowedTypes('wkhtmltopdf_toc', 'array');
     $resolver->setAllowedTypes('dummy_pdf_url', 'string');
     $resolver->setAllowedTypes('display_url', 'string');
     $resolver->setAllowedTypes('download_url', 'string');
     $resolver->setAllowedTypes('remote_url', 'string');
     // http://www.pinlady.net/PluginDetect/PDFReader/
     $resolver->setAllowedTypes('pluginDetect_PDFReader_url', 'string');
     $resolver->setAllowedTypes('waiting_view_path', 'string');
     $resolver->setNormalizer('wkhtmltopdf_global', function (Options $options, $value) use($wkhtmltopdf_global) {
         return array_merge($wkhtmltopdf_global, $value);
     });
     $resolver->setNormalizer('wkhtmltopdf_page', function (Options $options, $value) use($wkhtmltopdf_page) {
         return array_merge($wkhtmltopdf_page, $value);
     });
     $resolver->setNormalizer('wkhtmltopdf_cover', function (Options $options, $value) use($wkhtmltopdf_cover) {
         return array_merge($wkhtmltopdf_cover, $value);
     });
     $resolver->setNormalizer('wkhtmltopdf_toc', function (Options $options, $value) use($wkhtmltopdf_toc) {
         return array_merge($wkhtmltopdf_toc, $value);
     });
     $resolver->setNormalizer('waiting_view_path', function (Options $options, $value) {
         if (!file_exists($value)) {
             throw new \UnexpectedValueException('Error during parse waiting_view_path: File not found.');
         }
         $info = pathinfo($value);
         if ($info['extension'] != 'html') {
             throw new \UnexpectedValueException('Error during parse waiting_view_path: Unexpected file extension - ' . $info['extension']);
         }
         return $value;
     });
     $this->options = $resolver->resolve($options);
     $this->wkhtmltopdf->setOptions($this->options['wkhtmltopdf_global']);
     // kolejka żądań utworzenia pliku
     $this->queue = QueuePdfDb::openFile($this->options['queue_db_path']);
 }
Ejemplo n.º 2
-1
 public function testCanSetGlobalOptions()
 {
     $inFile = $this->getHtmlAsset();
     $outFile = $this->getOutFile();
     $binary = $this->getBinary();
     $pdf = new Pdf();
     $pdf->setOptions(array('binary' => $binary, 'no-outline', 'margin-top' => 0));
     $this->assertInstanceOf('mikehaertl\\wkhtmlto\\Pdf', $pdf->addPage($inFile));
     $this->assertTrue($pdf->saveAs($outFile));
     $this->assertFileExists($outFile);
     $tmpFile = $pdf->getPdfFilename();
     $this->assertEquals("{$binary} --no-outline --margin-top '0' '{$inFile}' '{$tmpFile}'", (string) $pdf->getCommand());
     unlink($outFile);
 }