Estou utilizando o Itext para conversão de um arquivo .rtf para .pdf.
O código abaixo está funcionando:
[code]public class GerarPdf implements Serializable {
public void gerarPdf(String inputFile , String outputFile){
// create a new document
Document document = new Document();
// create a PDF writer to save the new document to disk
try {
PdfWriter writer2 = PdfWriter.getInstance(document, new FileOutputStream(outputFile));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// open the document for modifications
document.open();
// create a new parser to load the RTF file
RtfParser parser = new RtfParser(null);
// read the rtf file into a compatible document
try {
parser.convertRtfDocument(new FileInputStream(inputFile), document);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// save the pdf to disk
document.close();
System.out.println("Finished");
}
[/code]
Porém o documento gerado é um texto limpo, sem tabelas ( e o conteudo que está dentro delas ).
O framework que uso é o Itext-Pdf 2.1.5 ( pois o 2.1.7 apresentou problemas de IllegalAcess e também tinha o mesmo erro ).
Gostaria de saber se alguem ja se deparou com esse erro, e também se existe alguma alternativa melhor ( com exemplo, por favor ) de como
poderia converter de rtf para pdf , ja que na net só encontrei recomendacoes de usar o Itext.
Também estou com este problema, já testei várias versões do itext para ver se era algum problema com as versões.
Cria-se um arquivo pdf, porém vazio.
No console aparece a seguinte mensagem:
run:
Exception in thread “main” java.lang.NullPointerException
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.importSystemFonts(Unknown Source)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.init(Unknown Source)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.setParser(Unknown Source)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationMgr.addDestination(Unknown Source)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordHandler.<init>(Unknown Source)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMap.<init>(Unknown Source)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMgr.<init>(Unknown Source)
at com.lowagie.text.rtf.parser.RtfParser.init(Unknown Source)
at com.lowagie.text.rtf.parser.RtfParser.convertRtfDocument(Unknown Source)
at converterrtfempdf.Main.gerarPdf(Main.java:38)
at converterrtfempdf.Main.main(Main.java:56)
Java Result: 1
CONSTRUÍDO COM SUCESSO (tempo total: 4 segundos)