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:
Documentdocument=newDocument();StringinputFile="C:temp/Arquivo.rtf";// create a PDF writer to save the new document to diskPdfWriterwriter=PdfWriter.getInstance(document,newFileOutputStream("C:temp/ArquivoModificado.pdf"));// open the document for modificationsdocument.open();// create a new parser to load the RTF fileRtfParserparser=newRtfParser(null);// read the rtf file into a compatible documentparser.convertRtfDocument(newFileInputStream(inputFile),document);// save the pdf to diskdocument.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:
Documentdocument=newDocument();StringinputFile="C:temp/Arquivo.rtf";// create a PDF writer to save the new document to diskPdfWriterwriter=PdfWriter.getInstance(document,newFileOutputStream("C:temp/ArquivoModificado.pdf"));// open the document for modificationsdocument.open();// create a new parser to load the RTF fileRtfParserparser=newRtfParser(null);// read the rtf file into a compatible documentparser.convertRtfDocument(newFileInputStream(inputFile),document);// save the pdf to diskdocument.close();System.out.println("Finished");
Exibindo a seguinte mensagem:
The document is open; you can only add Elements with content.
A questão de estar gerando errado o pdf não tem problema, pois eu não estava conseguindo executar.
Vou tentar usar a versão 2.1.5.
K
kelly_hayashi
Pôxa, funcionou esse código?
Eu naõ consegui transformar um arquivo rtf em pdf!
F
fausto
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!
S
Scorsatto
o iText-rtf-2.1.5.jar esta implementado apenas para importar negrito? ou ele tambem importa italico e sublinhado?
Aqui só funcionou para o negrito.
M
mauriciomaculan
No meu sistema está gerando um pdf em branco, alguém sabe dizer o por quê?
veja o código:
importcom.lowagie.text.Document;importcom.lowagie.text.DocumentException;importcom.lowagie.text.pdf.PdfWriter;importcom.lowagie.text.rtf.parser.RtfParser;importjava.io.FileInputStream;importjava.io.FileNotFoundException;importjava.io.FileOutputStream;importjava.io.IOException;publicclassMain{publicvoidgerarPdf(StringinputFile,StringoutputFile){// create a new documentDocumentdocument=newDocument();// create a PDF writer to save the new document to disktry{PdfWriterwriter=PdfWriter.getInstance(document,newFileOutputStream(outputFile));}catch(FileNotFoundExceptione){// TODO Auto-generated catch blocke.printStackTrace();}catch(DocumentExceptione){// TODO Auto-generated catch blocke.printStackTrace();}// open the document for modificationsdocument.open();// create a new parser to load the RTF fileRtfParserparser=newRtfParser(null);// read the rtf file into a compatible documenttry{parser.convertRtfDocument(newFileInputStream(inputFile),document);}catch(FileNotFoundExceptione){// TODO Auto-generated catch blocke.printStackTrace();}catch(IOExceptione){// TODO Auto-generated catch blocke.printStackTrace();}// save the pdf to diskdocument.close();System.out.println("Finished");}publicstaticvoidmain(String[]args){Mainm=newMain();m.gerarPdf("D:/contrato.rtf","D:/ContratoModificado.pdf");}}
Na execução apresenta 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.(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)