Ola pessoal,
Tenho uma pagina html e gostaria de imprimir ela pdf ela ja esta sendo imprimida,mais o problema q eu tenho é que ela não esta aceitando css,alguem tem algum exemplo de como usar css dentro da pagina html e o iText imprimir normalmente.
Obs: Eu sei que o iText não reconhece algumas tag’s CSS mais ele não esta reconhecendo nada;
segue o codigo.
Classe Main
public static void main(String[] args) throws FileNotFoundException, DocumentException {
Convert_HTML.convert(new FileInputStream(new File("C:\\Projeto\\ProvaGlobalizada.html")), new FileOutputStream("C:\\Projeto\\teste.pdf"));
}
Classe Convert_Html
public class Convert_HTML {
public static void convert(String input, OutputStream out) throws DocumentException{
Convert_HTML.convert(new ByteArrayInputStream(input.getBytes()), out);
}
public static void convert(InputStream input, OutputStream out) throws DocumentException{
Tidy tidy = new Tidy();
org.w3c.dom.Document doc = tidy.parseDOM(input, null);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument((org.w3c.dom.Document) doc, null);
renderer.layout();
renderer.createPDF(out);
}
}
Pagina Html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Teste</title>
</head>
<body>
<img src='file:///C:/Projeto/Cruzeiro.jpg' alt='teste imagem iText' />
<br />
<br />
<table bgcolor="#CCCCCC" >
<tr>
<td>TESTE PROVA GLOBALIZADA</td>
</tr>
<tr>
<td>TESTE PROVA GLOBALIZADA</td>
</tr>
<tr>
<td>TESTE PROVA GLOBALIZADA</td>
</tr>
</table>
</body>
</html>