README_WKHTMLTOPDF 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. ======================> wkhtmltopdf 0.10.0 beta5 Manual <=======================
  2. This file documents wkhtmltopdf, a program capable of converting html documents
  3. into PDF documents.
  4. ==================================> Contact <===================================
  5. If you experience bugs or want to request new features please visit
  6. <http://code.google.com/p/wkhtmltopdf/issues/list>, if you have any problems or
  7. comments please feel free to contact me: see
  8. <http://www.madalgo.au.dk/~jakobt/#about>
  9. ===========================> Reduced Functionality <============================
  10. Some versions of wkhtmltopdf are compiled against a version of QT without the
  11. wkhtmltopdf patches. These versions are missing some features, you can find out
  12. if your version of wkhtmltopdf is one of these by running wkhtmltopdf --version
  13. if your version is against an unpatched QT, you can use the static version to
  14. get all functionality.
  15. Currently the list of features only supported with patch QT includes:
  16. * Printing more then one HTML document into a PDF file.
  17. * Running without an X11 server.
  18. * Adding a document outline to the PDF file.
  19. * Adding headers and footers to the PDF file.
  20. * Generating a table of contents.
  21. * Adding links in the generated PDF file.
  22. * Printing using the screen media-type.
  23. * Disabling the smart shrink feature of webkit.
  24. ==================================> License <===================================
  25. Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.
  26. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
  27. This is free software: you are free to change and redistribute it. There is NO
  28. WARRANTY, to the extent permitted by law.
  29. ==================================> Authors <===================================
  30. Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by
  31. Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and
  32. Mário Silva.
  33. ==================================> Synopsis <==================================
  34. wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>
  35. ==============================> Document objects <==============================
  36. wkhtmltopdf is able to put several objects into the output file, an object is
  37. either a single webpage, a cover webpage or a table of content. The objects are
  38. put into the output document in the order they are specified on the command
  39. line, options can be specified on a per object basis or in the global options
  40. area. Options from the Global Options section can only be placed in the global
  41. options area
  42. A page objects puts the content of a singe webpage into the output document.
  43. (page)? <input url/file name> [PAGE OPTION]...
  44. Options for the page object can be placed in the global options and the page
  45. options areas. The applicable options can be found in the Page Options and
  46. Headers And Footer Options sections.
  47. A cover objects puts the content of a singe webpage into the output document,
  48. the page does not appear in the table of content, and does not have headers and
  49. footers.
  50. cover <input url/file name> [PAGE OPTION]...
  51. All options that can be specified for a page object can also be specified for a
  52. cover.
  53. A table of content object inserts a table of content into the output document.
  54. toc [TOC OPTION]...
  55. All options that can be specified for a page object can also be specified for a
  56. toc, further more the options from the TOC Options section can also be applied.
  57. The table of content is generated via XSLT which means that it can be styled to
  58. look however you want it to look. To get an aide of how to do this you can dump
  59. the default xslt document by supplying the --dump-default-toc-xsl, and the
  60. outline it works on by supplying --dump-outline, see the Outline Options
  61. section.
  62. ===============================> Global Options <===============================
  63. --collate Collate when printing multiple copies
  64. (default)
  65. --no-collate Do not collate when printing multiple
  66. copies
  67. --cookie-jar <path> Read and write cookies from and to the
  68. supplied cookie jar file
  69. --copies <number> Number of copies to print into the pdf
  70. file (default 1)
  71. -d, --dpi <dpi> Change the dpi explicitly (this has no
  72. effect on X11 based systems)
  73. -H, --extended-help Display more extensive help, detailing
  74. less common command switches
  75. -g, --grayscale PDF will be generated in grayscale
  76. -h, --help Display help
  77. --htmldoc Output program html help
  78. --image-dpi * <integer> When embedding images scale them down to
  79. this dpi (default 600)
  80. --image-quality * <integer> When jpeg compressing images use this
  81. quality (default 94)
  82. -l, --lowquality Generates lower quality pdf/ps. Useful to
  83. shrink the result document space
  84. --manpage Output program man page
  85. -B, --margin-bottom <unitreal> Set the page bottom margin (default 10mm)
  86. -L, --margin-left <unitreal> Set the page left margin (default 10mm)
  87. -R, --margin-right <unitreal> Set the page right margin (default 10mm)
  88. -T, --margin-top <unitreal> Set the page top margin (default 10mm)
  89. -O, --orientation <orientation> Set orientation to Landscape or Portrait
  90. (default Portrait)
  91. --output-format <format> Specify an output format to use pdf or ps,
  92. instead of looking at the extention of the
  93. output filename
  94. --page-height <unitreal> Page height
  95. -s, --page-size <Size> Set paper size to: A4, Letter, etc.
  96. (default A4)
  97. --page-width <unitreal> Page width
  98. --no-pdf-compression * Do not use lossless compression on pdf
  99. objects
  100. -q, --quiet Be less verbose
  101. --read-args-from-stdin Read command line arguments from stdin
  102. --readme Output program readme
  103. --title <text> The title of the generated pdf file (The
  104. title of the first document is used if not
  105. specified)
  106. --use-xserver * Use the X server (some plugins and other
  107. stuff might not work without X11)
  108. -V, --version Output version information an exit
  109. Items marked * are only available using patched QT.
  110. ==============================> Outline Options <===============================
  111. --dump-default-toc-xsl * Dump the default TOC xsl style sheet to
  112. stdout
  113. --dump-outline * <file> Dump the outline to a file
  114. --outline * Put an outline into the pdf (default)
  115. --no-outline * Do not put an outline into the pdf
  116. --outline-depth * <level> Set the depth of the outline (default 4)
  117. Items marked * are only available using patched QT.
  118. ================================> Page Options <================================
  119. --allow <path> Allow the file or files from the specified
  120. folder to be loaded (repeatable)
  121. --background Do print background (default)
  122. --no-background Do not print background
  123. --cookie <name> <value> Set an additional cookie (repeatable)
  124. --custom-header <name> <value> Set an additional HTTP header (repeatable)
  125. --custom-header-propagation Add HTTP headers specified by
  126. --custom-header for each resource request.
  127. --no-custom-header-propagation Do not add HTTP headers specified by
  128. --custom-header for each resource request.
  129. --debug-javascript Show javascript debugging output
  130. --no-debug-javascript Do not show javascript debugging output
  131. (default)
  132. --default-header * Add a default header, with the name of the
  133. page to the left, and the page number to
  134. the right, this is short for:
  135. --header-left='[webpage]'
  136. --header-right='[page]/[toPage]' --top 2cm
  137. --header-line
  138. --encoding <encoding> Set the default text encoding, for input
  139. --disable-external-links * Do not make links to remote web pages
  140. --enable-external-links * Make links to remote web pages (default)
  141. --disable-forms * Do not turn HTML form fields into pdf form
  142. fields (default)
  143. --enable-forms * Turn HTML form fields into pdf form fields
  144. --images Do load or print images (default)
  145. --no-images Do not load or print images
  146. --disable-internal-links * Do not make local links
  147. --enable-internal-links * Make local links (default)
  148. -n, --disable-javascript Do not allow web pages to run javascript
  149. -n, --enable-javascript Do allow web pages to run javascript
  150. (default)
  151. --javascript-delay <msec> Wait some milliseconds for javascript
  152. finish (default 200)
  153. --load-error-handling <handler> Specify how to handle pages that fail to
  154. load: abort, ignore or skip (default
  155. abort)
  156. --disable-local-file-access Do not allowed conversion of a local file
  157. to read in other local files, unless
  158. explecitily allowed with --allow
  159. --enable-local-file-access Allowed conversion of a local file to read
  160. in other local files. (default)
  161. --minimum-font-size <int> Minimum font size
  162. --password <password> HTTP Authentication password
  163. --disable-plugins Disable installed plugins (default)
  164. --enable-plugins Enable installed plugins (plugins will
  165. likely not work)
  166. --post <name> <value> Add an additional post field (repeatable)
  167. --post-file <name> <path> Post an additional file (repeatable)
  168. --print-media-type * Use print media-type instead of screen
  169. --no-print-media-type * Do not use print media-type instead of
  170. screen (default)
  171. -p, --proxy <proxy> Use a proxy
  172. --disable-smart-shrinking * Disable the intelligent shrinking strategy
  173. used by WebKit that makes the pixel/dpi
  174. ratio none constant
  175. --enable-smart-shrinking * Enable the intelligent shrinking strategy
  176. used by WebKit that makes the pixel/dpi
  177. ratio none constant (default)
  178. --stop-slow-scripts Stop slow running javascripts (default)
  179. --no-stop-slow-scripts Do not Stop slow running javascripts
  180. (default)
  181. --disable-toc-back-links * Do not link from section header to toc
  182. (default)
  183. --enable-toc-back-links * Link from section header to toc
  184. --user-style-sheet <url> Specify a user style sheet, to load with
  185. every page
  186. --username <username> HTTP Authentication username
  187. --zoom <float> Use this zoom factor (default 1)
  188. Items marked * are only available using patched QT.
  189. =========================> Headers And Footer Options <=========================
  190. --footer-center * <text> Centered footer text
  191. --footer-font-name * <name> Set footer font name (default Ariel)
  192. --footer-font-size * <size> Set footer font size (default 12)
  193. --footer-html * <url> Adds a html footer
  194. --footer-left * <text> Left aligned footer text
  195. --footer-line * Display line above the footer
  196. --no-footer-line * Do not display line above the footer
  197. (default)
  198. --footer-right * <text> Right aligned footer text
  199. --footer-spacing * <real> Spacing between footer and content in mm
  200. (default 0)
  201. --header-center * <text> Centered header text
  202. --header-font-name * <name> Set header font name (default Ariel)
  203. --header-font-size * <size> Set header font size (default 12)
  204. --header-html * <url> Adds a html header
  205. --header-left * <text> Left aligned header text
  206. --header-line * Display line below the header
  207. --no-header-line * Do not display line below the header
  208. (default)
  209. --header-right * <text> Right aligned header text
  210. --header-spacing * <real> Spacing between header and content in mm
  211. (default 0)
  212. --replace * <name> <value> Replace [name] with value in header and
  213. footer (repeatable)
  214. Items marked * are only available using patched QT.
  215. ================================> TOC Options <=================================
  216. --disable-dotted-lines * Do not use dottet lines in the toc
  217. --toc-header-text * <text> The header text of the toc (default Table
  218. of Content)
  219. --toc-level-indentation * <width> For each level of headings in the toc
  220. indent by this length (default 1em)
  221. --disable-toc-links * Do not link from toc to sections
  222. --toc-text-size-shrink * <real> For each level of headings in the toc the
  223. font is scaled by this facter (default
  224. 0.8)
  225. --xsl-style-sheet * <file> Use the supplied xsl style sheet for
  226. printing the table of content
  227. Items marked * are only available using patched QT.
  228. =============================> Specifying A Proxy <=============================
  229. By default proxy information will be read from the environment variables: proxy,
  230. all_proxy and http_proxy, proxy options can also by specified with the -p switch
  231. <type> := "http://" | "socks5://"
  232. <serif> := <username> (":" <password>)? "@"
  233. <proxy> := "None" | <type>? <sering>? <host> (":" <port>)?
  234. Here are some examples (In case you are unfamiliar with the BNF):
  235. http://user:password@myproxyserver:8080
  236. socks5://myproxyserver
  237. None
  238. ============================> Footers And Headers <=============================
  239. Headers and footers can be added to the document by the --header-* and --footer*
  240. arguments respectfully. In header and footer text string supplied to e.g.
  241. --header-left, the following variables will be substituted.
  242. * [page] Replaced by the number of the pages currently being printed
  243. * [frompage] Replaced by the number of the first page to be printed
  244. * [topage] Replaced by the number of the last page to be printed
  245. * [webpage] Replaced by the URL of the page being printed
  246. * [section] Replaced by the name of the current section
  247. * [subsection] Replaced by the name of the current subsection
  248. * [date] Replaced by the current date in system local format
  249. * [time] Replaced by the current time in system local format
  250. * [title] Replaced by the title of the of the current page object
  251. * [doctitle] Replaced by the title of the output document
  252. As an example specifying --header-right "Page [page] of [toPage]", will result
  253. in the text "Page x of y" where x is the number of the current page and y is the
  254. number of the last page, to appear in the upper left corner in the document.
  255. Headers and footers can also be supplied with HTML documents. As an example one
  256. could specify --header-html header.html, and use the following content in
  257. header.html:
  258. <html><head><script>
  259. function subst() {
  260. var vars={};
  261. var x=document.location.search.substring(1).split('&');
  262. for (var i in x) {var z=x[i].split('=',2);vars[z[0]] = unescape(z[1]);}
  263. var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
  264. for (var i in x) {
  265. var y = document.getElementsByClassName(x[i]);
  266. for (var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
  267. }
  268. }
  269. </script></head><body style="border:0; margin: 0;" onload="subst()">
  270. <table style="border-bottom: 1px solid black; width: 100%">
  271. <tr>
  272. <td class="section"></td>
  273. <td style="text-align:right">
  274. Page <span class="page"></span> of <span class="topage"></span>
  275. </td>
  276. </tr>
  277. </table>
  278. </body></html>
  279. As can be seen from the example, the arguments are sent to the header/footer
  280. html documents in get fashion.
  281. ==================================> Outlines <==================================
  282. Wkhtmltopdf with patched qt has support for PDF outlines also known as book
  283. marks, this can be enabled by specifying the --outline switch. The outlines are
  284. generated based on the <h?> tags, for a in-depth description of how this is done
  285. see the Table Of Contest section.
  286. The outline tree can sometimes be very deep, if the <h?> tags where spread to
  287. generous in the HTML document. The --outline-depth switch can be used to bound
  288. this.
  289. ==============================> Table Of Content <==============================
  290. A table of content can be added to the document by adding a toc objectto the
  291. command line. For example:
  292. wkhtmltopdf toc http://doc.trolltech.com/4.6/qstring.html qstring.pdf
  293. The table of content is generated based on the H tags in the input documents.
  294. First a XML document is generated, then it is converted to HTML using XSLT.
  295. The generated XML document can be viewed by dumping it to a file using the
  296. --dump-outline switch. For example:
  297. wkhtmltopdf --dump-outline toc.xml http://doc.trolltech.com/4.6/qstring.html qstring.pdf
  298. The XSLT document can be specified using the --xsl-style-sheet switch. For
  299. example:
  300. wkhtmltopdf toc --xsl-style-sheet my.xsl http://doc.trolltech.com/4.6/qstring.html qstring.pdf
  301. The --dump-default-toc-xsl switch can be used to dump the default XSLT style
  302. sheet to stdout. This is a good start for writing your own style sheet
  303. wkhtmltopdf --dump-default-toc-xsl
  304. The XML document is in the namespace
  305. "http://code.google.com/p/wkhtmltopdf/outline" it has a root node called
  306. "outline" which contains a number of "item" nodes. An item can contain any
  307. number of item. These are the outline subsections to the section the item
  308. represents. A item node has the following attributes:
  309. * "title" the name of the section.
  310. * "page" the page number the section occurs on.
  311. * "link" a URL that links to the section.
  312. * "backLink" the name of the anchor the the section will link back to.
  313. The remaining TOC options only affect the default style sheet so they will not
  314. work when specifying a custom style sheet.
  315. ===============================> Page Breaking <================================
  316. The current page breaking algorithm of WebKit leaves much to be desired.
  317. Basically webkit will render everything into one long page, and then cut it up
  318. into pages. This means that if you have two columns of text where one is
  319. vertically shifted by half a line. Then webkit will cut a line into to pieces
  320. display the top half on one page. And the bottom half on another page. It will
  321. also break image in two and so on. If you are using the patched version of QT
  322. you can use the CSS page-break-inside property to remedy this somewhat. There is
  323. no easy solution to this problem, until this is solved try organising your HTML
  324. documents such that it contains many lines on which pages can be cut cleanly.
  325. See also: <http://code.google.com/p/wkhtmltopdf/issues/detail?id=9>,
  326. <http://code.google.com/p/wkhtmltopdf/issues/detail?id=33> and
  327. <http://code.google.com/p/wkhtmltopdf/issues/detail?id=57>.
  328. =================================> Page sizes <=================================
  329. The default page size of the rendered document is A4, but using this --page-size
  330. optionthis can be changed to almost anything else, such as: A3, Letter and
  331. Legal. For a full list of supported pages sizes please see
  332. <http://doc.trolltech.com/4.6/qprinter.html#PageSize-enum>.
  333. For a more fine grained control over the page size the --page-height and
  334. --page-width options may be used
  335. ========================> Reading arguments from stdin <========================
  336. If you need to convert a lot of pages in a batch, and you feel that wkhtmltopdf
  337. is a bit to slow to start up, then you should try --read-args-from-stdin,
  338. When --read-args-from-stdin each line of input sent to wkhtmltopdf on stdin will
  339. act as a separate invocation of wkhtmltopdf, with the arguments specified on the
  340. given line combined with the arguments given to wkhtmltopdf
  341. For example one could do the following:
  342. echo "http://doc.trolltech.com/4.5/qapplication.html qapplication.pdf" >> cmds
  343. echo "--cover google.com http://en.wikipedia.org/wiki/Qt_(toolkit) qt.pdf" >> cmds
  344. wkhtmltopdf --read-args-from-stdin --book < cmds
  345. ===============================> Static version <===============================
  346. On the wkhtmltopdf website you can download a static version of wkhtmltopdf
  347. <http://code.google.com/p/wkhtmltopdf/downloads/list>. This static binary will
  348. work on most systems and comes with a build in patched QT.
  349. Unfortunately the static binary is not particularly static, on Linux it depends
  350. on both glibc and openssl, furthermore you will need to have an xserver
  351. installed but not necessary running. You will need to have different fonts
  352. install including xfonts-scalable (Type1), and msttcorefonts. See
  353. <http://code.google.com/p/wkhtmltopdf/wiki/static> for trouble shouting.
  354. ================================> Compilation <=================================
  355. It can happen that the static binary does not work for your system for one
  356. reason or the other, in that case you might need to compile wkhtmltopdf
  357. yourself.
  358. *GNU/Linux:*
  359. Before compilation you will need to install dependencies: X11, gcc, git and
  360. openssl. On Debian/Ubuntu this can be done as follows:
  361. sudo apt-get build-dep libqt4-gui libqt4-network libqt4-webkit
  362. sudo apt-get install openssl build-essential xorg git-core git-doc libssl-dev
  363. On other systems you must use your own package manager, the packages might be
  364. named differently.
  365. First you must check out the modified version of QT
  366. git clone git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git wkhtmltopdf-qt
  367. Next you must configure, compile and install QT, note this will take quite some
  368. time, depending on what arguments you use to configure qt
  369. cd wkhtmltopdf-qt
  370. ./configure -nomake tools,examples,demos,docs,translations -opensource -prefix ../wkqt
  371. make -j3
  372. make install
  373. cd ..
  374. All that is needed now is, to compile wkhtmltopdf.
  375. git clone git://github.com/antialize/wkhtmltopdf.git wkhtmltopdf
  376. cd wkhtmltopdf
  377. ../wkqt/bin/qmake
  378. make -j3
  379. You show now have a binary called wkhtmltopdf in the currently folder that you
  380. can use, you can optionally install it by running
  381. make install
  382. *Other operative systems and advanced features*
  383. If you want more details or want to compile under other operative systemsother
  384. then GNU/Linux, please see
  385. <http://code.google.com/p/wkhtmltopdf/wiki/compilation>.
  386. ================================> Installation <================================
  387. There are several ways to install wkhtmltopdf. You can download a already
  388. compiled binary, or you can compile wkhtmltopdf yourself. On windows the easiest
  389. way to install wkhtmltopdf is to download the latest installer. On linux you can
  390. download the latest static binary, however you still need to install some other
  391. pieces of software, to learn more about this read the static version section of
  392. the manual.
  393. ==================================> Examples <==================================
  394. This section presents a number of examples of how to invoke wkhtmltopdf.
  395. To convert a remote HTML file to PDF:
  396. wkhtmltopdf http://www.google.com google.pdf
  397. To convert a local HTML file to PDF:
  398. wkhtmltopdf my.html my.pdf
  399. You can also convert to PS files if you like:
  400. wkhtmltopdf my.html my.ps
  401. Produce the eler2.pdf sample file:
  402. wkhtmltopdf -H http://geekz.co.uk/lovesraymond/archive/eler-highlights-2008 eler2.pdf
  403. Printing a book with a table of content:
  404. wkhtmltopdf -H cover cover.html toc chapter1.html chapter2.html chapter3.html book.pdf