README_WKHTMLTOPDF 23 KB

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