Giter Site home page Giter Site logo

chromepdf's Introduction

ChromePdf

ChromePdf is a command line utility that simplifies the process of generating PDFs from HTML. ChromePdf handles this by using CefSharp to render the HTML and generate the PDF. As you may know, generating accurate PDFs from HTML from a backend application or even from the command line can be very cumbersome. There are many 3rd party libraries out there but many of them cost money and tend not to be very accurate. There are also some open source libraries, however, I found that many of them were either not complete, no longer being supported, or they did not create accurate PDFs.

So, I decided to leverage chromium to do all of the heavy lifiting because I have found that it produces the most accurate PDFs when generating them from HTML. I decided to share this utility in case anyone else might need it. Hence, ChromePdf!

The utility itself is just a windows console app which takes several arguments, so it is pretty straight-forward to use. To see help for the utility, simply call it from the command line without any arguments chromepdf. Here are the help contents for reference:

ChromePdf 1.0.0.0
Copyright c  2017

  -i, --input                   Required. Input URI (required).

  -o, --output                  Required. Output file path (required).

  -l, --landscape               (Default: False) Specifies that the PDF should
                                be rendered in landscape orientation.

  -b, --enable-backgrounds      (Default: False) Specifies that background
                                graphics should be rendered in the PDF.

  -n, --timeout                 (Default: 0) Specifies a timeout (milliseconds)
                                in which to kill the process if it has not
                                exited successfully (0 = no timeout).

  -d, --delay                   (Default: 0) Specifies a delay (milliseconds)
                                in which to wait for the URI to load before
                                processing (0 = no delay; This is independent
                                on the time it takes the page to load in the
                                browser.).

  -m, --margin-type             (Default: Default) Specifies the margin for the
                                PDF (available values: Custom, Default,
                                Minimum, None).

  -h, --enable-header-footer    (Default: False) Specifies that the
                                header/footer should be rendered in the PDF.

  -t, --title                   A title to be rendered in the PDF header (only
                                used if enable-header-footer present).

  -f, --footer-text             Text to be rendered in the PDF footer (only
                                used if enable-header-footer present).

  --margin-bottom               (Default: 0) Bottom margin (only used if
                                margin-type is set to custom).

  --margin-left                 (Default: 0) Left margin (only used if
                                margin-type is set to custom).

  --margin-right                (Default: 0) Right margin (only used if
                                margin-type is set to custom).

  --margin-top                  (Default: 0) Top margin (only used if
                                margin-type is set to custom).

  --page-height                 (Default: 0) Page height in microns (if 0 paper
                                size is set to A4).

  --page-width                  (Default: 0) Page width in microns (if 0 paper
                                size is set to A4).                               
                                

Some Simple Examples

Generate a PDF of github.com in landscape mode with background graphics:

chromepdf -i "https://github.com" -o github.pdf -l -b

Generate a PDF of a local html file:

chromepdf -i "<path to file>\test.html" -o github.pdf -l -b

Dependencies

VC++ Redistributable 2013 - The redistributable package is a required dependency of CefSharp. You can find it here.

chromepdf's People

Contributors

stuarthillary avatar tjscience avatar

Watchers

 avatar

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.