Small null pointer issue.
In the class TextToPDF you set "doc" to null, you then pass it to
PDTrueTypeFont.loadTTF which eventually crashes with a
NullPointerException in the class PDStream. I am not exactly sure what
you intended here.
public class TextToPDF
...
public static void main(String[] args) throws IOException
{
TextToPDF app = new TextToPDF();
PDDocument doc = null;
try
{
if( args.length < 2 )
{
app.usage();
}
else
{
for( int i=0; i<args.length-2; i++ )
{
if( args[i].equals( "-standardFont" ))
{
i++;
app.setFont( PDType1Font.getStandardFont(
args[i] ));
}
else if( args[i].equals( "-ttf" ))
{
i++;
if (i < args.length && args[i] != null) {
PDTrueTypeFont font = PDTrueTypeFont.loadTTF(
doc, new File( args[i]));
app.setFont( font );
}
}
public static PDTrueTypeFont loadTTF( PDDocument doc, File file )
throws IOException
{
PDTrueTypeFont retval = new PDTrueTypeFont();
PDFontDescriptorDictionary fd = new
PDFontDescriptorDictionary();
PDStream fontStream = new PDStream(doc, new FileInputStream(
file ), false );
public PDStream( PDDocument doc, InputStream str, boolean filtered )
throws IOException
{
OutputStream output = null;
try // doc is null here in this path
{
stream = new COSStream( doc.getDocument().getScratchFile()
);