文書更新:2018年12月25日(火) 午後5時27分38秒

Home > 備忘録(Fedora) > アプリケーション > url を PDF に変換する( 108 )

wkhtmltopdf を install する

  1. wkhtmltopdf を install する
  2. # dnf -y install wkhtmltopdf
    Repository fedora has no mirror or baseurl set.
    Last metadata expiration check performed 2:42:17 ago on Sun Aug 23 07:54:01 2015.
    エラー: nothing provides libQtWebKit.so.4()(64bit) needed by wkhtmltopdf-0.12.3-0.1.D20150713git79ff51e.fc22.x86_64
    (try to add '--allowerasing' to command line to replace conflicting packages)
    libQtWebKit.so.4()(64bit) が必要だということで こちらから rpm をダウンロードする
  3. rpm をダウンロード
  4. # wget ftp://mirror.switch.ch/pool/4/mirror/fedora/linux/releases/22/Everything/x86_64/os/Packages/q/qtwebkit-2.3.4-6.fc22.x86_64.rpm
  5. rpm を install する
  6. # rpm -ivh qtwebkit-2.3.4-6.fc22.x86_64.rpm
  7. wkhtmltopdf を再 install する
  8. # dnf -y install wkhtmltopdf

wkhtmltopdf で url を PDF 化してみる

  1. 使用例
  2. # wkhtmltopdf http://yahoo.co.jp yahoo.pdf
    出来上がったPDF → こちら
  3. ヘルプ
  4. [root@server]# wkhtmltopdf --help
    	Name:
      wkhtmltopdf 0.12.6
    
    Synopsis:
      wkhtmltopdf [GLOBAL OPTION]... [OBJECT]... <output file>
      
    Document objects:
      wkhtmltopdf is able to put several objects into the output file, an object is
      either a single webpage, a cover webpage or a table of contents.  The objects
      are put into the output document in the order they are specified on the
      command line, options can be specified on a per object basis or in the global
      options area. Options from the Global Options section can only be placed in
      the global options area.
    
      A page objects puts the content of a single webpage into the output document.
    
      (page)? <input url/file name> [PAGE OPTION]...
      Options for the page object can be placed in the global options and the page
      options areas. The applicable options can be found in the Page Options and 
      Headers And Footer Options sections.
    
      A cover objects puts the content of a single webpage into the output document,
      the page does not appear in the table of contents, and does not have headers
      and footers.
    
      cover <input url/file name> [PAGE OPTION]...
      All options that can be specified for a page object can also be specified for
      a cover.
    
      A table of contents object inserts a table of contents into the output
      document.
    
      toc [TOC OPTION]...
      All options that can be specified for a page object can also be specified for
      a toc, further more the options from the TOC Options section can also be
      applied. The table of contents is generated via XSLT which means that it can
      be styled to look however you want it to look. To get an idea of how to do
      this you can dump the default xslt document by supplying the
      --dump-default-toc-xsl, and the outline it works on by supplying
      --dump-outline, see the Outline Options section.
    
    Description:
      Converts one or more HTML pages into a PDF document, *not* using wkhtmltopdf
      patched qt.
    
    Global Options:
          --collate                       Collate when printing multiple copies
                                          (default)
          --no-collate                    Do not collate when printing multiple
                                          copies
          --copies <number>               Number of copies to print into the pdf
                                          file (default 1)
      -H, --extended-help                 Display more extensive help, detailing
                                          less common command switches
      -g, --grayscale                     PDF will be generated in grayscale
      -h, --help                          Display help
          --license                       Output license information and exit
          --log-level <level>             Set log level to: none, error, warn or
                                          info (default info)
      -l, --lowquality                    Generates lower quality pdf/ps. Useful to
                                          shrink the result document space
      -O, --orientation <orientation>     Set orientation to Landscape or Portrait
                                          (default Portrait)
      -s, --page-size <Size>              Set paper size to: A4, Letter, etc.
                                          (default A4)
      -q, --quiet                         Be less verbose, maintained for backwards
                                          compatibility; Same as using --log-level
                                          none
          --read-args-from-stdin          Read command line arguments from stdin
          --title <text>                  The title of the generated pdf file (The
                                          title of the first document is used if not
                                          specified)
      -V, --version                       Output version information and exit
    
    Reduced Functionality:
      This version of wkhtmltopdf has been compiled against a version of QT without
      the wkhtmltopdf patches. Therefore some features are missing, if you need
      these features please use the static version.
    
      Currently the list of features only supported with patch QT includes:
    
     * Printing more than one HTML document into a PDF file.
     * Running without an X11 server.
     * Adding a document outline to the PDF file.
     * Adding headers and footers to the PDF file.
     * Generating a table of contents.
     * Adding links in the generated PDF file.
     * Printing using the screen media-type.
     * Disabling the smart shrink feature of WebKit.
    
    Contact:
      If you experience bugs or want to request new features please visit 
      <https://wkhtmltopdf.org/support.html>