"description": "Python-PDFKit: HTML to PDF wrapper\r\n=\r\n\r\n\r\n. * Allow user specification of configuration * More easier custom configuration setting * Fix tests that was broken with latest wkhtmltopdf release * Rise an error when X server is missing on \*nix systems * Fix problems with external file encodings * Fix some corner cases when specific argument order is required * Support multiple values for some options * Fix regression on python 3 when trying to decode pdf output * Fix different issues with options handling * Fix different issues with searching for wkhtmltopdf binary Now if you need to get output you should pass "verbose=True" to API calls * By default PDFKit now passes "quiet" option to wkhtmltopdf. You can try to directly run a command from error message and see what error caused failure (on some wkhtmltopdf versions this can be cause by segmentation faults) This error means that PDFKit was unable to process an input. *where wkhtmltopdf* in Windows or *which wkhtmltopdf* on Linux should return actual path to binary. Make sure that you have wkhtmltopdf in your `$PATH` or set via custom configuration (see preceding section). ``IOError: 'No wkhtmltopdf executable found'``: R = pdfkit.PDFKit('html', 'string', verbose=True) You can get CLI command by creating ``pdfkit.PDFKit`` class directly and then calling its ``command()`` method:: If you are getting strange results in PDF or some option looks like its ignored you should try to run ``wkhtmltopdf`` directly to see if it produces the same result. If you struggling to generate correct PDF firstly you should check ``wkhtmltopdf`` output for some clues, you can get it by passing ``verbose=True`` to API calls:: om_string(html_string, output_file, configuration=config)Īlso you can use ``configuration()`` call to check if wkhtmltopdf is present in ``$PATH``:: * ``meta_tag_prefix`` - the prefix for ``pdfkit`` specific meta tags - by default this is ``pdfkit-``Įxample - for when ``wkhtmltopdf`` is not on ``$PATH``::Ĭonfig = nfiguration(wkhtmltopdf='/opt/bin/wkhtmltopdf') By default ``pdfkit`` will attempt to locate this using ``which`` (on UNIX type systems) or ``where`` (on Windows). * ``wkhtmltopdf`` - the location of the ``wkhtmltopdf`` binary. It takes the configuration options as initial paramaters. This should be an instance of ``nfiguration()`` API call. om_string(body, 'out.pdf') #with -page-size=Legal and -orientation=LandscapeĮach API call takes an optional configuration paramater. You can also pass any options through meta tags in your HTML:: om_file('file.html', options=options, css=css) You should try *-user-style-sheet* option first. **Warning** This is a workaround for `this bug `_ in wkhtmltopdf. You can specify external CSS files when converting files or strings using *css* option. om_file('file.html', options=options, toc=toc, cover=cover, cover_first=True) om_file('file.html', options=options, toc=toc, cover=cover) If you need cover before TOC, use ``cover_first`` option:: om_url('', 'out.pdf', verbose=True)ĭue to wkhtmltopdf command syntax, **TOC** and **Cover** options must be specified separately. If need to get ``wkhtmltopdf`` output you should pass ``verbose=True`` to API calls:: om_url('', 'out.pdf', options=options)īy default, PDFKit will run ``wkhtmltopdf`` with ``quiet`` option turned on, since in most cases output is not needed and can cause excessive memory usage and corrupted results. custom-header Authorization secret) we may use a 2-tuple (see example below). With option that need multiple values (e.g. allow, cookie, custom-header, post, postfile, run-script, replace) you may use a list or a tuple. If option without value, use *None, False* or *''* for dict value. You can specify all wkhtmltopdf `options `_. # Without output_path, PDF is returned for assigning to a variable If you wish to further process generated PDF, you can read it to a variable:: You can pass a list with multiple URLs or files:: * Windows and other options: check wkhtmltopdf `homepage `_ for binary installers To use this options you should install static binary from `wkhtmltopdf `_ site or you can use `this script `_. **Warning!** Version in debian/ubuntu repos have reduced functionality (because it compiled without the wkhtmltopdf QT patches), such as adding outlines, headers, footers, TOC etc. $ pip install pdfkit (or pip3 for python3) This is adapted version of `ruby PDFKit `_ library, so big thanks to them! Python 2 and 3 wrapper for wkhtmltopdf utility to convert HTML to PDF using Webkit.
0 Comments
Leave a Reply. |