python generate pdf

#encoding=utf-8
'''
Created on 2015-3-29

@author: cooler
'''

import pdfkit

# pdfkit.from_url('http://google.com', 'out.pdf')
# pdfkit.from_file('test.html', 'out.pdf')
# pdfkit.from_string('Hello!', 'out.pdf')

options = {
    # 'page-size': 'Letter',
    # 'margin-top': '0.75in',
    # 'margin-right': '0.75in',
    # 'margin-bottom': '0.75in',
    # 'margin-left': '0.75in',
    # 'encoding': "UTF-8",
    # 'custom-header' : [
    #     ('Accept-Encoding', 'gzip')
    # ]
    # 'cookie': [
    #     ('cookie-name1', 'cookie-value1'),
    #     ('cookie-name2', 'cookie-value2'),
    # ],
    # 'no-outline': None
    # "header-center":"nddd",
    "header-right":"First examination room"
}

pdfkit.from_url('https://www.baidu.com', 'out.pdf', options=options)



wkhtmltopdf [OPTIONS]... <input file> [More input files] <output file>
General options
  --allow <path> Allow loading files or files from the specified folder (repeatable)
--book* Set a will print a book, usually set options
  --collate collate when printing multiple copies
  --cookie <name> <value> set an additional cookie (repeatable)
  --cookie-jar <path> read and Write cookies and provide in the cookie jar file
  --copies <number> Number of copies to print to pdf file (default 1)
  --cover* <url> Use HTML file as cover. It will insert before the TOC with header and footer
  --custom-header <name> <value> set an additional HTTP header (repeatable)
  --debug-javascript show javascript debug output
--default-header* add A default header, with the name of the left side of the page, and the number of pages to the right, for example: --header-left '[webpage]' --header-right '[page]/[toPage]'


--disable-javascript Disable JavaScript execution on web pages
  --disable-pdf-compression* Disable lossless compression on PDF objects
  --disable-smart-shrinking* Disable WebKit's smart shrinking strategy so that pixel/DPI ratio is not
  unchanged- -disallow-local-file-access Disallow allowing converted local files to read other local files, unless explecitily allow
