wkhtmltopdf.txt 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. Name:
  2. wkhtmltopdf 0.12.6 (with patched qt)
  3. Synopsis:
  4. wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>
  5. Document objects:
  6. wkhtmltopdf is able to put several objects into the output file, an object is
  7. either a single webpage, a cover webpage or a table of contents. The objects
  8. are put into the output document in the order they are specified on the
  9. command line, options can be specified on a per object basis or in the global
  10. options area. Options from the Global Options section can only be placed in
  11. the global options area.
  12. A page objects puts the content of a single webpage into the output document.
  13. (page)? <input url/file name> [PAGE OPTION]...
  14. Options for the page object can be placed in the global options and the page
  15. options areas. The applicable options can be found in the Page Options and
  16. Headers And Footer Options sections.
  17. A cover objects puts the content of a single webpage into the output document,
  18. the page does not appear in the table of contents, and does not have headers
  19. and footers.
  20. cover <input url/file name> [PAGE OPTION]...
  21. All options that can be specified for a page object can also be specified for
  22. a cover.
  23. A table of contents object inserts a table of contents into the output
  24. document.
  25. toc [TOC OPTION]...
  26. All options that can be specified for a page object can also be specified for
  27. a toc, further more the options from the TOC Options section can also be
  28. applied. The table of contents is generated via XSLT which means that it can
  29. be styled to look however you want it to look. To get an idea of how to do
  30. this you can dump the default xslt document by supplying the
  31. --dump-default-toc-xsl, and the outline it works on by supplying
  32. --dump-outline, see the Outline Options section.
  33. Description:
  34. Converts one or more HTML pages into a PDF document, using wkhtmltopdf patched
  35. qt.
  36. Global Options:
  37. --collate Collate when printing multiple copies
  38. (default)
  39. --no-collate Do not collate when printing multiple
  40. copies
  41. --cookie-jar <path> Read and write cookies from and to the
  42. supplied cookie jar file
  43. --copies <number> Number of copies to print into the pdf
  44. file (default 1)
  45. -d, --dpi <dpi> Change the dpi explicitly (this has no
  46. effect on X11 based systems) (default 96)
  47. -H, --extended-help Display more extensive help, detailing
  48. less common command switches
  49. -g, --grayscale PDF will be generated in grayscale
  50. -h, --help Display help
  51. --htmldoc Output program html help
  52. --image-dpi <integer> When embedding images scale them down to
  53. this dpi (default 600)
  54. --image-quality <integer> When jpeg compressing images use this
  55. quality (default 94)
  56. --license Output license information and exit
  57. --log-level <level> Set log level to: none, error, warn or
  58. info (default info)
  59. -l, --lowquality Generates lower quality pdf/ps. Useful to
  60. shrink the result document space
  61. --manpage Output program man page
  62. -B, --margin-bottom <unitreal> Set the page bottom margin
  63. -L, --margin-left <unitreal> Set the page left margin (default 10mm)
  64. -R, --margin-right <unitreal> Set the page right margin (default 10mm)
  65. -T, --margin-top <unitreal> Set the page top margin
  66. -O, --orientation <orientation> Set orientation to Landscape or Portrait
  67. (default Portrait)
  68. --page-height <unitreal> Page height
  69. -s, --page-size <Size> Set paper size to: A4, Letter, etc.
  70. (default A4)
  71. --page-width <unitreal> Page width
  72. --no-pdf-compression Do not use lossless compression on pdf
  73. objects
  74. -q, --quiet Be less verbose, maintained for backwards
  75. compatibility; Same as using --log-level
  76. none
  77. --read-args-from-stdin Read command line arguments from stdin
  78. --readme Output program readme
  79. --title <text> The title of the generated pdf file (The
  80. title of the first document is used if not
  81. specified)
  82. --use-xserver Use the X server (some plugins and other
  83. stuff might not work without X11)
  84. -V, --version Output version information and exit
  85. Outline Options:
  86. --dump-default-toc-xsl Dump the default TOC xsl style sheet to
  87. stdout
  88. --dump-outline <file> Dump the outline to a file
  89. --outline Put an outline into the pdf (default)
  90. --no-outline Do not put an outline into the pdf
  91. --outline-depth <level> Set the depth of the outline (default 4)
  92. Page Options:
  93. --allow <path> Allow the file or files from the specified
  94. folder to be loaded (repeatable)
  95. --background Do print background (default)
  96. --no-background Do not print background
  97. --bypass-proxy-for <value> Bypass proxy for host (repeatable)
  98. --cache-dir <path> Web cache directory
  99. --checkbox-checked-svg <path> Use this SVG file when rendering checked
  100. checkboxes
  101. --checkbox-svg <path> Use this SVG file when rendering unchecked
  102. checkboxes
  103. --cookie <name> <value> Set an additional cookie (repeatable),
  104. value should be url encoded.
  105. --custom-header <name> <value> Set an additional HTTP header (repeatable)
  106. --custom-header-propagation Add HTTP headers specified by
  107. --custom-header for each resource request.
  108. --no-custom-header-propagation Do not add HTTP headers specified by
  109. --custom-header for each resource request.
  110. --debug-javascript Show javascript debugging output
  111. --no-debug-javascript Do not show javascript debugging output
  112. (default)
  113. --default-header Add a default header, with the name of the
  114. page to the left, and the page number to
  115. the right, this is short for:
  116. --header-left='[webpage]'
  117. --header-right='[page]/[toPage]' --top 2cm
  118. --header-line
  119. --encoding <encoding> Set the default text encoding, for input
  120. --disable-external-links Do not make links to remote web pages
  121. --enable-external-links Make links to remote web pages (default)
  122. --disable-forms Do not turn HTML form fields into pdf form
  123. fields (default)
  124. --enable-forms Turn HTML form fields into pdf form fields
  125. --images Do load or print images (default)
  126. --no-images Do not load or print images
  127. --disable-internal-links Do not make local links
  128. --enable-internal-links Make local links (default)
  129. -n, --disable-javascript Do not allow web pages to run javascript
  130. --enable-javascript Do allow web pages to run javascript
  131. (default)
  132. --javascript-delay <msec> Wait some milliseconds for javascript
  133. finish (default 200)
  134. --keep-relative-links Keep relative external links as relative
  135. external links
  136. --load-error-handling <handler> Specify how to handle pages that fail to
  137. load: abort, ignore or skip (default
  138. abort)
  139. --load-media-error-handling <handler> Specify how to handle media files
  140. that fail to load: abort, ignore or skip
  141. (default ignore)
  142. --disable-local-file-access Do not allowed conversion of a local file
  143. to read in other local files, unless
  144. explicitly allowed with --allow (default)
  145. --enable-local-file-access Allowed conversion of a local file to read
  146. in other local files.
  147. --minimum-font-size <int> Minimum font size
  148. --exclude-from-outline Do not include the page in the table of
  149. contents and outlines
  150. --include-in-outline Include the page in the table of contents
  151. and outlines (default)
  152. --page-offset <offset> Set the starting page number (default 0)
  153. --password <password> HTTP Authentication password
  154. --disable-plugins Disable installed plugins (default)
  155. --enable-plugins Enable installed plugins (plugins will
  156. likely not work)
  157. --post <name> <value> Add an additional post field (repeatable)
  158. --post-file <name> <path> Post an additional file (repeatable)
  159. --print-media-type Use print media-type instead of screen
  160. --no-print-media-type Do not use print media-type instead of
  161. screen (default)
  162. -p, --proxy <proxy> Use a proxy
  163. --proxy-hostname-lookup Use the proxy for resolving hostnames
  164. --radiobutton-checked-svg <path> Use this SVG file when rendering checked
  165. radiobuttons
  166. --radiobutton-svg <path> Use this SVG file when rendering unchecked
  167. radiobuttons
  168. --resolve-relative-links Resolve relative external links into
  169. absolute links (default)
  170. --run-script <js> Run this additional javascript after the
  171. page is done loading (repeatable)
  172. --disable-smart-shrinking Disable the intelligent shrinking strategy
  173. used by WebKit that makes the pixel/dpi
  174. ratio non-constant
  175. --enable-smart-shrinking Enable the intelligent shrinking strategy
  176. used by WebKit that makes the pixel/dpi
  177. ratio non-constant (default)
  178. --ssl-crt-path <path> Path to the ssl client cert public key in
  179. OpenSSL PEM format, optionally followed by
  180. intermediate ca and trusted certs
  181. --ssl-key-password <password> Password to ssl client cert private key
  182. --ssl-key-path <path> Path to ssl client cert private key in
  183. OpenSSL PEM format
  184. --stop-slow-scripts Stop slow running javascripts (default)
  185. --no-stop-slow-scripts Do not Stop slow running javascripts
  186. --disable-toc-back-links Do not link from section header to toc
  187. (default)
  188. --enable-toc-back-links Link from section header to toc
  189. --user-style-sheet <path> Specify a user style sheet, to load with
  190. every page
  191. --username <username> HTTP Authentication username
  192. --viewport-size <> Set viewport size if you have custom
  193. scrollbars or css attribute overflow to
  194. emulate window size
  195. --window-status <windowStatus> Wait until window.status is equal to this
  196. string before rendering page
  197. --zoom <float> Use this zoom factor (default 1)
  198. Headers And Footer Options:
  199. --footer-center <text> Centered footer text
  200. --footer-font-name <name> Set footer font name (default Arial)
  201. --footer-font-size <size> Set footer font size (default 12)
  202. --footer-html <url> Adds a html footer
  203. --footer-left <text> Left aligned footer text
  204. --footer-line Display line above the footer
  205. --no-footer-line Do not display line above the footer
  206. (default)
  207. --footer-right <text> Right aligned footer text
  208. --footer-spacing <real> Spacing between footer and content in mm
  209. (default 0)
  210. --header-center <text> Centered header text
  211. --header-font-name <name> Set header font name (default Arial)
  212. --header-font-size <size> Set header font size (default 12)
  213. --header-html <url> Adds a html header
  214. --header-left <text> Left aligned header text
  215. --header-line Display line below the header
  216. --no-header-line Do not display line below the header
  217. (default)
  218. --header-right <text> Right aligned header text
  219. --header-spacing <real> Spacing between header and content in mm
  220. (default 0)
  221. --replace <name> <value> Replace [name] with value in header and
  222. footer (repeatable)
  223. TOC Options:
  224. --disable-dotted-lines Do not use dotted lines in the toc
  225. --toc-header-text <text> The header text of the toc (default Table
  226. of Contents)
  227. --toc-level-indentation <width> For each level of headings in the toc
  228. indent by this length (default 1em)
  229. --disable-toc-links Do not link from toc to sections
  230. --toc-text-size-shrink <real> For each level of headings in the toc the
  231. font is scaled by this factor (default
  232. 0.8)
  233. --xsl-style-sheet <file> Use the supplied xsl style sheet for
  234. printing the table of contents
  235. Page sizes:
  236. The default page size of the rendered document is A4, but by using the
  237. --page-size option this can be changed to almost anything else, such as: A3,
  238. Letter and Legal. For a full list of supported pages sizes please see
  239. <https://doc.qt.io/archives/qt-4.8/qprinter.html#PaperSize-enum>.
  240. For a more fine grained control over the page size the --page-height and
  241. --page-width options may be used
  242. Reading arguments from stdin:
  243. If you need to convert a lot of pages in a batch, and you feel that
  244. wkhtmltopdf is a bit too slow to start up, then you should try
  245. --read-args-from-stdin,
  246. When --read-args-from-stdin each line of input sent to wkhtmltopdf on stdin
  247. will act as a separate invocation of wkhtmltopdf, with the arguments specified
  248. on the given line combined with the arguments given to wkhtmltopdf
  249. For example one could do the following:
  250. echo "https://doc.qt.io/archives/qt-4.8/qapplication.html qapplication.pdf" >> cmds
  251. echo "cover google.com https://en.wikipedia.org/wiki/Qt_(software) qt.pdf" >> cmds
  252. wkhtmltopdf --read-args-from-stdin --book < cmds
  253. Specifying A Proxy:
  254. By default proxy information will be read from the environment variables:
  255. proxy, all_proxy and http_proxy, proxy options can also by specified with the
  256. -p switch
  257. <type> := "http://" | "socks5://"
  258. <serif> := <username> (":" <password>)? "@"
  259. <proxy> := "None" | <type>? <string>? <host> (":" <port>)?
  260. Here are some examples (In case you are unfamiliar with the BNF):
  261. http://user:password@myproxyserver:8080
  262. socks5://myproxyserver
  263. None
  264. Footers And Headers:
  265. Headers and footers can be added to the document by the --header-* and
  266. --footer* arguments respectively. In header and footer text string supplied
  267. to e.g. --header-left, the following variables will be substituted.
  268. * [page] Replaced by the number of the pages currently being printed
  269. * [frompage] Replaced by the number of the first page to be printed
  270. * [topage] Replaced by the number of the last page to be printed
  271. * [webpage] Replaced by the URL of the page being printed
  272. * [section] Replaced by the name of the current section
  273. * [subsection] Replaced by the name of the current subsection
  274. * [date] Replaced by the current date in system local format
  275. * [isodate] Replaced by the current date in ISO 8601 extended format
  276. * [time] Replaced by the current time in system local format
  277. * [title] Replaced by the title of the of the current page object
  278. * [doctitle] Replaced by the title of the output document
  279. * [sitepage] Replaced by the number of the page in the current site being converted
  280. * [sitepages] Replaced by the number of pages in the current site being converted
  281. As an example specifying --header-right "Page [page] of [topage]", will result
  282. in the text "Page x of y" where x is the number of the current page and y is
  283. the number of the last page, to appear in the upper left corner in the
  284. document.
  285. Headers and footers can also be supplied with HTML documents. As an example
  286. one could specify --header-html header.html, and use the following content in
  287. header.html:
  288. <!DOCTYPE html>
  289. <html><head><script>
  290. function subst() {
  291. var vars = {};
  292. var query_strings_from_url = document.location.search.substring(1).split('&');
  293. for (var query_string in query_strings_from_url) {
  294. if (query_strings_from_url.hasOwnProperty(query_string)) {
  295. var temp_var = query_strings_from_url[query_string].split('=', 2);
  296. vars[temp_var[0]] = decodeURI(temp_var[1]);
  297. }
  298. }
  299. var css_selector_classes = ['page', 'frompage', 'topage', 'webpage', 'section', 'subsection', 'date', 'isodate', 'time', 'title', 'doctitle', 'sitepage', 'sitepages'];
  300. for (var css_class in css_selector_classes) {
  301. if (css_selector_classes.hasOwnProperty(css_class)) {
  302. var element = document.getElementsByClassName(css_selector_classes[css_class]);
  303. for (var j = 0; j < element.length; ++j) {
  304. element[j].textContent = vars[css_selector_classes[css_class]];
  305. }
  306. }
  307. }
  308. }
  309. </script></head><body style="border:0; margin: 0;" onload="subst()">
  310. <table style="border-bottom: 1px solid black; width: 100%">
  311. <tr>
  312. <td class="section"></td>
  313. <td style="text-align:right">
  314. Page <span class="page"></span> of <span class="topage"></span>
  315. </td>
  316. </tr>
  317. </table>
  318. </body></html>
  319. As can be seen from the example, the arguments are sent to the header/footer
  320. html documents in get fashion.
  321. Outlines:
  322. Wkhtmltopdf with patched qt has support for PDF outlines also known as book
  323. marks, this can be enabled by specifying the --outline switch. The outlines
  324. are generated based on the <h?> tags, for a in-depth description of how this
  325. is done see the Table Of Contents section.
  326. The outline tree can sometimes be very deep, if the <h?> tags where spread to
  327. generous in the HTML document. The --outline-depth switch can be used to
  328. bound this.
  329. Table Of Contents:
  330. A table of contents can be added to the document by adding a toc object to the
  331. command line. For example:
  332. wkhtmltopdf toc https://doc.qt.io/archives/qt-4.8/qstring.html qstring.pdf
  333. The table of contents is generated based on the H tags in the input documents.
  334. First a XML document is generated, then it is converted to HTML using XSLT.
  335. The generated XML document can be viewed by dumping it to a file using the
  336. --dump-outline switch. For example:
  337. wkhtmltopdf --dump-outline toc.xml https://doc.qt.io/archives/qt-4.8/qstring.html qstring.pdf
  338. The XSLT document can be specified using the --xsl-style-sheet switch. For
  339. example:
  340. wkhtmltopdf toc --xsl-style-sheet my.xsl https://doc.qt.io/archives/qt-4.8/qstring.html qstring.pdf
  341. The --dump-default-toc-xsl switch can be used to dump the default XSLT style
  342. sheet to stdout. This is a good start for writing your own style sheet
  343. wkhtmltopdf --dump-default-toc-xsl
  344. The XML document is in the namespace "http://wkhtmltopdf.org/outline" it has a
  345. root node called "outline" which contains a number of "item" nodes. An item
  346. can contain any number of item. These are the outline subsections to the
  347. section the item represents. A item node has the following attributes:
  348. * "title" the name of the section.
  349. * "page" the page number the section occurs on.
  350. * "link" a URL that links to the section.
  351. * "backLink" the name of the anchor the section will link back to.
  352. The remaining TOC options only affect the default style sheet so they will not
  353. work when specifying a custom style sheet.
  354. Contact:
  355. If you experience bugs or want to request new features please visit
  356. <https://wkhtmltopdf.org/support.html>