You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2014/12/12 19:18:32 UTC
svn commit: r1645016 -
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java
Author: tilman
Date: Fri Dec 12 18:18:31 2014
New Revision: 1645016
URL: http://svn.apache.org/r1645016
Log:
PDFBOX-2559: Fix -ttf option, as done by John Hewson in the trunk
Modified:
pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java
Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java?rev=1645016&r1=1645015&r2=1645016&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/TextToPDF.java Fri Dec 12 18:18:31 2014
@@ -53,7 +53,21 @@ public class TextToPDF
*/
public PDDocument createPDFFromText( Reader text ) throws IOException
{
- PDDocument doc = null;
+ PDDocument doc = new PDDocument();
+ createPDFFromText(doc, text);
+ return doc;
+ }
+
+ /**
+ * Create a PDF document with some text.
+ *
+ * @param doc The PDF document that shall content the text.
+ * @param text The stream of text data.
+ *
+ * @throws IOException If there is an error writing the data.
+ */
+ public void createPDFFromText( PDDocument doc, Reader text ) throws IOException
+ {
try
{
@@ -62,7 +76,6 @@ public class TextToPDF
//calculate font height and increase by 5 percent.
height = height*fontSize*1.05f;
- doc = new PDDocument();
BufferedReader data = new BufferedReader( text );
String nextLine = null;
PDPage page = new PDPage();
@@ -156,7 +169,6 @@ public class TextToPDF
}
throw io;
}
- return doc;
}
/**
@@ -171,7 +183,7 @@ public class TextToPDF
public static void main(String[] args) throws IOException
{
TextToPDF app = new TextToPDF();
- PDDocument doc = null;
+ PDDocument doc = new PDDocument();
try
{
if( args.length < 2 )
@@ -203,7 +215,7 @@ public class TextToPDF
throw new IOException( "Unknown argument:" + args[i] );
}
}
- doc = app.createPDFFromText( new FileReader( args[args.length-1] ) );
+ app.createPDFFromText( doc, new FileReader( args[args.length-1] ) );
doc.save( args[args.length-2] );
}
}
@@ -213,10 +225,7 @@ public class TextToPDF
}
finally
{
- if( doc != null )
- {
- doc.close();
- }
+ doc.close();
}
}