Hello there,
i know that the rtf is not supported anymore but i hope you could help me
with a (i hope) easy problem (espacially for you ;) ).
I want to convert a RTF File into a PDF File in a very easy Java program.
My program should be used as a jar (or runable jar) just to take the
rtf-File and create a pdf-File after that delete the rtf and a Enterprise
Application Server will take this file and send it to the destinations.
Problem is i'll got the same NullPointerException:
I hope you would help me.
Thanks,
Best Regards
Bernhard
Heres the Exception:
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
at.xtention.converter.RtfToPdfConverter.rtftopdf(RtfToPdfConverter.java:59)
at
at.xtention.converter.RtfToPdfConverter.main(RtfToPdfConverter.java:34)
Heres the Source-Code:
package at.xtention.converter;
import com.lowagie.text.Document;
import com.lowagie.text.pdf.PdfWriter;
import com.lowagie.text.rtf.parser.RtfParser;
import com.lowagie.text.DocumentException;
import com.lowagie.text.PageSize;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.File;
public class RtfToPdfConverter {
public String dirname = "E:\\Program Files\\eclipse\\##TEST##\\";
public String filename = "Out\\PdfResult_" + (new
java.util.Date()).getTime() + ".pdf";
public String filename_rtf = "In\\in.rtf";
/**
* @param args
*/
public RtfToPdfConverter() {
init();
}
private void init(){
filename = "Out\\PdfResult_" + (new java.util.Date()).getTime() +
".pdf";
filename_rtf = "In\\in.rtf";
}
public static void main(String[] args) {
RtfToPdfConverter rtf = new RtfToPdfConverter();
rtf.rtftopdf("", "");
}
public void rtftopdf(String rtfPath, String pdfPath){
String dirname_pdf = dirname + filename;
String dirname_rtf = dirname + filename_rtf;
if(rtfPath != null && !rtfPath.trim().equals("")){
dirname_rtf = rtfPath;
}
if(pdfPath != null && !rtfPath.trim().equals("")){
dirname_pdf = pdfPath;
}
File rtf_file = new File(dirname_rtf );
System.out.println("Path rtf: "+ dirname_rtf );
Document doc = new Document( PageSize.A4, 50, 50, 50, 50 );
System.out.println( "Path pdf: " + dirname_pdf );
PdfWriter writer = null;
try {
writer = PdfWriter.getInstance( doc, new FileOutputStream(
dirname_pdf ) );
RtfParser pars = new RtfParser(new Document(PageSize.A4));
doc.addAuthor( "XT-Converter" );
doc.open();
FileInputStream rtf_fin = new FileInputStream( rtf_file );
if (rtf_fin != null && doc != null) {
pars.convertRtfDocument( rtf_fin, doc );
}
// doc.add( new Paragraph( new String (byteMessage)));
doc.close();
System.out.println( "finished parsing" );
} catch ( DocumentException e ) {
System.out.println( "DocumentException!");
System.err.println(e);
} catch ( FileNotFoundException e ) {
System.out.println( "FileNotFoundException! ");
System.err.println(e);
} catch ( IOException e ) {
System.out.println( "IOException!");
System.err.println(e);
}
}
}
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php