Package org.apache.pdfbox.tools
Class TextToPDF
java.lang.Object
org.apache.pdfbox.tools.TextToPDF
This will take a text file and output a pdf with that text.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final PDType1Font
The default fontprivate static final int
The default font sizeprivate PDFont
private static final int
The scaling factor for font units to PDF unitsprivate int
private boolean
private static final float
The line height as a factor of the font sizeprivate PDRectangle
private static final Map<String,
PDType1Font> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncreatePDFFromText
(Reader text) Create a PDF document with some text.void
createPDFFromText
(PDDocument doc, Reader text) Create a PDF document with some text.private static PDRectangle
createRectangle
(String paperSize) getFont()
int
Sets page size of produced PDF.private static String[]
This will get the names of the standard 14 fonts.private static PDType1Font
getStandardFont
(String name) A convenience method to get one of the standard 14 font from name.boolean
Tells the paper orientation.static void
This will create a PDF document with some text in it.void
void
setFontSize
(int aFontSize) void
setLandscape
(boolean landscape) Sets paper orientation.void
setMediaBox
(PDRectangle mediaBox) Sets page size of produced PDF.private void
usage()
This will print out a message telling how to use this example.
-
Field Details
-
FONTSCALE
private static final int FONTSCALEThe scaling factor for font units to PDF units- See Also:
-
DEFAULT_FONT
The default font -
DEFAULT_FONT_SIZE
private static final int DEFAULT_FONT_SIZEThe default font size- See Also:
-
LINE_HEIGHT_FACTOR
private static final float LINE_HEIGHT_FACTORThe line height as a factor of the font size- See Also:
-
fontSize
private int fontSize -
mediaBox
-
landscape
private boolean landscape -
font
-
STANDARD_14
-
-
Constructor Details
-
TextToPDF
public TextToPDF()
-
-
Method Details
-
createPDFFromText
Create a PDF document with some text.- Parameters:
text
- The stream of text data.- Returns:
- The document with the text in it.
- Throws:
IOException
- If there is an error writing the data.
-
createPDFFromText
Create a PDF document with some text.- Parameters:
doc
- The document.text
- The stream of text data.- Throws:
IOException
- If there is an error writing the data.
-
main
This will create a PDF document with some text in it.
see usage() for commandline- Parameters:
args
- Command line arguments.- Throws:
IOException
- If there is an error with the PDF.
-
createRectangle
-
usage
private void usage()This will print out a message telling how to use this example. -
getStandardFont
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
This will get the names of the standard 14 fonts.- Returns:
- An array of the names of the standard 14 fonts.
-
getFont
- Returns:
- Returns the font.
-
setFont
- 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
Sets page size of produced PDF.- Returns:
- returns the page size (media box)
-
setMediaBox
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
-