gostaria de saber como eu faço para converter um arquivo rtf em pdf usando itext 1.3.1 e itext-rtf 2.1.4
Estou usando o seguinte codigo:
Document document = new Document();
String inputFile = "C:temp/Arquivo.rtf";
// create a PDF writer to save the new document to disk
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:temp/ArquivoModificado.pdf"));
// 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
parser.convertRtfDocument(new FileInputStream(inputFile), document);
// save the pdf to disk
document.close();
System.out.println("Finished");
Exibindo a seguinte mensagem:
The document is open; you can only add Elements with content.
gostaria de saber como eu faço para converter um arquivo rtf em pdf usando itext 1.3.1 e itext-rtf 2.1.4
Estou usando o seguinte codigo:
Document document = new Document();
String inputFile = "C:temp/Arquivo.rtf";
// create a PDF writer to save the new document to disk
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:temp/ArquivoModificado.pdf"));
// 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
parser.convertRtfDocument(new FileInputStream(inputFile), document);
// save the pdf to disk
document.close();
System.out.println("Finished");
Exibindo a seguinte mensagem:
The document is open; you can only add Elements with content.
Att[/quote]
o problema esta aqui
String inputFile = "C:temp/Arquivo.rtf";
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:temp/ArquivoModificado.pdf"));
esta faltando a barra
String inputFile = "C:/temp/Arquivo.rtf";
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("C:/temp/ArquivoModificado.pdf"));
Testei o código acima mas estou com o seguinte erro.
Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.lowagie.text.Chunk.<init>()V from class com.lowagie.text.rtf.parser.destinations.RtfDestinationDocument
at com.lowagie.text.rtf.parser.destinations.RtfDestinationDocument.handleCloseGroup(Unknown Source)
at com.lowagie.text.rtf.parser.RtfParser.handleCloseGroup(Unknown Source)
at com.lowagie.text.rtf.parser.RtfParser.tokenise(Unknown Source)
at com.lowagie.text.rtf.parser.RtfParser.convertRtfDocument(Unknown Source)
at com.aton.rtf.RtfToPdf.CopyOfApp.main(CopyOfApp.java:28)
Pessoal alguém sabe como setar o charset neste exemplo? Eu tenho vários rtf’s e eles possuem acentos que geram caracteres errados no pdf final… Alias esse itext-rtf foi descontinuado?
Se alguém puder ajudar eu agradeço!
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 writer = 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");
}
public static void main(String[] args) {
Main m = new Main();
m.gerarPdf("D:/contrato.rtf", "D:/ContratoModificado.pdf");
}
}[/code]
Na execução apresenta a seguinte mensagem:
[quote]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.(Unknown Source)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMap.(Unknown Source)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMgr.(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)[/quote]