首页 > 编程知识 正文

翻页电子书怎么转换成pdf,网页转pdf在线工具

时间:2023-05-03 17:11:25 阅读:44449 作者:4001

1 .依赖部署

compile (com.itext pdf : kernel :7.0.1 ) ) compile ) org.XHTML renderer : flying-saucer-pdf-itext 5336666

publicstaticfinalvoidhtmltopdf (字符串html content,字符串文件路径) throwsexception{newfile文件路径).get parent文件) 输出流文件流(try ) itextrenderertextrenderer=new file输出流(file path ); itextfontresolverfontresolver=text renderer.getfontresolver (; stringagreementbody=html content; //符号替换agreement body=agreement body.replace (' nbsp;' 、 agreement body=agreement body.replace (' ndash;' 、''; agreement body=agreement body.replace (' mdash;' 、 agreement body=agreement body.replace (' lsquo;' 、“”; //leftsinglequotationmarkagreementbody=协议主体. replace (rsquo; //rightsinglequotationmarkagreementbody=agreement body.replace (' sb quo;' 、 //single low-9 quotationmarkagreementbody=agreement body.replace (' ldquo;' 、" "、"; //leftdoublequotationmarkagreementbody=协议主体. replace (rdquo; //rightdoublequotationmarkagreementbody=agreement body.replace (' BD quo;' 、 //double low-9 quotationmarkagreementbody=agreement body.replace (' prime;' 、 //minutesagreementbody=agreement body.replace (' prime;' 、 //secondsagreementbody=agreement body.replace (' LSA quo;' 、 //singleleftanglequotationagreementbody=agreement body.replace (' RSA quo;' 、 //singlerightanglequotationagreementbody=agreement body.replace (' oline;' 、 //overlinefontresolver.addfont (/fonts/simsun.TTC ),com.itext pdf.kernel.pdf.pdf name.identity h.getvall vove textRenderer.layout (; text renderer.create pdf (filestream,true ); }3.使用速率模板引擎赋值

publicstaticvoidmain (字符串[ ] args ) Velocity对象velocityenginevelocityengine=newvelocityengine ); velocitycontextcontext=newvelocitycontext (; context.put('msg ','我是哈哈哈'); 字符串写入器=new string writer (; velocity engine.merge template ('资源/模板模板下存储的文件'、' utf-8 '、上下文、字符串写入器); String filePath='文件存储路径文件名'; try { pdf utils.htmltopdf (string writer.tostring )、destFilePath ); }catch(exceptione ) { log.error ) ',e ); }4.最后,可以在相应的文件目录中查看生成的PDF文件

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。