mac配置wkhtmltopdf

摘要:
安装依赖性:git、wget、gcc、xcode、X11.wkhtmltopdf是一个将html页面转换为pdf的工具。该公司参与将html转换为pdf/jpg的功能已有一段时间。我查了很多资料,在网上找到了以下两种方法:a)使用swt的面板。setPage(url)和Graphics2D;b) HtmlImageGenerator1)下载wkhtmltopdf qt$gitclone

安装依赖:git, wget, gcc, xcode, X11.


wkhtmltopdf是一个将html页面转成pdf的工具。

这段时间公司涉及到将html转成pdf/jpg的相关功能,我查了很多资料,网上大能找到的方法主要有以下两种:

a)利用swt的panel.setPage(url) 和Graphics2D结合

b)HtmlImageGenerator

1)下载wkhtmltopdf-qt 

$ git clone git://gitorious.org/+wkhtml2pdf/qt/wkhtmltopdf-qt.git
$ cd wkhtmltopdf-qt

2)编译wkhtmltopdf-qt(这阶段时间可能会比较久)

$ ./configure -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk -arch x86_64 -release -static -fast -exceptions -no-accessibility -no-stl -no-sql-ibase -no-sql-mysql -no-sql-odbc -no-sql-psql -no-sql-sqlite -no-sql-sqlite2 -no-qt3support -xmlpatterns -no-phonon -no-phonon-backend -webkit -no-scripttools -no-mmx -no-3dnow -no-sse -no-sse2 -no-ssse3 -qt-zlib -qt-libtiff -qt-libpng -qt-libmng -qt-libjpeg -openssl -graphicssystem raster -opensource -nomake "tools examples demos docs translations" -no-opengl -no-dbus -no-framework -no-dwarf2 -no-multimedia -no-declarative -largefile -rpath -no-nis -no-cups -no-iconv -no-pch -no-gtkstyle -no-nas-sound -no-sm -no-xshape -no-xinerama -no-xfixes -no-xrandr -no-xrender -no-mitshm -no-xkb -no-glib -no-openvg -no-xsync -no-javascript-jit -no-egl -carbon --prefix=../wkqt/
$ make -j3
$ make install

3)退出wkhtmltopdf-qt目录,此时会生成一个wkqt目录。下载并解压wkhtmltopdf-0.11.0_rc1.tar.bz2

$ wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1.tar.bz2
$ tar xvjf wkhtmltopdf-0.11.0_rc1.tar.bz2
$ rm wkhtmltopdf-0.11.0_rc1.tar.bz2
$ cd wkhtmltopdf-0.11.0_rc1

4)修改src/image/image.pro和src/pdf/pdf.pro文件 

macx {
#    CONFIG -= app_bundle
    CONFIG += x86_64
}

 5)保持在目录wkhtmltopdf-0.11.0_rc1,编译wkhtmltopdf和wkhtmltoimage

$ ../wkqt/bin/qmake
$ make
$ sudo make install

6)绑定生成/bin/wkhtmltopdf.app和/bin/wkhtmltoimage.app(这里需要用到qt里的资源文件)。

$ cd wkhtmltopdf-qt
$ sudo cp -pr src/gui/mac/qt_menu.nib /bin/wkhtmltopdf.app/Contents/Resources
$ sudo cp -pr src/gui/mac/qt_menu.nib /bin/wkhtmltoimage.app/Contents/Resources
$ sudo ln -s /bin/wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf /usr/local/bin
$ sudo ln -s /bin/wkhtmltoimage.app/Contents/MacOS/wkhtmltoimage /usr/local/bin

7)确定编译成功wkhtmltopdf --version 

timelyxyz-MacBook-Pro:bin apple$ wkhtmltopdf --version
Name:
  wkhtmltopdf 0.10.0 rc2

