如何在基于 Linux(共享主机)的 Web 服务器上安装 wkhtmltopdf

发布于 2024-08-21 16:54:59 字数 342 浏览 24 评论 0 原文

我已尝试各种方法在我们的网络服务器上安装 wkhtmltopdf 但不幸的是它没有安装。我无法访问 user/bin 文件夹,如安装教程中所述。

在服务器上的 public_html 文件夹中有一个子文件夹 _vti_bin,我从 wkhtmltopdf-0.9.1 复制了文件 wkhtmltopdf-i386 -static-i386,但我无法执行它。

如何在(共享托管)网络服务器上安装 wkhtmltopdf 并使其正常工作?

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 stated in a tutorial on installation.

On the server in public_html folder there is a sub folder _vti_bin, I copied the file wkhtmltopdf-i386 from wkhtmltopdf-0.9.1-static-i386, but I am not able to execute it.

How to install wkhtmltopdf on (shared hosting) web server and get it working?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

乖不如嘢 2024-08-28 16:54:59

我已成功在我的共享托管帐户上安装 wkhtmltopdf-amd64,无需 root 访问权限。

这就是我所做的:

从这里下载相关的静态二进制文件 v0.10.0: http://code .google.com/p/wkhtmltopdf/downloads/list

编辑:以上内容已移至此处

通过我的共享主机上的 ssh 输入以下内容:

