Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Printing with Puphpeteer

Printing with Puphpeteer

Talk at Virtual StripeCon Europe 2020

Andy Adiwidjaja

September 23, 2020
Tweet

More Decks by Andy Adiwidjaja

Other Decks in Technology

Transcript

  1. Web2Print Solutions - FPdf - MPdf - Reportlab (Python) -

    XHTML2Pdf (Python) - XML 2 Indesign - Wkhtmltopdf - Puppeteer Commercial: - PDFReactor - PrinceXML - Antennahouse https://www.print-css.rocks/
  2. Puppeteer Headless Chrome Node.js API - maintained by Chrome DevTools

    team - originally for test automation - Ability to save Screenshots and PDFs Current Chromium. Flexbox! Grid! Not: Complete CSS paged media standard https://github.com/puppeteer/puppeteer
  3. nesk/puphpeteer Puppeteer bridge for PHP, based on nesk/rialto Needs nodejs,

    needs PHP exec permissions composer require nesk/puphpeteer npm install @nesk/puphpeteer
  4. Simple example use Nesk\Puphpeteer\Puppeteer; $puppeteer = new Puppeteer(); $browser =

    $puppeteer->launch(); $page = $browser->newPage(); $page->goto($pageUrl, [ "waitUntil" => "networkidle2", ]); $page->pdf([ "path" => $path, "printBackground" => true, "format" => "A4", ]); $browser->close();
  5. HTML / CSS: - Inline SVG Icons - Flexbox styling

    - mm-based sizes & positions - Page containers Process: - Self-service frontend editing - Generate PDF online - Import into InDesign - Process with PDF/X Complex example
  6. Important: Instant preview to make it fit. PDF creation is

    slow, PDF rendering in the browser is slower So: Image with URL to a Puppeteer Screenshot: $page->screenshot([ 'path' => $tmpPath ]); Customer self-service
  7. Last trick: Authenticated content // Render page content as html

    $html = $this->print($request)->forTemplate(); // First load any page to load style resources. $page->goto($pageUrl, [ "waitUntil" => "networkidle2", "timeout" => 120000 ]); // Replace with real data $page->setContent($html);
  8. Conclusion So Pros: - Full Chrome, familiar development - Easily

    integrated into PHP Cons: - Not full css paged media - CMYK requires ghostscript magic - Not fast gs -dNOSAFER -dPDFX -dBATCH -dNOPAUSE -dNOCACHE -sColorConversionStrategy=CMYK -sDEVICE=pdfwrite -dProcessColorModel=/DeviceCMYK -sOutputFile=pb-x3.pdf -dFIXEDMEDIA -dDEVICEWIDTHPOINTS=297.638 -dDEVICEHEIGHTPOINTS=612.283 -sPageList=1,2 mydef.ps flyer_pb.pdf
  9. That’s all folks! We are excited to hear from you:

    Andy Adiwidjaja Phone: +49 4102 208456 EMail: [email protected] Illustrations: Maria Müller-Leinweber https://www.mamuelei.de