Convert web thành pdf/image

0
3051

Cài đặt wkhtmltopdf

yum -y install wkhtmltopdf

Cài đặt xvfb

yum -y install xorg-x11-server-Xvfb

Cài đặt fonts

yum -y install xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi

Cấu hình start xvfb

/etc/systemd/system/xvfb.service
[Unit]
Description=Virtual Frame Buffer X Server
After=network.target

[Service]
ExecStart=/usr/bin/Xvfb :42 -screen 0 1024x768x24 -ac +extension GLX +render -noreset

[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl enable xvfb
systemctl start xvfb

Tạo command ngắn gọn

/usr/local/bin/wkhtmltopdf.sh
xvfb-run -a -s "-screen 0 1024x768x24" wkhtmltopdf "$@"
chmod +x /usr/local/bin/wkhtmltopdf.sh

Testing

wkhtmltopdf.sh http://google.com google.pdf

Leave a Reply

avatar
  Subscribe  
Notify of