将html文件转换为pdf

将html文件转换为pdf

本文介绍了如何将html文件转换为pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html报告,我想使用Java脚本转换为pdf格式.

实际上,用于将html文件转换为pdf的Java脚本代码.

谢谢.

I have a html report and i want to convert into pdf format using java script.

Indeed Java script code for converting html file into pdf.

Thanks.

推荐答案

// Example javascript script to convert the
// www.google.com web page to a PDF file

var conv = new ActiveXObject("pdfServMachine.converter");
conv.convert("http://www.google.com", "c:\\google.pdf", false);
WScript.Echo("finished conversion");




或尝试使用此方法..如果您不想要javascript

这是将本地html文件转换为pdf的代码段.
URL url = new File("test.html").toURI().toURL(); WebClient webClient =新的WebClient(); HtmlPage页面= webClient.getPage(url); OutputStream os = null;试试{os = new FileOutputStream("test.pdf"); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(page,url.toString()); renderer.layout(); renderer.createPDF(os); }最后{if(os!= null)os.close();

或也可以尝试一下.它会起作用....





or try this..if u dnt want javascript

here is a code snippet to convert a local html file to pdf.
URL url = new File("test.html").toURI().toURL(); WebClient webClient = new WebClient(); HtmlPage page = webClient.getPage(url); OutputStream os = null; try{ os = new FileOutputStream("test.pdf"); ITextRenderer renderer = new ITextRenderer(); renderer.setDocument(page,url.toString()); renderer.layout(); renderer.createPDF(os); } finally{ if(os != null) os.close();

or try this also..it will work....


Client Side - Minimum Code:
(NOT RECOMMENDED) security of reading / writing on client can prohibit client side generation

html = new html




这篇关于如何将html文件转换为pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 18:34