Package org.apache.pdfbox.tools
Class TextToPDF
- java.lang.Object
-
- org.apache.pdfbox.tools.TextToPDF
-
- All Implemented Interfaces:
java.util.concurrent.Callable<java.lang.Integer>
public class TextToPDF extends java.lang.Object implements java.util.concurrent.Callable<java.lang.Integer>This will take a text file and output a pdf with that text.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classTextToPDF.PageSizes
-
Field Summary
Fields Modifier and Type Field Description private floatbottomMarginprivate java.nio.charset.Charsetcharsetprivate static floatDEFAULT_FONT_SIZEThe default font sizeprivate static floatDEFAULT_LINE_HEIGHT_FACTORThe line height as a factor of the font sizeprivate static floatDEFAULT_MARGINThe default marginprivate PDFontfontprivate static intFONTSCALEThe scaling factor for font units to PDF unitsprivate floatfontSizeprivate java.io.Fileinfileprivate booleanlandscapeprivate floatleftMarginprivate floatlineSpacingprivate float[]marginsprivate PDRectanglemediaBoxprivate java.io.Fileoutfileprivate TextToPDF.PageSizespageSizeprivate floatrightMarginprivate Standard14Fonts.FontNamestandardFontprivate java.io.PrintStreamSYSERRprivate floattopMarginprivate java.io.Filettf
-
Constructor Summary
Constructors Constructor Description TextToPDF()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description java.lang.Integercall()PDDocumentcreatePDFFromText(java.io.Reader text)Create a PDF document with some text.voidcreatePDFFromText(PDDocument doc, java.io.Reader text)Create a PDF document with some text.floatgetBottomMargin()PDFontgetFont()intgetFontSize()floatgetLeftMargin()floatgetLineSpacing()PDRectanglegetMediaBox()Sets page size of produced PDF.floatgetRightMargin()floatgetTopMargin()booleanisLandscape()Tells the paper orientation.static voidmain(java.lang.String[] args)This will create a PDF document with some text in it.voidsetBottomMargin(float bottomMargin)voidsetFont(PDFont aFont)voidsetFontSize(float aFontSize)voidsetFontSize(int aFontSize)Deprecated.voidsetLandscape(boolean landscape)Sets paper orientation.voidsetLeftMargin(float leftMargin)voidsetLineSpacing(float lineSpacing)voidsetMediaBox(PDRectangle mediaBox)Sets page size of produced PDF.voidsetRightMargin(float rightMargin)voidsetTopMargin(float topMargin)
-
-
-
Field Detail
-
FONTSCALE
private static final int FONTSCALE
The scaling factor for font units to PDF units- See Also:
- Constant Field Values
-
DEFAULT_FONT_SIZE
private static final float DEFAULT_FONT_SIZE
The default font size- See Also:
- Constant Field Values
-
DEFAULT_LINE_HEIGHT_FACTOR
private static final float DEFAULT_LINE_HEIGHT_FACTOR
The line height as a factor of the font size- See Also:
- Constant Field Values
-
DEFAULT_MARGIN
private static final float DEFAULT_MARGIN
The default margin- See Also:
- Constant Field Values
-
mediaBox
private PDRectangle mediaBox
-
font
private PDFont font
-
SYSERR
private final java.io.PrintStream SYSERR
-
fontSize
private float fontSize
-
lineSpacing
private float lineSpacing
-
landscape
private boolean landscape
-
pageSize
private TextToPDF.PageSizes pageSize
-
charset
private java.nio.charset.Charset charset
-
margins
private float[] margins
-
standardFont
private Standard14Fonts.FontName standardFont
-
ttf
private java.io.File ttf
-
infile
private java.io.File infile
-
outfile
private java.io.File outfile
-
leftMargin
private float leftMargin
-
rightMargin
private float rightMargin
-
topMargin
private float topMargin
-
bottomMargin
private float bottomMargin
-
-
Method Detail
-
main
public static void main(java.lang.String[] args)
This will create a PDF document with some text in it.
see usage() for commandline- Parameters:
args- Command line arguments.
-
call
public java.lang.Integer call()
- Specified by:
callin interfacejava.util.concurrent.Callable<java.lang.Integer>
-
createPDFFromText
public PDDocument createPDFFromText(java.io.Reader text) throws java.io.IOException
Create a PDF document with some text.- Parameters:
text- The stream of text data.- Returns:
- The document with the text in it.
- Throws:
java.io.IOException- If there is an error writing the data.
-
createPDFFromText
public void createPDFFromText(PDDocument doc, java.io.Reader text) throws java.io.IOException
Create a PDF document with some text.- Parameters:
doc- The document.text- The stream of text data.- Throws:
java.io.IOException- If there is an error writing the data.
-
getFont
public PDFont getFont()
- Returns:
- Returns the font.
-
setFont
public void setFont(PDFont aFont)
- Parameters:
aFont- The font to set.
-
getFontSize
public int getFontSize()
- Returns:
- Returns the fontSize, truncated to integer.
-
setFontSize
@Deprecated public void setFontSize(int aFontSize)
Deprecated.- Parameters:
aFontSize- The fontSize to set.
-
setFontSize
public void setFontSize(float aFontSize)
- Parameters:
aFontSize- The fontSize to set.
-
getLineSpacing
public float getLineSpacing()
- Returns:
- Returns the lineSpacing.
-
setLineSpacing
public void setLineSpacing(float lineSpacing)
- Parameters:
lineSpacing- The lineSpacing to set.
-
getLeftMargin
public float getLeftMargin()
- Returns:
- Returns the left margin.
-
setLeftMargin
public void setLeftMargin(float leftMargin)
- Parameters:
leftMargin- The left margin to be set.
-
getRightMargin
public float getRightMargin()
- Returns:
- Returns the right margin.
-
setRightMargin
public void setRightMargin(float rightMargin)
- Parameters:
rightMargin- The right margin to be set.
-
getTopMargin
public float getTopMargin()
- Returns:
- Returns the top margin.
-
setTopMargin
public void setTopMargin(float topMargin)
- Parameters:
topMargin- The top margin to be set.
-
getBottomMargin
public float getBottomMargin()
- Returns:
- Returns the bottom margin.
-
setBottomMargin
public void setBottomMargin(float bottomMargin)
- Parameters:
bottomMargin- The bottom margin to be set.
-
getMediaBox
public PDRectangle getMediaBox()
Sets page size of produced PDF.- Returns:
- returns the page size (media box)
-
setMediaBox
public void setMediaBox(PDRectangle mediaBox)
Sets page size of produced PDF.- Parameters:
mediaBox-
-
isLandscape
public boolean isLandscape()
Tells the paper orientation.- Returns:
- true for landscape orientation
-
setLandscape
public void setLandscape(boolean landscape)
Sets paper orientation.- Parameters:
landscape- true for landscape orientation
-
-