Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript GimmeCode
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 23-Dec-10 23:33pm
Edited 27-Dec-10 2:14am
v3
Comments
Smithers-Jones at 24-Dec-10 5:37am
   
repost
Sandeep Mewara at 24-Dec-10 11:00am
   
Any effort?
Hiren Solanki at 27-Dec-10 8:14am
   
Removed excessive white space from question and some grammar fixing.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try this..!!!!!
 

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

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();
%>
  Permalink  
v2
Comments
yaprig at 29-Dec-10 2:38am
   
thnx Hiren
Hiren Solanki at 27-Dec-10 8:13am
   
Combined both of your answer.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 269
1 Peter Leow 205
2 OriginalGriff 200
3 _Amy 190
4 Andreas Gieriet 180
0 OriginalGriff 7,540
1 Sergey Alexandrovich Kryukov 6,412
2 Maciej Los 3,849
3 Peter Leow 3,653
4 CHill60 2,702


Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 27 Dec 2010
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100