iio\libmergepdf\Merger::addRaw PHP Method

addRaw() public method

Note that your PDFs are merged in the order that you add them
public addRaw ( string $pdf, iio\libmergepdf\Pages $pages = null ) : void
$pdf string
$pages iio\libmergepdf\Pages
return void
    public function addRaw($pdf, Pages $pages = null)
    {
        assert('is_string($pdf)');
        // Create temporary file
        $fname = $this->getTempFname();
        if (@file_put_contents($fname, $pdf) === false) {
            throw new Exception("Unable to create temporary file");
        }
        $this->addFromFile($fname, $pages, true);
    }

Usage Example

 /**
  * @Route("/")
  * @Template()
  */
 public function indexAction(Request $request)
 {
     $this->rebuildAction(false);
     /** @var $snappy Snappy */
     $snappy = $this->get('knp_snappy.pdf');
     $cover = $snappy->getOutput($this->getPath('cover.html'));
     $snappy->setOption('margin-top', '20');
     $snappy->setOption('margin-right', '0');
     $snappy->setOption('margin-bottom', '16');
     $snappy->setOption('margin-left', '0');
     $snappy->setOption('header-html', $this->getPath('header.html'));
     $snappy->setOption('header-spacing', '5');
     $snappy->setOption('footer-html', $this->getPath('footer.html'));
     $snappy->setOption('footer-spacing', '5');
     $snappy->setOption('xsl-style-sheet', $this->getPath('toc.xml'));
     $html = file_get_contents($this->getPath('content.html'));
     if ($request->query->get('ids')) {
         $html = $this->addFilters($html, explode(',', $request->query->get('ids')));
     }
     $contents = $snappy->getOutputFromHtml($html, array('toc' => true));
     $pdfMerger = new Merger();
     $pdfMerger->addRaw($cover, new Pages('1'));
     $pdfMerger->addRaw($contents);
     $contents = $pdfMerger->merge();
     return new Response($contents, 200, array('Content-Type' => 'application/pdf'));
 }
All Usage Examples Of iio\libmergepdf\Merger::addRaw