$ wget {relavant url to binary from link above}
$ tar -xvf {filename of above wget'd file}

然后,您的主机上将拥有二进制文件,并且无论它是否位于 /usr/bin/ 文件夹中,都可以运行它。 (或者至少我能够)

测试:

$ ./wkhtmltopdf-amd64 http://www.example.com example.pdf
  • 请注意,如果您位于可执行文件所在的文件夹中,则可能应该在其前面加上 ./ 以确保万无一失。

无论如何为我工作

I've managed to successfully install wkhtmltopdf-amd64 on my shared hosting account without root access.

Here's what i did:

Downloaded the relevant static binary v0.10.0 from here: http://code.google.com/p/wkhtmltopdf/downloads/list

EDIT: The above has moved to here

via ssh on my shared host typed the following:

$ wget {relavant url to binary from link above}
$ tar -xvf {filename of above wget'd file}

you'll then have the binary on your host and will be able to run it regardless of if its in the /usr/bin/ folder or not. (or at least i was able to)

To test:

$ ./wkhtmltopdf-amd64 http://www.example.com example.pdf
  • Note remember that if you're in the folder in which the executable is, you should probably preface it with ./ just to be sure.

Worked for me anyway

思慕 2024-08-28 16:54:59

如果您有 sudo 访问权限...

Ubuntu 14.04 / 15.04 / 18.04:

sudo apt-get install wkhtmltopdf
# or
sudo apt install wkhtmltopdf

其他

查看其他答案。

If you have sudo access...

Ubuntu 14.04 / 15.04 / 18.04:

sudo apt-get install wkhtmltopdf
# or
sudo apt install wkhtmltopdf

Others

Look at the other answers.

偷得浮生 2024-08-28 16:54:59

如果是 ubuntu,则继续执行此操作,已经测试过。:--

首先,

sudo aptitude install openssl build-essential xorg libssl-dev

安装64 位操作系统的依赖项

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

为 32 位操作系统

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
 mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

If its ubuntu then go ahead with this, already tested.:--

first, installing dependencies

sudo aptitude install openssl build-essential xorg libssl-dev

for 64bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

for 32bits OS

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
 mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf
我恋#小黄人 2024-08-28 16:54:59

CentOS 最新更新:

  • sudo yum install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi
  • wget https://github.com/ wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz code>
  • sudo mv wkhtmltox/bin/* /usr/local/bin/
  • 检查安装是否成功: wkhtmltopdf -V
  • rm -rf wkhtmltox
  • rm -f wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

Latest update for CentOS:

  • sudo yum install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi
  • wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • tar -xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
  • sudo mv wkhtmltox/bin/* /usr/local/bin/
  • check installation success: wkhtmltopdf -V
  • rm -rf wkhtmltox
  • rm -f wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
遗弃M 2024-08-28 16:54:59

Debian 8 杰西
这有效
sudo apt-get install wkhtmltopdf

Debian 8 Jessie
This works
sudo apt-get install wkhtmltopdf

空城旧梦 2024-08-28 16:54:59

如果没有完全访问此服务器(由于是托管帐户),您很可能会遇到问题。我什至可以说,我认为这是徒劳的努力——他们必须有充分的理由将服务器锁定在托管环境中。

致电您的托管公司并向他们提出安装请求,但不要指望得到好的答复 - 他们通常不会为单个用户安装非常自定义的项目,除非有充分的理由(例如错误修复)。

最后,根据您对服务器管理的熟悉程度以及您为服务器托管支付的费用,现在考虑类似 http://www .slicehost.com。每月 20 美元将为您提供一个低级网络服务器(256 内存),您可以安装任何您想要的东西。但是,如果您正在运行多个站点或负载很重,则成本将会上升,因为您需要更大的服务器。

GL!

Chances are that without full access to this server (due to being a hosted account) you are going to have problems. I would go so far as to say that I think it is a fruitless endeavor--they have to lock servers down in hosted environments for good reason.

Call your hosting company and make the request to them to install it, but don't expect a good response--they typically won't install very custom items for single users unless there is a really good reason (bug fixes for example).

Lastly, depending on how familiar you are with server administration and what you are paying for server hosting now consider something like http://www.slicehost.com. $20 a month will get you a low grade web server (256 ram) and you can install anything you want. However, if you are running multiple sites or have heavy load the cost will go up as you need larger servers.

GL!

メ斷腸人バ 2024-08-28 16:54:59

自从添加了最热门的答案以来,一些事情发生了变化。它们曾经对我有用,但现在不再那么有效了,所以我花了一些时间,为 Ubuntu 16.04 提出了以下解决方案。对于 Ubuntu 14.04,请参阅答案底部的评论。如果这不适用于共享主机,我们深表歉意,但这似乎是一般 wkhtmltopdf 安装说明的转到答案。

# Install dependencies
apt-get install libfontconfig \
    zlib1g \
    libfreetype6 \
    libxrender1 \
    libxext6 \
    libx11-6

# TEMPORARY FIX! SEE: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001
apt-get install libssl1.0.0=1.0.2g-1ubuntu4.8
apt-get install libssl-dev=1.0.2g-1ubuntu4.8

# Download, extract and move binary in place
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xf wkhtmltopdf.tar.xz
mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

测试一下:

wkhtmltopdf http://www.google.com google.pdf

当前工作目录中现在应该有一个名为 google.pdf 的文件。

这种方法从网站下载二进制文件,这意味着您可以使用最新版本,而不必依赖包管理器进行更新。

请注意,截至今天,我的解决方案包括此错误的临时修复。我意识到这个解决方案确实不太好,但希望它能很快被删除。 在阅读此答案时,请务必检查链接的 GitHub 问题的状态,看看是否仍然需要修复!

对于 Ubuntu 14.04,您将需要降级到不同版本的 libssl。您可以在此处查找版本。无论如何,在任何生产服务器上执行降级 libssl 之前,请务必考虑降级的影响。

我希望这对某人有帮助!

A few things have changed since the top answers were added. They used to work out for me, but not quite anymore, so I have been hacking around for a bit and came up with the following solution for Ubuntu 16.04. For Ubuntu 14.04, see the comment at the bottom of the answer. Apologies if this doesn't work for shared hosting, but it seems like this is the goto answer for wkhtmltopdf installation instructions in general.

# Install dependencies
apt-get install libfontconfig \
    zlib1g \
    libfreetype6 \
    libxrender1 \
    libxext6 \
    libx11-6

# TEMPORARY FIX! SEE: https://github.com/wkhtmltopdf/wkhtmltopdf/issues/3001
apt-get install libssl1.0.0=1.0.2g-1ubuntu4.8
apt-get install libssl-dev=1.0.2g-1ubuntu4.8

# Download, extract and move binary in place
curl -L -o wkhtmltopdf.tar.xz https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar -xf wkhtmltopdf.tar.xz
mv wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

Test it out:

wkhtmltopdf http://www.google.com google.pdf

You should now have a file named google.pdf in the current working directory.

This approach downloads the binary from the website, meaning that you can use the latest version instead of relying on package managers to be updated.

Note that as of today, my solution includes a temporary fix to this bug. I realize that the solution is really not great, but hopefully it can be removed soon. Be sure to check the status of the linked GitHub issue to see if the fix is still necessary when you read this answer!

For Ubuntu 14.04, you will need to downgrade to a different version of libssl. You can find the versions here. Anyways, be sure to consider the implications of downgrading libssl before doing so on any production server.

I hope this helps someone!

浴红衣 2024-08-28 16:54:59

将 wkhtmltopdf 可执行文件放在服务器上并对其进行 chmod +x。

创建一个可执行 shell 脚本wrapp.sh,其中包含:

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

下载该体系结构所需的共享对象并将它们放置在名为“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

(其中一些是符号链接)

...然后您就可以开始了:

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

如果您遇到所有字符都出现方形等字体问题,请显式定义 TrueType 字体:

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

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);
}
千紇 2024-08-28 16:54:59

wkhtmltopdf 稳定版本列表: http://wkhtmltopdf.org/downloads.html

在 Debian 8.2 上安装 wkhtmltopdf (杰西)x64:

sudo apt-get install xfonts-75dpi
sudo apt-get install xfonts-base
sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-jessie-amd64.deb

List of stable versions wkhtmltopdf: http://wkhtmltopdf.org/downloads.html

Installing wkhtmltopdf on Debian 8.2 (jessie) x64:

sudo apt-get install xfonts-75dpi
sudo apt-get install xfonts-base
sudo wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
sudo dpkg -i wkhtmltox-0.12.2.1_linux-jessie-amd64.deb
笛声青案梦长安 2024-08-28 16:54:59

共享主机没有 ssh 或 shell 访问权限?

我是这样做的;

  1. 访问 https://wkhtmltopdf.org/downloads.html 并下载适用于 Linux 的适当稳定版本。对于我的情况,我选择了 32 位
    这是 wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  2. 解压缩到本地驱动器上的文件夹。
  3. 使用 FTP 程序将文件夹上传到 public_html(或任何适合您需要的位置),就像任何其他文件一样。
  4. 更改 snappy.php 文件中的二进制路径以指向您刚刚上传的文件夹中的相应文件。
    宾果!就这样,你就有了。您应该能够生成 PDF 文件。

Shared hosting no ssh or shell access?

Here is how i did it;

  1. Visit https://wkhtmltopdf.org/downloads.html and download the appropriate stable release for Linux. For my case I chose 32-bit
    which is wkhtmltox-0.12.4_linux-generic-i386.tar.xz
  2. Unzip to a folder on your local drive.
  3. Upload the folder to public_html (or whichever location fits your need) using an FTP program just like any other file(s)
  4. Change the binary paths in snappy.php file to point the appropriate files in the folder you just uploaded.
    Bingo! there you have it. You should be able to generate PDF files.
安穩 2024-08-28 16:54:59

尝试后,下面的命令对我有用

cd ~
yum install -y xorg-x11-fonts-75dpi xorg-x11-fonts-Type1 openssl git-core fontconfig
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
mv wkhtmltox/bin/wkhtmlto* /usr/bin

After trying, below command work for me

cd ~
yum install -y xorg-x11-fonts-75dpi xorg-x11-fonts-Type1 openssl git-core fontconfig
wget https://downloads.wkhtmltopdf.org/0.12/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
mv wkhtmltox/bin/wkhtmlto* /usr/bin
千笙结 2024-08-28 16:54:59

我在共享托管服务上安装 wkhtmltopdf 时也遇到了问题,没有 rpm、dnf、apt 或任何安装任何工具的工具,所以我升级到专用服务器并使用早期帖子中的知识进行安装,即
ssh 到新服务器

  1. cat /etc/os-release (确定服务器上运行的发行版 - 在我的例子中是 almalinux8)
  2. https://github.com/wkhtmltopdf/packaging/releases 并上传到新服务器
  3. dnf install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts -75dpi(预安装所有依赖项 - 重要!)
  4. rpm -i wkhtmltox-0.12.6.1-2.almalinux8.x86_64.rpm(安装软件包)
  5. wkhtmltopdf -V(测试安装)
  6. wkhtmltopdf http://www.google.com google.pdf(创建您的第一个 pdf)
  7. wkhtmltoimage http://www.google.com google.png (创建您的第一张图片)
  8. exec('wkhtmltoimage --allow . page.html image.png'); (在网站脚本中运行的 php 代码)
  9. 工作完成!

I also had a problem installing wkhtmltopdf on a shared hosting service with no rpm,dnf,apt or any tool to install anything with so instead I upgraded to a dedicated server and installed using knowledge found in earlier posts i.e.
ssh into new server

  1. cat /etc/os-release (to determine the distribution running on your server - in my case almalinux8)
  2. download package from https://github.com/wkhtmltopdf/packaging/releases and upload to new server
  3. dnf install -y libpng libjpeg openssl icu libX11 libXext libXrender xorg-x11-fonts-Type1 xorg-x11-fonts-75dpi (to pre-install all dependencies - important!)
  4. rpm -i wkhtmltox-0.12.6.1-2.almalinux8.x86_64.rpm (installs the package)
  5. wkhtmltopdf -V (test the installation)
  6. wkhtmltopdf http://www.google.com google.pdf (create your first pdf)
  7. wkhtmltoimage http://www.google.com google.png (crearte your first image)
  8. exec('wkhtmltoimage --allow . page.html image.png'); (php code to run in script on website)
  9. job done!
放飞的风筝 2024-08-28 16:54:59

wkhtmltopdf 12.5 版本现在仅在其下载页面上列出 DEB 文件。作为一名 Mac 用户,对 linux 或 DEB 文件了解不多,我无法使用发布的解决方案。

此页面帮助我克服了下载 DEB 文件的已知问题:http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/

基本上我做了什么是:

  1. https://wkhtmltopdf.org/downloads.html 下载
  2. 解压 DEB 文件。
  3. 解压 data.tar.xz
  4. 将二进制文件上传到步骤 3 中解压的“usr”文件夹中(usr/local/bin/wkhtmltopdf)

然后我发现“exec”功能在我的主机上被禁用。因此,如果您使用 PHP 来运行它,请确保您可以专门运行“exec”。 “我可以运行 wkhtmltopdf 二进制文件吗”不够具体。我的错。

Version 12.5 of wkhtmltopdf only lists DEB files on their download page now. Being a mac user and not knowing much linux or what DEB files were I couldn't use the solutions posted.

This page helped me get past the knew twist of downloading a DEB file: http://www.g-loaded.eu/2008/01/28/how-to-extract-rpm-or-deb-packages/

Basically what I did was:

  1. Downloaded from https://wkhtmltopdf.org/downloads.html
  2. Unzipped the DEB file.
  3. Unzipped data.tar.xz
  4. Uploaded the binary in the unzipped 'usr' folder from step 3 (usr/local/bin/wkhtmltopdf)

Then I found out that the 'exec' function was disabled on my host. So make sure you can specifically run 'exec' if you're using PHP to run this. "Can I run the wkhtmltopdf binary" isn't specific enough. My fault.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文