License:
  Copyright (C) 2010 wkhtmltopdf/wkhtmltoimage Authors.



  License LGPLv3+: GNU Lesser General Public License version 3 or later
  <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to
  change and redistribute it. There is NO WARRANTY, to the extent permitted by
  law.

Authors:
  Written by Jan Habermann, Christian Sciberras and Jakob Truelsen. Patches by
  Mehdi Abbad, Lyes Amazouz, Pascal Bach, Emmanuel Bouthenot, Benoit Garret and
  Mário Silva.

上面提到的swt的方法具体代码

/**
  * 根据构造函数内容将url抓屏后的页面生成图片放在file路径对应位置
  * 
  * @throws Exception
  */
  public String producePic() throws Exception {
      JEditorPane editorPane = new JEditorPane();
      editorPane.setEditable(false);
      editorPane.setPage(url);
      JScrollPane jsp = new JScrollPane(editorPane);
      getContentPane().add(jsp);
      this.setLocation(0, 0);
      this.setVisible(true);

      Thread.sleep(5 * 1000);

      setSize(10000, 10000);
      pack();
      BufferedImage image = new BufferedImage(editorPane.getWidth(),editorPane.getHeight(), BufferedImage.TYPE_INT_RGB);
      Graphics2D graphics2D = image.createGraphics();
      editorPane.paint(graphics2D);

      BufferedImage image1 = resize(image, 600, 400);

      ImageIO.write(image1, "jpg", file);
      dispose();
      return file.getName();
}

免责声明:文章转载自《mac配置wkhtmltopdf》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇个人 搭建 邮件服务器 使用ewomailORACLE 11GR2常用参数(含隐含参数)设置下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

CentOS7.6离线安装docker

2019/10/24,docker 摘要:CentOS 7.6中离线安装docker 18.06.3以及docker-compose 1.24.1 在线安装可参照 文档 Ubuntu18.04离线安装docker可以参考博客Ubuntu18.04通过deb包离线安装docker-ce 所需环境 1.CentOS 7.6,内核版本需要大于3.10(使用una...

解决node.js升级中遇到的问题,提示n: command not found

1,首先了解下什么是node.js 简单的说 Node.js 就是运行在服务端的 JavaScript。Node.js 是一个基于Chrome JavaScript 运行时建立的一个平台。Node.js是一个事件驱动I/O服务端JavaScript环境,基于Google的V8引擎,V8引擎执行Javascript的速度非常快,性能非常好。 2.升级原因。...

MySQL在linux上的rpm包方式安装方法

1、下载上传mysql server和client rpm包: [root@faspdev mnt]# ls MySQL-client-5.5.53-1.el6.x86_64.rpm MySQL-server-5.5.53-1.el6.x86_64.rpm 2、安装mysql数据库: 1)安装mysql server端rpm包: [root@faspdev...

Linux系统下查找安装包所在目录的六种方法

想知道Linux系统下安装了哪些软件包,以及软件包安装在哪个目录下,可以用以下6种命令 1. whichwhich命令查找出相关命令是否已经在搜索路径中,例子如下:$which gcc //显示出GNC的C编译器安装在哪个目录返回结果为:/usr/bin/gcc注意:如果which没有找到要找的命令,可以试试whereis,该命令搜索更大的范围的系统目录。...

ubuntu安装python3.6

ubuntu16.04自带python2.7和python3.5, 若需安装python 3.6: 先是sudo apt-install python3.6,报错:找不到python3.6安装包。 Reading package lists... Done Building dependency tree Reading state info...

如何在Ubuntu 20.04上安装Apache ZooKeeper

ZooKeeper是Apache软件基金会的一个软件项目,它提供了一个用于构建分布式应用的高性能共享数据服务。它被一个集群用来维护共享数据,并采用强大的同步技术。它提供了一个简单的接口,用于管理配置信息、命名、分布式同步和提供组服务。在本文中,我们将向您展示如何在Ubuntu 20.04服务器上安装Apache ZooKeeper。先决条件一台运行Ubun...