In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will give you a detailed explanation on how to generate PDF. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
1. Generate PDF at the backend
Thinkphp uses the MPDF plug-in
Sample code:
Public function pdf () {
/ / introduce the class library
Vendor ('mpdf.mpdf')
/ / set Chinese coding
$mpdf=new\ mPDF ('zh-cn','A4', 0,' Song style', 0,0)
/ / html content
$html=' a PDF file'
$mpdf- > WriteHTML ($html)
$mpdf- > Output ()
Exit
}
two。 Use the command line to link web pages to generate PDF
Download wkhtmltox
Tool command link generated PDF file
. / wkhtmltox/bin/wkhtmltopdf http://www.baidu.com test.pdf
3. Using js to generate PDF
Introduce the following two js plug-ins
Html2canvas.js
Jspdf.debug.js
Sample code:
Function explode () {
$(".ncap-order-details") .css ("background-color",'# FFFFFF')
Html2canvas ($(".ncap-order-details"), {
Onrendered:function (canvas) {
Var pageData = canvas.toDataURL (1. 0)
Var pdf = new jsPDF ('', 'pt', 'a4')
Pdf.addImage (pageData, 'JPEG', 0, 0, 595.28, 592.28/canvas.width * canvas.height)
Pdf.save ('stone.pdf')
}
})
}
Principle: first take screenshots, then insert screenshots into PDF
$(".ncap-order-details") is the div area to be screenshot. The screenshot defaults to a transparent background, so set the background color in advance, and then save the screenshot to PDF.
This is the end of the article on "how to generate PDF". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.