changing the DPI explicitly with --allow --dpi <dpi> (this has no effect on X11 based systems)
  -- enable-plugins enable installed plugins (like Flash
  --encoding <encoding> set default text encoding
  --extended-help display more extensive help detailing less common command switches
  --forms* turn on HTML form field conversion For PDF form fields
--grayscale PDF will be generated in grayscale
--help Display help
  --htmldoc output program HTML help
  --ignore-load-errors ignore claims that an error page has been encountered during loading
--lowquality yield low quality pdf/ps.useful to shrink the resulting document space
  --manpage output program manual pages
--margin-bottom <unitreal> set the bottom margin of the page (default 10mm)
--margin-left <unitreal> set the left margin (default 10mm)
--margin-right <unitreal> set the right margin of the page (default 10mm)
- -margin-top <unitreal> set the top margin of the page (default 10mm)
  --minimum-font-size <int> minimum font size (default 5)
  --no-background do not print the background
--orientation <orientation> set the orientation to landscape Or portrait
  --page-height <unitreal> page height (default unit millimeter)
  --page-offset* <offset> set starting page number (default 1)
--page-size <size> set paper size: A4, Letter, etc.
    --page-width <unitreal> page width (default unit millimeter)
  --password <password> HTTP authentication password
  --post <name> <value> Add an additional post field (repeatable)
  --post-file <name> <path> Post an aditional file (repeatable)
  --print-media-type* print media type to use instead of screen
--proxy <proxy> use proxy
--quiet Be less verbose
-- -read-args-from-stdin read command line arguments from stdin --readme
output program readme
--redirect-delay <msec> wait a few milliseconds for JS-redirect (default 200)
--replace* <name> < value> Replace name, value headers and footers (repeatable)
--stop-slow-scripts Stop slow JavaScripts
--title <text> Title of the generated PDF file (the title of the first document is used if not specified)
--toc* Insert table of contents at the beginning of the file
--use-xserver* Use X server (some plugins and other stuff may not work without X11)
--user-style-sheet <url> Specifies the user's style sheet, loaded in each page
--username <username> HTTP authentication username
--version output version information exit
  --zoom <float> Use this scaling factor (default 1) for

header and footer options
--header-center* <text> (set header content at center) 
--header-font-name* <name> (default Arial) (set header font name)
--header-font-size* <size> (set the font size of the header)
--header-html* <url> (add an HTML header followed by a URL)
--header-left* <text> (left-aligned header text)
-- header-line* (display a line under the header)
--header-right* <text> (right-align the header text)
--header-spacing* <real> (set the distance between the header and content, default 0)
--footer-center* <text> (set footer content at center position) 
--footer-font-name* <name> (set footer font name)
--footer-font-size* <size> ( Set the font size of the footer default 11)
--footer-html* <url> (add an HTML footer, followed by the URL)
--footer-left* <text> (left-aligned footer text)
--footer-line* display a line over the footer content)
--footer-right* <text> (right-aligned footer text)
--footer-spacing*   <real>    (设置页脚和内容的距离)
./wkhtmltopdf --footer-right '[page]/[topage]' http://www.baidu.com baidu.pdf
./wkhtmltopdf --header-center '报表' --header-line --margin-top 2cm --header-line http://192.168.212.139/oma/  oma.pdf
表内容选项中
--toc-depth* <level>  Set the depth of the toc (default 3)
--toc-disable-back-links*  Do not link from section header to toc
--toc-disable-links*  Do not link from toc to sections
--toc-font-name* <name>  Set the font used for the toc (default Arial)
--toc-header-font-name* <name>  The font of the toc header (if unset use --toc-font-name)
--toc-header-font-size* <size>  The font size of the toc header (default 15)
--toc-header-text* <text>  The header text of the toc (default Table Of Contents)
--toc-l1-font-size* <size>  Set the font size on level 1 of the toc (default 12)
--toc-l1-indentation* <num>  Set indentation on level 1 of the toc (default 0)
--toc-l2-font-size* <size>  Set the font size on level 2 of the toc (default 10)
--toc-l2-indentation* <num>  Set indentation on level 2 of the toc (default 20)
--toc-l3-font-size* <size>  Set the font size on level 3 of the toc (default
--toc-l3-indentation* <num>  Set indentation on level 3 of the toc (default 40)
--toc-l4-font-size* <size>  Set the font size on level 4 of the toc (default 6)
--toc-l4-indentation* <num>  Set indentation on level 4 of the toc (default 60)
--toc-l5-font-size* <size>  Set the font size on level 5 of the toc (default 4)
--toc-l5-indentation* <num>  Set indentation on level 5 of the toc (default 80)
--toc-l6-font-size* <size>  Set the font size on level 6 of the toc (default 2)
--toc-l6-indentation* <num>  Set indentation on level 6 of the toc (default 100)
--toc-l7-font-size* <size>  Set the font size on level 7 of the toc (default 0)
--toc-l7-indentation* <num>  Set indentation on level 7 of the toc (default 120)
--toc-no-dots*  Do not use dots, in the toc
轮廓选项
--dump-outline <file>  转储目录到一个文件
--outline  显示目录(文章中h1,h2来定)
--outline-depth <level>Sets the depth of the table of contents (default 4) * [page] is replaced by the number of pages currently being printed
footer and header

* [frompage] is replaced by the number of the first page to be printed * [topage] is replaced
by the number of the last page to be printed
* [webpage] is replaced by the URL of the page being printed
* [section] is replaced by the name of the current section
* [subsection] is replaced by the name of the current subsection
* [date] is replaced by the current date system's local format
* [time] is replaced by the current time, the system's local
format./wkhtmltopdf --footer-right '[page]/[topage] ' http://www.baidu.com baidu.pdf
./wkhtmltopdf --header-center 'report' --outline --header-line --margin-top 2cm --header-line http://www.hao123 .com/hao123.pdf
./wkhtmltopdf --header-left '[webpage]' --footer-center 'test([page]/[toPage])' http://www.baidu.com baidu.pdf

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326316947&siteId=291194637