PDF项目

福尔摩斯对我笑 2018-12-07 46817 次 15075条

参考gitHub: pdfjs 毕竟强大,但是主要靠把网页转成图片在转为PDF的方式,这样很多PDF里面都是图片,用户体验不好,pass

  • https://github.com/linwalker/render-html-to-pdf

puppeteer的实现方式

参考:https://www.cnblogs.com/dreamless/p/9673792.html https://www.jianshu.com/p/8e65fdcb6d85 https://juejin.im/post/5a68a501f265da3e54693f30

API文档: https://pptr.dev/ https://my.oschina.net/reamd7/blog/1634846 中文版: https://blog.csdn.net/deeplies/article/details/80861761#class-browserfetcher

删除PDF第一页的标题 ` @page:first {margin-top: 0;} body {margin-top: 1cm;}

`

页面页脚添加图片时,比较将图片转为base64编码格式,才能正常使用


var detalStr = /<div class=\"productLink\">[\s\S]*?<\/div>.*<div class=\"productMain\">/;
const sequenceStr = /<div class="show_sequence.*<\/a><\/div>/;
const Protocol = /<div ><a  >Request for protocol<\/a><\/div>/g;
(async () => {
var enDetail = fs.readFileSync("./en-detail.html","utf-8"); //获取html代码
enDetail = enDetail.replace(/[\r\n]/g,""); //去除换行和空格
enDetail = enDetail.replace(detalStr,`<div >`) //去除头信息
enDetail =enDetail.replace(/\/static\/main\/products\//g,"./").replace(detalStr,"").replace(sequenceStr, "").replace(Protocol, ""); //替换图片路径和其他内容
const browser = await puppeteer.launch();
const page = await browser.newPage();
var pp = await page.goto(`file:${path.join(__dirname)}`);
await page.setContent(enDetail); //设置PDF内容
//注意这个必须放到设置HTML之后
await page.addStyleTag
({
path: './en.css',
})

标签: 无

非特殊说明,本博所有文章均为博主原创。

上一篇
下一篇
头像也是LOGO
未来博客 博主大人
到了这个年纪,不应该再彷徨!

发表评论



 


已有 15075 条评论 1


  1. off white hoodie

    My husband and i were so joyful when Peter could finish off his survey through your precious recommendations he was given in your blog. It is now and again perplexing to simply always be handing out helpful hints that many many people might have been selling. Therefore we do know we now have the blog owner to thank because of that. The explanations you have made, the straightforward site menu, the friendships your site make it easier to create – it’s got everything remarkable, and it is leading our son and us do think the subject matter is fun, and that’s incredibly indispensable. Thank you for the whole lot!

    回复 2019年10月25日
  2. curry 6 shoes

    I want to voice my admiration for your kindness giving support to men who absolutely need assistance with the field. Your personal dedication to passing the solution across appeared to be certainly good and has consistently enabled men and women just like me to realize their aims. Your new insightful publication signifies so much a person like me and extremely more to my peers. Thanks a ton; from all of us.

    回复 2019年10月24日
  3. air max 2019

    I as well as my buddies have been examining the great information located on your web blog and then then I got an awful feeling I never expressed respect to the web site owner for those tips. These guys had been as a result warmed to study them and have in effect actually been loving these things. Thank you for getting really helpful and for having these kinds of essential topics most people are really needing to discover. My honest apologies for not saying thanks to you earlier.

    回复 2019年10月24日
  4. jordan shoes

    I have to express my thanks to you for rescuing me from this particular incident. Right after browsing through the world wide web and seeing proposals that were not productive, I believed my entire life was over. Living without the presence of strategies to the issues you have sorted out by means of your main article is a critical case, and those which may have in a negative way damaged my career if I hadn’t discovered your website. Your personal capability and kindness in playing with all the pieces was precious. I don’t know what I would have done if I hadn’t come upon such a solution like this. I am able to at this point relish my future. Thank you very much for your reliable and effective help. I will not be reluctant to suggest your web blog to any individual who desires support on this area.

    回复 2019年10月24日
  5. balenciaga

    I want to express some appreciation to you just for rescuing me from this type of problem. Because of browsing through the search engines and coming across basics that were not pleasant, I was thinking my life was well over. Being alive devoid of the strategies to the issues you have solved through this website is a crucial case, as well as ones which may have in a wrong way affected my career if I hadn’t noticed the blog. Your personal skills and kindness in maneuvering a lot of stuff was crucial. I am not sure what I would have done if I hadn’t come upon such a point like this. I can at this point relish my future. Thanks very much for this skilled and amazing help. I will not be reluctant to endorse your web sites to any individual who should receive guidelines on this issue.

    回复 2019年10月23日
  6. kyrie irving shoes

    I am just writing to make you know of the brilliant experience my friend’s daughter went through going through your site. She mastered many things, which include how it is like to possess a very effective giving heart to get folks clearly gain knowledge of some grueling subject matter. You undoubtedly exceeded people’s desires. Many thanks for producing these practical, healthy, edifying and even unique guidance on that topic to Julie.

    回复 2019年10月23日
  7. nfl jerseys

    I’m commenting to let you know of the awesome encounter our child obtained studying the blog. She noticed several things, which include what it is like to possess an awesome giving nature to get men and women clearly know a variety of specialized subject matter. You actually exceeded people’s expected results. Thanks for supplying the precious, dependable, informative not to mention cool thoughts on this topic to Evelyn.

    回复 2019年10月22日
  8. nike shoes

    I wish to express some thanks to this writer just for rescuing me from this type of matter. After scouting throughout the world-wide-web and finding things that were not helpful, I assumed my life was done. Being alive without the presence of strategies to the difficulties you have resolved all through this site is a serious case, as well as those which might have adversely affected my entire career if I had not discovered your blog. Your main talents and kindness in touching every aspect was tremendous. I am not sure what I would have done if I had not come across such a stuff like this. I’m able to now look forward to my future. Thanks for your time very much for your professional and results-oriented guide. I won’t think twice to propose the website to any individual who would like guidelines on this problem.

    回复 2019年10月21日
  9. golden goose outlet

    I and my buddies were actually checking out the good key points from your web page while suddenly I had a horrible feeling I had not thanked the website owner for those techniques. These young men are already absolutely thrilled to learn all of them and already have pretty much been taking advantage of these things. I appreciate you for simply being quite considerate and then for picking this kind of smart subject matter millions of individuals are really eager to understand about. My very own sincere regret for not saying thanks to sooner.

    回复 2019年10月20日
  10. jordan 13

    A lot of thanks for your own efforts on this site. Betty loves getting into internet research and it’s easy to see why. I know all of the lively way you produce practical tactics on your web blog and therefore foster participation from others about this theme plus our child is certainly starting to learn a great deal. Have fun with the rest of the year. You have been carrying out a tremendous job.

    回复 2019年10月19日
  11. jordan 12

    I enjoy you because of all your efforts on this web site. My aunt delights in conducting internet research and it’s really obvious why. I know all concerning the compelling manner you deliver invaluable tactics through your blog and even strongly encourage participation from other individuals on that subject so our favorite simple princess is certainly starting to learn so much. Take pleasure in the remaining portion of the year. You have been doing a pretty cool job.

    回复 2019年10月18日
  12. jimmy choo shoes

    I and also my guys were actually going through the excellent pointers located on your web blog then the sudden came up with a terrible suspicion I never expressed respect to the site owner for them. These boys had been for this reason stimulated to study them and have now seriously been taking advantage of those things. I appreciate you for getting indeed considerate and then for picking this sort of great subjects millions of individuals are really wanting to know about. Our own honest regret for not saying thanks to sooner.

    回复 2019年10月17日
  13. nike air max 2018

    I wanted to post you one little note to help give many thanks again over the gorgeous advice you have shared on this website. It is wonderfully generous of people like you in giving openly precisely what many individuals would’ve advertised for an e book to make some cash for their own end, chiefly considering the fact that you could have done it in case you desired. The basics as well worked to be the great way to be aware that other people have a similar zeal the same as my personal own to learn very much more with regards to this matter. I’m sure there are a lot more pleasurable situations ahead for many who browse through your website.

    回复 2019年10月16日
  14. yeezy

    I have to get across my affection for your kindness for folks that should have guidance on this important subject matter. Your real commitment to getting the solution all through ended up being amazingly good and have really helped men and women like me to reach their endeavors. Your entire warm and helpful guide denotes a lot to me and much more to my office colleagues. Many thanks; from everyone of us.

    回复 2019年10月15日
  15. off white

    I wanted to send you a tiny note to finally give thanks as before for all the pleasant concepts you have shown on this page. This has been so incredibly generous with you to grant publicly all that a few people would have supplied for an e book to help make some profit for themselves, specifically considering the fact that you might have done it in case you decided. These solutions in addition served to become a good way to fully grasp that the rest have a similar dream just like my own to see many more when it comes to this condition. I’m sure there are many more fun occasions in the future for individuals who discover your website.

    回复 2019年10月14日
  16. fila

    I wanted to send a brief comment in order to appreciate you for the magnificent ways you are writing on this site. My long internet search has now been paid with awesome concept to exchange with my visitors. I would tell you that most of us readers are really blessed to be in a good community with very many perfect professionals with good points. I feel very fortunate to have come across your entire webpage and look forward to so many more entertaining minutes reading here. Thanks a lot once more for a lot of things.

    回复 2019年10月14日
  17. StevDede

    Zithromax Dosing Chart Cialis Professional Generique 20 Mg Keflex 250 Mg viagra Priligy Forum 2013 Propecia Temples Levitra Italiano

    回复 2019年10月13日
  18. nike epic react flyknit

    I as well as my friends came analyzing the nice solutions found on the website and so suddenly I had a terrible feeling I never thanked the web site owner for them. Those boys are actually absolutely passionate to study them and have now extremely been loving them. I appreciate you for actually being quite kind as well as for choosing varieties of very good resources millions of individuals are really wanting to learn about. My personal honest regret for not expressing gratitude to you sooner.

    回复 2019年10月13日
  19. golden goose sneakers

    Thanks a lot for giving everyone such a special chance to discover important secrets from this website. It can be very excellent plus packed with a great time for me personally and my office co-workers to visit your blog at the very least three times weekly to read through the fresh things you have. And of course, I’m so actually contented concerning the attractive solutions you give. Some 2 facts on this page are ultimately the most effective I’ve had.

    回复 2019年10月12日
  20. nhl jerseys

    I truly wanted to send a message to thank you for all the pleasant tricks you are giving out on this website. My long internet look up has finally been paid with reputable facts and techniques to exchange with my best friends. I ‘d express that we website visitors actually are really lucky to dwell in a notable site with many wonderful individuals with beneficial opinions. I feel truly privileged to have seen your web page and look forward to some more pleasurable times reading here. Thanks once again for everything.

    回复 2019年10月11日
  21. nike air vapormax

    Needed to post you one tiny remark to help say thanks over again over the incredible techniques you’ve provided at this time. It was so particularly open-handed with people like you to present publicly all that many of us could have sold as an e-book in making some dough for their own end, mostly seeing that you might well have tried it in case you wanted. These good tips also acted as a great way to understand that some people have the identical desire the same as my personal own to figure out very much more with regard to this matter. Certainly there are several more fun times up front for those who examine your blog post.

    回复 2019年10月10日
  22. coach outlet

    I enjoy you because of every one of your labor on this blog. My aunt really loves carrying out research and it’s simple to grasp why. Most of us hear all regarding the compelling means you create very helpful guidelines by means of your web site and as well as increase response from people on this content plus our simple princess has been becoming educated so much. Enjoy the remaining portion of the new year. You are performing a remarkable job.

    回复 2019年10月9日
  23. moncler

    Thank you so much for providing individuals with an extraordinarily brilliant possiblity to check tips from this blog. It is always so terrific plus stuffed with a great time for me and my office peers to visit your web site at a minimum thrice in 7 days to read through the new things you will have. And of course, I’m so usually astounded with the effective creative ideas you give. Some 3 ideas in this posting are without a doubt the finest we have all ever had.

    回复 2019年10月8日
  24. nike shoes for women

    I actually wanted to type a small word in order to appreciate you for all the nice suggestions you are placing at this website. My time intensive internet lookup has at the end of the day been honored with wonderful strategies to talk about with my two friends. I ‘d claim that we visitors are undeniably endowed to be in a wonderful network with very many wonderful individuals with beneficial secrets. I feel truly fortunate to have encountered your site and look forward to many more thrilling moments reading here. Thanks a lot once again for all the details.

    回复 2019年10月7日