I Want to print html as a pdf. Here is my code. It was not throwing any error but when i open pdf it is showing error
Here is my java code
URL u = new URL("http://localhost/printPdf.Html");
URLConnection uc = u.openConnection();
BufferedInputStream is = new BufferedInputStream(uc.getInputStream());
File outs = new File("D:/HtmlToPdf.pdf")
BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(outs));
byte[] b = new byte[8 * 1024];
int read = 0;
while ((read = is.read(b)) > -1) {
bout.write(b, 0, read);
}
bout.flush();
bout.close();
is.close();
Here is my html file
<html>
<head></head>
<body><div>Hi !!! Example PDF </div></body>
</html>
When i open pdf i am getting this error
Adobe Reader could not open because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly decoded).