phantom.js - HTML To PDF

  1. import phantom from 'phantom';  
  2. const pageToPdf = (url) => {  
  3.  phantom.create().then((ph) {  
  4.  ph.createPage().then((page) => {  
  5.   page.open(url).then((status) => {  
  6.   // 配置存储的pdf地址  
  7.   page.render('存储的地址.pdf').then((status) => {  
  8.    console.log('Page rendered');  
  9.    ph.exit();  
  10.   });  
  11.   });  
  12.  });  
  13.  });  
  14. };  
  15. pageToPdf('https://www.tongbanjie.com');  

猜你喜欢

转载自www.cnblogs.com/mjian/p/9385703.html