Olha, se for executado esse meu código vai aparecer estes [color=red]WARNINGS [/color].
[code]Tidy (vers 4th August 2000) Parsing “InputStream”
line 1 column 1 - Warning: inserting missing ‘title’ element
InputStream: Document content looks like HTML 2.0
1 warnings/errors were found!
plumbing.render INFO:: Using CSS implementation from: org.xhtmlrenderer.context.StyleReference
plumbing.load INFO:: TIME: parse stylesheets 312ms
plumbing.match INFO:: media = print
plumbing.match INFO:: Matcher created with 119 selectors[/code]
Mas são apenas ALERTAS. Se vc for no seu OutPut (C:\teste.pdf) o arquivo vai estar lá sim, pois o Tidy trata de corrigir esses erros sózinho.
Vai ai novamente meu códico completo e FUNCIONANDO!!
[code]package com.ederbaum.pdf;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
import org.xhtmlrenderer.pdf.ITextRenderer;
import com.lowagie.text.DocumentException;
/**
*/
public class Html2Pdf {
public static void convert(String input, OutputStream out) throws DocumentException{
convert(new ByteArrayInputStream(input.getBytes()), out);
}
public static void convert(InputStream input, OutputStream out) throws DocumentException{
Tidy tidy = new Tidy();
Document doc = tidy.parseDOM(input, null);
ITextRenderer renderer = new ITextRenderer();
renderer.setDocument(doc, null);
renderer.layout();
renderer.createPDF(out);
}
}[/code]
Ai vc usa assim, que VAI FUNCIONAR!!
Html2Pdf.convert("<h1>Hello PDF</h1>", new FileOutputStream("C:\\teste.pdf"));