PhantomJS Summary of HTML to PDF

Recently, you have to make a function of transferring PDF for our article. After comparing, I think PhantomJS is better to transform. How to use it now.

Download

can be downloaded by official website: official website

or Wget can also:

wget -p / tmp / https://bitbucket.org/riya/phantomjs/downloads/partomjs-2.1.1-linux-x86_64.tar.bz2

// Unzip TAR XJF /TMP/PHANTOMJS-2.1.1-Linux-x86_64.tar.bz2 -c / usr / Local /// Rename MV /usR/local/phantomjs-2.1.1-linux-x86_64 / usr / local / phantomjs // established soft connection ln -s / usr / local / phantomjs / bin / phantomjs / usr / local / BIN / now can perform PhantomJS -Version at the terminal to see if the installation is successful

   is now not enough, light phantomjs To transform, there will be some problems: 

Solution:

  • 1: Chinese garbled
  • yum -y install bitmap-fonts Bitmap-fonTS-CJK
  • 2: The font thick is inconsistent

This is the reason why CentOS does not exist, and can be imported into the font.

Installing Font Management Tools: Yum Install -y Fontconfig Mkfontscale

Access C: \ Windows \ FONTS, come out of the required font COPY. Then uploaded to / usr / share / fonts under the server


to perform the three commands of mkfontscale, mkfontdir, fc-cache -fv, and then restart the server (Reboot).

Code uses
  • Now, you can write code:
Import Phantom from ‘Phantom’; const pagetopdf = (URL) => {Phantom.create (). THEN ((pH) {ph.createpage (). Then ((page) => {Page.Open (URL) .Then ((status) ) => {// Configure the stored PDF address Page.Render (‘Stored address.pdf’). Then ((status) => {Console.log (‘Page Renred’); ph.exit ();}) ;});});};}; PageTopdf (‘https://www.tongbanjie.com “);

OK Now you can now deploy code to try it.
 Summary   
It is a small-editor to introduce the PHANTOMJS to export HTML to PDF, I hope to help everyone. If you have any questions, please leave a message, Xiaobian will reply to everyone. Thank you very much for your support of Tumi Cloud Website!
© Copyright Notice
THE END
Just support it if you like
like0
share
comment Grab the couch

Please log in to comment