Package org.apache.pdfbox.tools
Class TextToPDF
- java.lang.Object
-
- org.apache.pdfbox.tools.TextToPDF
-
public class TextToPDF extends java.lang.ObjectThis will take a text file and output a pdf with that text.
-
-
Field Summary
Fields Modifier and Type Field Description private static PDType1FontDEFAULT_FONTThe default fontprivate static intDEFAULT_FONT_SIZEThe default font sizeprivate PDFontfontprivate static intFONTSCALEThe scaling factor for font units to PDF unitsprivate intfontSizeprivate booleanlandscapeprivate static floatLINE_HEIGHT_FACTORThe line height as a factor of the font sizeprivate PDRectanglemediaBoxprivate static java.util.Map<java.lang.String,PDType1Font>STANDARD_14
-
Constructor Summary
Constructors Constructor Description TextToPDF()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.private static PDRectanglecreateRectangle(java.lang.String paperSize)PDFontgetFont()intgetFontSize()PDRectanglegetMediaBox()Sets page size of produced PDF.private static java.lang.String[]getStandard14Names()This will get the names of the standard 14 fonts.private static PDType1FontgetStandardFont(java.lang.String name)A convenience method to get one of the standard 14 font from name.booleanisLandscape()Tells the paper orientation.static voidmain(java.lang.String[] args)This will create a PDF document with some text in it.voidsetFont(PDFont aFont)voidsetFontSize(int aFontSize)voidsetLandscape(boolean landscape)Sets paper orientation.voidsetMediaBox(PDRectangle mediaBox)Sets page size of produced PDF.private voidusage()This will print out a message telling how to use this example.
-
-
-
Field Detail
-
FONTSCALE
private static final int FONTSCALE
The scaling factor for font units to PDF units- See Also:
- Constant Field Values
-
DEFAULT_FONT
private static final PDType1Font DEFAULT_FONT
The default font
-
DEFAULT_FONT_SIZE
private static final int DEFAULT_FONT_SIZE
The default font size- See Also:
- Constant Field Values
-
LINE_HEIGHT_FACTOR
private static final float LINE_HEIGHT_FACTOR
The line height as a factor of the font size- See Also:
- Constant Field Values
-
fontSize
private int fontSize
-
mediaBox
private PDRectangle mediaBox
-
landscape
private boolean landscape
-
font
private PDFont font
-
STANDARD_14
private static final java.util.Map<java.lang.String,PDType1Font> STANDARD_14
-
-
Method Detail
-
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.
-
main
public static void main(java.lang.String[] args) throws java.io.IOExceptionThis will create a PDF document with some text in it.
see usage() for commandline- Parameters:
args- Command line arguments.- Throws:
java.io.IOException- If there is an error with the PDF.
-
createRectangle
private static PDRectangle createRectangle(java.lang.String paperSize)
-
usage
private void usage()
This will print out a message telling how to use this example.
-
getStandardFont
private static PDType1Font getStandardFont(java.lang.String name)
A convenience method to get one of the standard 14 font from name.- Parameters:
name- The name of the font to get.- Returns:
- The font that matches the name or null if it does not exist.
-
getStandard14Names
private static java.lang.String[] getStandard14Names()
This will get the names of the standard 14 fonts.- Returns:
- An array of the names of the standard 14 fonts.
-
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.
-
setFontSize
public void setFontSize(int aFontSize)
- Parameters:
aFontSize- The fontSize to 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
-
-