[color=darkblue]Qual a melhor forma de se conveter uma página js ou html para PDF ?
Desde já agradeço ![/color]
[color=darkblue]Qual a melhor forma de se conveter uma página js ou html para PDF ?
Desde já agradeço ![/color]
[color=darkblue]Utilizei o código abaixo, ele relamente converte Html para PDF, porém com Strings pequenas, estou tentando adaptar a leitura dele, se alguém puder me ajudar, desde já agradeço : [/color]
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;
import org.w3c.dom.Document;
import org.w3c.tidy.Tidy;
import org.xhtmlrenderer.pdf.ITextRenderer;
import com.lowagie.text.DocumentException;
/**
*
* @author
*
*/
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);
}
public static void main(String[] args) {
OutputStream os;
try {
String temporario = "";
Scanner scanner = new Scanner(new FileReader(new File("C:/ext-2.2.1/tutorial.html")));
while(scanner.hasNext()){
temporario += scanner.next();
}
os = new FileOutputStream("C:\html2pdf.pdf");
Html2Pdf.convert(temporario, os);
// Html2Pdf.convert("<title>TESTE</title><h1 style=\"color:red\">ATÉ QUE ENFIM PDF !!!</h1>", os);
// Html2Pdf.convert("C:\Yahoo! Brasil.htm", os);
os.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Tidy (vers 4th August 2000) Parsing "InputStream"
line 1 column 43 - Warning: <linkrel> unexpected or duplicate quote mark
line 1 column 43 - Warning: <linkrel> unknown attribute value "text/css"
line 1 column 43 - Error: linkrel is not recognized!
line 1 column 43 - Warning: discarding unexpected linkrel
line 1 column 126 - Warning: <scripttype> unexpected or duplicate quote mark
line 1 column 126 - Warning: <scripttype> unknown attribute value "../ext-2.2.1/adapter/ext/ext-base.js"
line 1 column 126 - Error: <scripttype> is not recognized!
line 1 column 126 - Warning: discarding unexpected <scripttype>
line 1 column 198 - Warning: discarding unexpected </script>
line 1 column 207 - Warning: <scripttype> unexpected or duplicate quote mark
line 1 column 207 - Warning: <scripttype> unknown attribute value "../ext-2.2.1/ext-all.js"
line 1 column 207 - Error: <scripttype> is not recognized!
line 1 column 207 - Warning: discarding unexpected <scripttype>
line 1 column 266 - Warning: discarding unexpected </script>
line 1 column 275 - Warning: <styletype> unexpected or duplicate quote mark
line 1 column 275 - Warning: <styletype> unknown attribute value "null"
line 1 column 275 - Error: <styletype> is not recognized!
line 1 column 275 - Warning: discarding unexpected <styletype>
line 1 column 1.440 - Warning: discarding unexpected </style>
line 1 column 1.448 - Warning: <scripttype> unexpected or duplicate quote mark
line 1 column 1.448 - Warning: <scripttype> unknown attribute value "null"
line 1 column 1.448 - Error: <scripttype> is not recognized!
line 1 column 1.448 - Warning: discarding unexpected <scripttype>
line 1 column 1.875 - Warning: <divclass> unexpected or duplicate quote mark
line 1 column 1.875 - Warning: <divclass> unknown attribute value "null"
line 1 column 1.875 - Error: <divclass> is not recognized!
line 1 column 1.875 - Warning: discarding unexpected <divclass>
line 1 column 1.910 - Warning: discarding unexpected </div>
line 1 column 4.832 - Warning: discarding unexpected </script>
line 1 column 4.841 - Warning: </head> isn't allowed in <body> elements
line 1 column 4.848 - Warning: <body> isn't allowed in <body> elements
InputStream: Document content looks like HTML 3.2
31 warnings/errors were found!
This document has errors that must be fixed before
using HTML Tidy to generate a tidied up version.
[color=darkblue]Esse código foi tirado desse tópico, como já havia postado esse tópico, preferi deixar a dúvida aqui:[/color]