2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

#docker + alpine + headless #GoogleChrome = chromium で HTML to PDF 変換 / スクリーンショット撮影を実行する例 ( online で URL 指定 )

Last updated at Posted at 2019-10-30

参考

ヘッドレス Chrome ことはじめ  |  Web  |  Google Developers

TL;DR
Headless Chrome が Chrome 59 に搭載されます!これは Chrome をヘッドレス環境で実行する手段です。Chrome をクローム(ブラウザーのUIのこと)なしに実行します!ヘッドレス Chrome によって、Chromium とそのエンジン Blink が提供するモダンなウェブプラットフォームの機能すべてがコマンドラインにもたらされるのです。

docker run alpine

docker run -it --name chrome-headless alpine:3.10.3 ash

install chromium

apk add --update chromium

Convert HTML to PDF

chromium-browser --no-sandbox --headless --disable-gpu --print-to-pdf https://yahoo.com

Copy pdf file to local = docker host and open it

docker cp chrome-headless:/output.pdf ./
open output.pdf

PDF

謎に日付が入っているが、これさえ消せたら良いのだけど。

image

Web

比較

image

スクリーンショット

chromium-browser --no-sandbox --headless --disable-gpu  --screenshot --window-size=1280,1696 https://yahoo.com
docker cp chrome-headless:/screenshot.png ./ && open screenshot.png

image

Original by Github issue

チャットメンバー募集

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

Twitter

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?