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

Printing with Puphpeteer

Printing with Puphpeteer

Talk at Virtual StripeCon Europe 2020

40bdf1149bc91ae556f61e8a552429ec?s=128

Andy Adiwidjaja

September 23, 2020
Tweet

Transcript

  1. Printing with Puphpeteer Andy Adiwidjaja Virtual StripeCon Europe, 23.09.2020

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

    XHTML2Pdf (Python) - XML 2 Indesign - Wkhtmltopdf - Puppeteer Commercial: - PDFReactor - PrinceXML - Antennahouse https://www.print-css.rocks/
  3. 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
  4. nesk/puphpeteer Puppeteer bridge for PHP, based on nesk/rialto Needs nodejs,

    needs PHP exec permissions composer require nesk/puphpeteer npm install @nesk/puphpeteer
  5. 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();
  6. 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
  7. 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
  8. 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);
  9. 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
  10. That’s all folks! We are excited to hear from you:

    Andy Adiwidjaja Phone: +49 4102 208456 EMail: aa@adiwidjaja.com Illustrations: Maria Müller-Leinweber https://www.mamuelei.de