Click here to Skip to main content
14,977,821 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
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.
Posted
Updated 27-Dec-10 2:14am
v3
Comments
Smithers-Jones 24-Dec-10 5:37am
   
repost
Sandeep Mewara 24-Dec-10 11:00am
   
Any effort?
Hiren solanki 27-Dec-10 8:14am
   
Removed excessive white space from question and some grammar fixing.
Member 12087416 26-Oct-15 6:55am
   
How we export a html form to pdf using only pure javascript..NOt OTHER languages.I don't wanted to add any plugins/libraries to my code

1 solution

Try this..!!!!!


C#
// 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");



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....


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

html = new html$()
pdf = new pdf$();

html.parse("<B> Hello World</B>");
html.writeToPdf(pdf);

pdf.writeToFile('c:/temp/hello_world.pdf');
window.open('file://c:/temp/hello_world.pdf');

Server Side - Minimum ASP Code:

<%@ language=javascript%>
<script SRC="collinsPdf.js" language="JavaScript" runat="Server"></script>
<script SRC="collinsHtml.js" language="JavaScript" runat="Server"></script>
<%
   html = new html$();
   pdf = new pdf$();

   html.parse("The Date is: <b><i>" + new Date() + "</i></B>");
   html.writeToPdf(pdf);
   pdf.sendToClient();
%>
   
v2
Comments
Hiren solanki 27-Dec-10 8:13am
   
Combined both of your answer.
yaprig 29-Dec-10 2:38am
   
thnx Hiren
Member 12087416 26-Oct-15 6:49am
   
useless answer .What he can asked what u can tell .He clearly mentioned using javascript .But again u can explain in some other languages.From what useful to anyone.Nothing Please give answer related or directly if possible otherwise don't give any answers this is my request mainly to @@@@@yapring.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900