简体   繁体   English

如何在 Mac OsX 10.7.3 上安装和运行 wkhtmltopdf 以在 PHP 应用程序中使用

[英]How To Install and Run wkhtmltopdf on Mac OsX 10.7.3 for use in a PHP Application

I've written a PHP/MySQL application that utilizes wkhtmltopdf to generate reports from data entered into the database.我编写了一个 PHP/MySQL 应用程序,它利用 wkhtmltopdf 从输入到数据库中的数据生成报告。 The client asked that I also install it to run as a standalone on a Mac that he has.客户要求我也安装它以在他拥有的 Mac 上独立运行。 Currently have the PHP/MySQL portion running without difficulty using XAMMP, but am having incredible difficulty getting wkhtmltopdf even installed on the system.目前使用 XAMMP 可以毫无困难地运行 PHP/MySQL 部分,但是即使在系统上安装 wkhtmltopdf 也遇到了令人难以置信的困难。

I have zero experience with Macs, and despite five hours of Googling and trying different approaches, I cannot even copy the most recent wkhtmltopdf .i386 into the /usr folder.我对 Mac 的体验为零,尽管使用了五个小时的谷歌搜索并尝试了不同的方法,但我什至无法将最新的 wkhtmltopdf .i386 复制到 /usr 文件夹中。 Oddly, the laptop doesn't have a /usr/local/bin folder.奇怪的是,笔记本电脑没有 /usr/local/bin 文件夹。

Unless I've missed it, I can't find simple instructions on how to get this thing working and would greatly appreciate any help that could be offered.除非我错过了它,否则我找不到有关如何使这件事正常工作的简单说明,并且非常感谢可以提供的任何帮助。

Homebrew only has wkhtmltopdf-0,9,9 and it fails with QT patched options by default. Homebrew 只有 wkhtmltopdf-0,9,9 并且默认情况下它会失败并带有 QT 补丁选项。 So if you need HEAD version with fully suppoorted options just因此,如果您需要具有完全支持选项的 HEAD 版本

  • Grab yourself a copy of fresh wkhtmltopdf给自己一份新鲜的 wkhtmltopdf
  • Open it and drag to Applications打开它并拖动到应用程序
  • Then cd /usr/local/bin && ln -s /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf wkhtmltopdf然后cd /usr/local/bin && ln -s /Applications/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf wkhtmltopdf

If you have Homebrew installed run: brew install wkhtmltopdf如果您安装了 Homebrew,请运行: brew install wkhtmltopdf

That will also install wkhtmltoimage.这也将安装 wkhtmltoimage。

Alternatively, you can download the compiled binaries from http://wkhtmltopdf.org/downloads.html and place them somewhere in your path like /usr/local/bin.或者,您可以从http://wkhtmltopdf.org/downloads.html下载已编译的二进制文件,并将它们放置在您的路径中的某个位置,例如 /usr/local/bin。 If you plan on running your script in another environment like a server or App Engine, this is the way to go.如果您计划在服务器或 App Engine 等其他环境中运行您的脚本,这就是您要走的路。

This seems to have easy to install packages:这似乎有易于安装的软件包:

http://wkhtmltopdf.org/downloads.html http://wkhtmltopdf.org/downloads.html

I successfully installed the OS X 10.6+ (Cocoa) 64-bit on my OSX 10.9.4 by simply running the pkg.我通过简单地运行 pkg 在我的 OSX 10.9.4 上成功安装了 OS X 10.6+ (Cocoa) 64 位。 Using it for the PDFKit Rails gem.将它用于 PDFKit Rails gem。

For anyone trying to use mikehaertl\\wkhtmlto\\Pdf with MAMP make sure you install the latest version for Mac http://wkhtmltopdf.org/downloads.html and define the binary parameter.对于尝试将 mikehaertl\\wkhtmlto\\Pdf 与 MAMP 一起使用的任何人,请确保为 Mac http://wkhtmltopdf.org/downloads.html安装最新版本并定义二进制参数。

$options = array(
    'page-size' => 'Letter',
    'orientation' => 'portrait',
    'binary' => '/usr/local/bin/wkhtmltopdf'
);

$pdf = new Pdf($options);

You will need to run the command in the terminal before the PDF creation:在创建 PDF 之前,您需要在终端中运行命令:

brew cask install wkhtmltopdf

When I create the PDF, I get this log in the server:当我创建 PDF 时,我在服务器中得到这个日志:

2020-05-31 17:20:10.657  INFO 11168 --- [io-8080-exec-10] c.g.jhonnymertz.wkhtmltopdf.wrapper.Pdf  : Initialized with {xvfbConfig=null, wkhtmltopdfCommand='/usr/local/bin/wkhtmltopdf'}
2020-05-31 17:20:20.166  INFO 11168 --- [io-8080-exec-10] c.g.jhonnymertz.wkhtmltopdf.wrapper.Pdf  : PDF successfully generated with: /usr/local/bin/wkhtmltopdf -B 0 -L 0 -R 0 -T 0 --page-width 148 --page-height 212 /var/folders/0c/_vpt6xnj71ng91nm9kk5jw3w0000gn/T/java-wkhtmltopdf-wrapper6721963b-6a8c-4260-9ac6-a545920d1ab117331429448032181725.html -

该命令对我很有效:

brew install --cask wkhtmltopdf

Lion (10.7) doesnt make /usr/local anymore, but you can create it. Lion (10.7) 不再创建/usr/local ,但您可以创建它。

If the package you want doesnt have a an installer for the binaries then you'll have to compile from source.如果你想要的包没有二进制文件的安装程序,那么你必须从源代码编译。 Im which case all the instructions you need should be available from the download site for the package.在这种情况下,您需要的所有说明都应该可以从软件包的下载站点获得。

The other option would be to see if its available in any of the OS X package managers (Fink, MacPorts, Homebrew).另一种选择是查看它是否在任何 OS X 包管理器(Fink、MacPorts、Homebrew)中可用。 If it is you could install everything that way.如果是这样,您可以以这种方式安装所有内容。 I can say its not in the MacPorts repository - i checked :-)我可以说它不在 MacPorts 存储库中 - 我检查了 :-)

UPDATE : Homebrew seems to have it...更新:Homebrew 似乎有它......

I was struggling to install wkhtmltopdf but after some research this helped me to install it on a MAC OSx我正在努力安装 wkhtmltopdf 但经过一些研究这帮助我将它安装在 MAC OSx 上

brew install wkhtmltopdf --cask

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM