Giter Site home page Giter Site logo

chromehtml2pdf's Introduction

HTML to PDF converter using headless Chrome

This provides a clean command line interface for creating PDFs of web pages using headless chrome.

It is meant to basically be a drop-in replacement for wkhtmltopdf or other command line HTML to PDF generators. It seems to generate PDFs essentially identical to what is printed from Chrome itself, and since the chromium team plans on keeping up headless chrome, this seems to be a good option that will stay stable into the future (unlike many PDF creation tools, which unfortunately, are difficult to maintain).

This can be called from programming languages such as Python, PHP, Java, etc., with appropriate command line arguments to facilitate automated PDF creation from HTML pages.

Installation

See https://www.npmjs.com/package/chromehtml2pdf

Usage

Once installed, simple command line usage is:

chromehtml2pdf --out=out.pdf https://wikipedia.org

to generate a PDF of that web page.

For local files use:

chromehtml2pdf --out=out.pdf file:///path/to/file/file.htm

There are a number of optional arguments for how to print (margins, page sizes, orientation, header/footer, etc.). To see all of the options, once installed type

chromehtml2pdf --help

This has been tested on Linux Ubuntu ^14.04.

Known Issues

Permissions issues:

When installing using npm install -g, I noticed that the chrome executables that come packaged with puppeteer are not executable by users who did not install it. You will notice this as an EACCES error (if it happens to you).

If you want something that can be used for all users on a system, then you can:

  1. Pass --executablePath with some path to chrome/chromium that all users can run.

  2. Change the permissions of the chrome installation that is in puppeteer. Currently, this is stored in /node_modules/puppeteer/.local-chromium/.

chromehtml2pdf's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

chromehtml2pdf's Issues

Chromium Sandbox Issue

Greetings,

Thanks for your work.

I would like to suggest that a flag be added allowing puppeteer/chromium to run with the sandbox disabled.

var launchConfig = {args: ['--no-sandbox', '--disable-setuid-sandbox'] };

According to the document below, the sandbox is going away and, in my case, my installation does not come with the sandbox or the sandbox creation utility.

https://chromium.googlesource.com/chromium/src/+/master/docs/linux_suid_sandbox_development.md

Cheers.

Format as one page

Thanks for creating this package ๐Ÿ‘

One question:
Is it possible to have it format to 1 page and detect the height?
Cutting it up in A4 pages creates unwanted separations

margin* arguments seem to be ignored

Hi I'm running via docker in latest alpine container with alpine-repo version of chromium.
I can see it recognised my marginLeft=2 argument in the print statement:

Converting file: file:///home/pptruser/mnt/company/scorecard.html
out = mnt/company/company_scorecard.pdf
printBackground = true
format = A4
marginLeft = 2
Using chrome executable: /usr/bin/chromium-browser

but am definitely not getting 2 inch margin, no matter what value I place there the PDF is the same.

Cannot run from php exec()

I am able to convert html to pdf no problem directly from the command line.

However, I tried many different options to run this command through PHP (with Laravel) using exec and none of them work.
For example, neither of these commands generates the file:

exec('chromehtml2pdf --out=file.pdf ')
exec('C:\Users\\AppData\Roaming\npm\chromehtml2pdf.cmd --out=file.pdf ')

I only post this here, because the documentation reports that this should be executable from php, but it isn't working for me. Perhaps there is more configuration needed, but there is nothing in the documentation addressing it.

Unexpected Token While Executing

I installed chromehtml2pdf and wanted to see the extra options it offered but I am having trouble with the unexpected token error. Is this something related to my setup?

CentOS Linux release 7.7.1908 (Core)
Nodejs and npm installed from yum

chromehtml2pdf --help
/usr/lib/node_modules/chromehtml2pdf/index.js:144
    (async () => {
           ^

SyntaxError: Unexpected token (
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.runMain (module.js:611:10)
    at run (bootstrap_node.js:394:7)
    at startup (bootstrap_node.js:160:9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.