Top Description Inners Fields Constructors Methods
org.apache.pdfbox.tools

public Class TextToPDF

extends Object
implements Callable<Integer>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Annotations
@Command
name:texttopdf
header:Creates a PDF document from text
versionProvider:Version
mixinStandardHelpOptions:true
Imports
java.io.BufferedReader, .File, .FileInputStream, .IOException, .InputStream, .InputStreamReader, .PrintStream, .Reader, java.nio.charset.Charset, .StandardCharsets, java.util.concurrent.Callable, org.apache.pdfbox.pdmodel.PDDocument, .PDPage, .PDPageContentStream, org.apache.pdfbox.pdmodel.common.PDRectangle, org.apache.pdfbox.pdmodel.font.PDFont, .PDType0Font, .PDType1Font, .Standard14Fonts.FontName, picocli.CommandLine, .CommandLine.Command, .CommandLine.Option

This will take a text file and output a pdf with that text.
Author
Ben Litchfield

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private float
private Charset
private static final float
DEFAULT_FONT_SIZE

The default font size

private static final float
DEFAULT_LINE_HEIGHT_FACTOR

The line height as a factor of the font size

private static final float
DEFAULT_MARGIN

The default margin

private PDFont
private static final int
FONTSCALE

The scaling factor for font units to PDF units

private float
private File
private boolean
private float
private float
private float[]
private PDRectangle
private File
private TextToPDF.PageSizes
private float
private Standard14Fonts.FontName
private final PrintStream
private float
private File

Constructor Summary

AccessConstructor and Description
public
TextToPDF()

Constructor.

Method Summary

Modifier and TypeMethod and Description
public Integer
call()

Implements java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

public PDDocument

Returns:

The document with the text in it.
createPDFFromText
(Reader
The stream of text data.
text
)

Create a PDF document with some text.

public void
createPDFFromText(PDDocument
The document.
doc
,
Reader
The stream of text data.
text
)

Create a PDF document with some text.

public float

Returns:

Returns the bottom margin.
getBottomMargin
()

public PDFont

Returns:

Returns the font.
getFont
()

public int

Returns:

Returns the fontSize, truncated to integer.
getFontSize
()

public float

Returns:

Returns the left margin.
getLeftMargin
()

public float

Returns:

Returns the lineSpacing.
getLineSpacing
()

public PDRectangle

Returns:

returns the page size (media box)
getMediaBox
()

Sets page size of produced PDF.

public float

Returns:

Returns the right margin.
getRightMargin
()

public float

Returns:

Returns the top margin.
getTopMargin
()

public boolean

Returns:

true for landscape orientation
isLandscape
()

Tells the paper orientation.

public static void
main(String[]
Command line arguments.
args
)

This will create a PDF document with some text in it.

public void
setBottomMargin(float
The bottom margin to be set.
bottomMargin
)

public void
setFont(PDFont
The font to set.
aFont
)

public void
setFontSize(int
The fontSize to set.
aFontSize
)
Deprecated use setFontSize(float)

public void
setFontSize(float
The fontSize to set.
aFontSize
)

public void
setLandscape(boolean
true for landscape orientation
landscape
)

Sets paper orientation.

public void
setLeftMargin(float
The left margin to be set.
leftMargin
)

public void
setLineSpacing(float
The lineSpacing to set.
lineSpacing
)

public void
setMediaBox(PDRectangle mediaBox)

Sets page size of produced PDF.

public void
setRightMargin(float
The right margin to be set.
rightMargin
)

public void
setTopMargin(float
The top margin to be set.
topMargin
)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bottomMarginback to summary
private float bottomMargin
charsetback to summary
private Charset charset
Annotations
@Option
names:-charset
description:the charset to use. (default: ${DEFAULT-VALUE})
DEFAULT_FONT_SIZEback to summary
private static final float DEFAULT_FONT_SIZE

The default font size

DEFAULT_LINE_HEIGHT_FACTORback to summary
private static final float DEFAULT_LINE_HEIGHT_FACTOR

The line height as a factor of the font size

DEFAULT_MARGINback to summary
private static final float DEFAULT_MARGIN

The default margin

fontback to summary
private PDFont font
FONTSCALEback to summary
private static final int FONTSCALE

The scaling factor for font units to PDF units

fontSizeback to summary
private float fontSize
Annotations
@Option
names:-fontSize
description:the size of the font to use (default: ${DEFAULT-VALUE})
infileback to summary
private File infile
Annotations
@Option
names:-i, --input
description:the text file to convert
required:true
landscapeback to summary
private boolean landscape
Annotations
@Option
names:-landscape
description:set orientation to landscape
leftMarginback to summary
private float leftMargin
lineSpacingback to summary
private float lineSpacing
Annotations
@Option
names:-lineSpacing
description:the factor of the font size for the line height (default: ${DEFAULT-VALUE})
marginsback to summary
private float[] margins
Annotations
@Option
names:-margins
arity:0..4
description:Left Right Top Bottom margins (default: ${DEFAULT-VALUE})
mediaBoxback to summary
private PDRectangle mediaBox
outfileback to summary
private File outfile
Annotations
@Option
names:-o, --output
description:the generated PDF file
required:true
pageSizeback to summary
private TextToPDF.PageSizes pageSize
Annotations
@Option
names:-pageSize
description:the page size to use. Candidates: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE})
rightMarginback to summary
private float rightMargin
standardFontback to summary
private Standard14Fonts.FontName standardFont
Annotations
@Option
names:-standardFont
description:the font to use for the text. Either this or -ttf should be specified but not both. Candidates: ${COMPLETION-CANDIDATES} (default: ${DEFAULT-VALUE})
SYSERRback to summary
private final PrintStream SYSERR
Annotations
@SuppressWarnings:squid:S106
topMarginback to summary
private float topMargin
ttfback to summary
private File ttf
Annotations
@Option
names:-ttf
paramLabel:
description:the TTF font to use for the text. Either this or -standardFont should be specified but not both.

