How to install wkhtmltopdf on a linux based (shared hosting) web server

后端 未结 11 1712
刺人心
刺人心 2020-11-30 17:58

I have tried in all ways to get wkhtmltopdf installed on our web server but unfortunately it is not getting installed. I cannot access user/bin folder as st

11条回答
  •  一生所求
    2020-11-30 19:00

    Place the wkhtmltopdf executable on the server and chmod it +x.

    Create an executable shell script wrap.sh containing:

    #!/bin/sh
    export HOME="$PWD"
    export LD_LIBRARY_PATH="$PWD/lib/"
    exec $@ 2>/dev/null
    #exec $@ 2>&1 # debug mode
    

    Download needed shared objects for that architecture and place them an a folder named "lib":

    • lib/libfontconfig.so.1
    • lib/libfontconfig.so.1.3.0
    • lib/libfreetype.so.6
    • lib/libfreetype.so.6.3.18
    • lib/libX11.so.6 lib/libX11.so.6.2.0
    • lib/libXau.so.6 lib/libXau.so.6.0.0
    • lib/libxcb.so.1 lib/libxcb.so.1.0.0
    • lib/libxcb-xlib.so.0
    • lib/libxcb-xlib.so.0.0.0
    • lib/libXdmcp.so.6
    • lib/libXdmcp.so.6.0.0
    • lib/libXext.so.6 lib/libXext.so.6.4.0

    (some of them are symlinks)

    … and you're ready to go:

    ./wrap.sh ./wkhtmltopdf-amd64 --page-size A4 --disable-internal-links --disable-external-links "http://www.example.site/" out.pdf
    

    If you experience font problems like squares for all the characters, define TrueType fonts explicitly:

    @font-face {
      font-family:Trebuchet MS;
      font-style:normal;
      font-weight:normal;
      src:url("http://www.yourserver.tld/fonts/Trebuchet_MS.ttf");
      format(TrueType);
    }
    

提交回复
热议问题