0
1

More than 1 year has passed since last update.

2019年 #HTML #PDF 変換の情勢とは? ( phantomjs -> wkhtmlpdf -> headless Chrome + #node + puppeteer )

Last updated at Posted at 2019-10-30

古い手法とは

PhantomJSのかわりにwkhtmltopdfが重宝されてきたけどモダンブラウザの仕組み、 HTML5やjsに対応しきれてないよーって書かれてる気がする。

The traditional approaches
Until 2017, there were two common ways to convert HTML to PDF. The first was to use wkhtmltopdf — an open source command line tool specifically designed for the task. A second alternative was PhantomJS, an open source “headless” web browser which can be controlled with JavaScript.

Although these tools have served many people extremely well, they do have some downsides. Support for the latest HTML5 and JavaScript features lags a long way behind the modern browsers we’re used to such as Chrome, Firefox or Safari.

Chrome を直接利用する

凝ったことをやろうとすると、色々大変だよって書いてるような気がする。

Using the Chrome devtools API
If you’d like to use Chrome directly yourself, you can get started by using the “print-to-pdf” command line option, but for more control over the PDF you’ll need to communicate with Chrome’s devtools API.

Puppeteer

Chrome / chromium と dev-tool を上手に使うための仕組み、 node の Puppeteer が良さげって書かれているような気がする。

Controlling Chrome with Puppeteer

You could use Puppeteer to automate a Headless Chrome browser instance in almost any way. Here we’ll just be focusing on how it can be used to create PDFs.

Google cloud function

サーバーレスで使う方法があるらしい。

Using Puppeteer via Google Cloud Functions
One interesting new option is the ability to run headless Chrome on Google Cloud’s “serverless” platform — Cloud Functions. This feature was added to Cloud Functions in August 2018 and should provide a low-cost and highly scalable way of generating PDFs. Google’s announcement post has a good walk-through that explains how to set it all up.

比較

headless Chrome がエクセレント!

image

typesettingってなんだろうな

参考

強い!

仕組み
puppeteerは、WebdriverIOのようなクロスブラウザ対応のツールとは異なり、Chrome DevTools Protocol2 を利用してNode.jsからChromeの開発者ツールへ接続して操作を行います。

puppeteerがこれらのライブラリと一線を画すのは、なんと言っても本家ChromeのDevTool開発チームが作成・メンテナンスしている、という点でしょう。

--headless時代の本命? Chrome を Node.jsから操作するライブラリ puppeteer について - Qiita

Original by Github issue

チャットメンバー募集

何か質問、悩み事、相談などあればLINEオープンチャットもご利用ください。

Twitter

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1