Constructor Detail

TextToPDFback to summary
public TextToPDF()

Constructor.

Method Detail

callback to summary
public Integer call()

Implements java.util.concurrent.Callable.call.

Doc from java.util.concurrent.Callable.call.

Computes a result, or throws an exception if unable to do so.

Returns:Integer

computed result

Annotations
@Override
createPDFFromTextback to summary
public PDDocument createPDFFromText(Reader text) throws IOException

Create a PDF document with some text.

Parameters
text:Reader

The stream of text data.

Returns:PDDocument

The document with the text in it.

Exceptions
IOException:
If there is an error writing the data.
createPDFFromTextback to summary
public void createPDFFromText(PDDocument doc, Reader text) throws IOException

Create a PDF document with some text.

Parameters
doc:PDDocument

The document.

text:Reader

The stream of text data.

Exceptions
IOException:
If there is an error writing the data.
getBottomMarginback to summary
public float getBottomMargin()
Returns:float

Returns the bottom margin.

getFontback to summary
public PDFont getFont()
Returns:PDFont

Returns the font.

getFontSizeback to summary
public int getFontSize()
Returns:int

Returns the fontSize, truncated to integer.

getLeftMarginback to summary
public float getLeftMargin()
Returns:float

Returns the left margin.

getLineSpacingback to summary
public float getLineSpacing()
Returns:float

Returns the lineSpacing.

getMediaBoxback to summary
public PDRectangle getMediaBox()

Sets page size of produced PDF.

Returns:PDRectangle

returns the page size (media box)

getRightMarginback to summary
public float getRightMargin()
Returns:float

Returns the right margin.

getTopMarginback to summary
public float getTopMargin()
Returns:float

Returns the top margin.

isLandscapeback to summary
public boolean isLandscape()

Tells the paper orientation.

Returns:boolean

true for landscape orientation

mainback to summary
public static void main(String[] args)

This will create a PDF document with some text in it.
see usage() for commandline

Parameters
args:String[]

Command line arguments.

setBottomMarginback to summary
public void setBottomMargin(float bottomMargin)
Parameters
bottomMargin:float

The bottom margin to be set.

setFontback to summary
public void setFont(PDFont aFont)
Parameters
aFont:PDFont

The font to set.

setFontSizeback to summary
public void setFontSize(int aFontSize)

Deprecated

use setFontSize(float)

Parameters
aFontSize:int

The fontSize to set.

Annotations
@Deprecated
setFontSizeback to summary
public void setFontSize(float aFontSize)
Parameters
aFontSize:float

The fontSize to set.

setLandscapeback to summary
public void setLandscape(boolean landscape)

Sets paper orientation.

Parameters
landscape:boolean

true for landscape orientation

setLeftMarginback to summary
public void setLeftMargin(float leftMargin)
Parameters
leftMargin:float

The left margin to be set.

setLineSpacingback to summary
public void setLineSpacing(float lineSpacing)
Parameters
lineSpacing:float

The lineSpacing to set.

setMediaBoxback to summary
public void setMediaBox(PDRectangle mediaBox)

Sets page size of produced PDF.

setRightMarginback to summary
public void setRightMargin(float rightMargin)
Parameters
rightMargin:float

The right margin to be set.

setTopMarginback to summary
public void setTopMargin(float topMargin)
Parameters
topMargin:float

The top margin to be set.

org.apache.pdfbox.tools back to summary

private final Enum TextToPDF.PageSizes

extends Enum<TextToPDF.PageSizes>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
public static final TextToPDF.PageSizes
pack-priv final PDRectangle

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public PDRectangle
public static TextToPDF.PageSizes
public static TextToPDF.PageSizes[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

A0back to summary
public static final TextToPDF.PageSizes A0
A1back to summary
public static final TextToPDF.PageSizes A1
A2back to summary
public static final TextToPDF.PageSizes A2
A3back to summary
public static final TextToPDF.PageSizes A3
A4back to summary
public static final TextToPDF.PageSizes A4
A5back to summary
public static final TextToPDF.PageSizes A5
A6back to summary
public static final TextToPDF.PageSizes A6
LEGALback to summary
public static final TextToPDF.PageSizes LEGAL
LETTERback to summary
public static final TextToPDF.PageSizes LETTER
pageSizeback to summary
pack-priv final PDRectangle pageSize

Constructor Detail

PageSizesback to summary
private PageSizes(PDRectangle pageSize)

Method Detail

getPageSizeback to summary
public PDRectangle getPageSize()
valueOfback to summary
public static TextToPDF.PageSizes valueOf(String name)
valuesback to summary
public static TextToPDF.PageSizes[] values()