This is my code to create a pdf from java with itext pdf library which i succeed it. My problem now is that i can not add javascript code either from html when onload called or neither from java code . i dont got any exception. what i am doing wrong?is it possible to be achieved?
public class App {
public static final String src = "new.pdf";
public static final String HTML = "test.html";
public static void main(String[] args) throws IOException, DocumentException {
Document document = new Document();
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(src));
// writer.addJavaScript("<script>alert('asdas')</script>");
document.open();
document.setJavaScript_onLoad("yourFunction()");
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new FileInputStream(HTML));
document.close();
}
}
<html>
<head>
<style>.col{padding:3px 20px 3px 20px}</style>
<script type="text/javascript">
function yourFunction(){
alert('You clicked the bottom text');
}
</script>
</head>
<body style="font-family:tahoma" onload="yourFunction()">
<div style="background:rgb(230,230,230); padding:5px ;border:1px solid black;">
<b style="color:rgb(51,153,255)">Sample header</b>
<img style="float:right" height="25px" width="80px" src="resources/images/itext.png"/>
</div>
<br/>
<table border='0' style='border-collapse: collapse;'>
<tr>
<td class="col">String 1</td>
<td class="col">: 1234354545</td>
</tr>
<tr>
<td class="col">String 32</td>
<td class="col">: rere</td>
</tr>
<tr>
<td class="col">String 3</td>
<td class="col">: ureuiu</td>
</tr>
<tr>
<td class="col">Date</td>
<td class="col">: dfdfjkdjk</td>
</tr>
</table>
<br/>
<br/>
<br/>
<hr/>
<br/>
Contact us
</body>
</html>