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

public final Class ExtractImages

extends Object
implements Callable<Integer>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Callable
Annotations
@Command
name:extractimages
header:Extracts the images from a PDF document
versionProvider:Version
mixinStandardHelpOptions:true
Imports
java.awt.geom.Point2D, java.awt.image.BufferedImage, java.io.File, .FileOutputStream, .IOException, .InputStream, .PrintStream, java.util.Arrays, .Collections, .HashSet, .List, .Set, java.util.concurrent.Callable, org.apache.commons.io.FilenameUtils, org.apache.pdfbox.Loader, org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine, org.apache.pdfbox.cos.COSName, .COSStream, org.apache.pdfbox.io.IOUtils, org.apache.pdfbox.pdmodel.PDDocument, .PDPage, .PDResources, org.apache.pdfbox.pdmodel.encryption.AccessPermission, org.apache.pdfbox.pdmodel.font.PDFont, org.apache.pdfbox.pdmodel.graphics.color.PDColor, .PDDeviceGray, .PDDeviceRGB, .PDPattern, org.apache.pdfbox.pdmodel.graphics.form.PDTransparencyGroup, org.apache.pdfbox.pdmodel.graphics.image.PDImage, .PDImageXObject, org.apache.pdfbox.pdmodel.graphics.pattern.PDAbstractPattern, .PDTilingPattern, org.apache.pdfbox.pdmodel.graphics.state.PDExtendedGraphicsState, .PDGraphicsState, .PDSoftMask, .RenderingMode, org.apache.pdfbox.tools.imageio.ImageIOUtil, org.apache.pdfbox.util.Matrix, .Vector, picocli.CommandLine, .CommandLine.Command, .CommandLine.Option

Extracts the images from a PDF file.
Author
Ben Litchfield

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
private int
private File
private static final List<String>
private boolean
private String
private String
private final Set<COSStream>
private final PrintStream
private final PrintStream
private boolean

Constructor Summary

AccessConstructor and Description
public
ExtractImages()

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 static void
main(String[]
The command-line arguments.
args
)

Entry point for the application.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

imageCounterback to summary
private int imageCounter
infileback to summary
private File infile
Annotations
@Option
names:-i, --input
description:the PDF file
required:true
JPEGback to summary
private static final List<String> JPEG
noColorConvertback to summary
private boolean noColorConvert
Annotations
@Option
names:-noColorConvert
description:Images are extracted with their original colorspace if possible.
passwordback to summary
private String password
Annotations
@Option
names:-password
description:the password for the PDF or certificate in keystore.
arity:0..1
interactive:true
prefixback to summary
private String prefix
Annotations
@Option
names:-prefix
description:the image prefix (default to pdf name).
seenback to summary
private final Set<COSStream> seen
SYSERRback to summary
private final PrintStream SYSERR
Annotations
@SuppressWarnings:squid:S106
SYSOUTback to summary
private final PrintStream SYSOUT
Annotations
@SuppressWarnings:squid:S106
useDirectJPEGback to summary
private boolean useDirectJPEG
Annotations
@Option
names:-useDirectJPEG
description:Forces the direct extraction of JPEG/JPX images regardless of colorspace or masking.

Constructor Detail

ExtractImagesback to summary
public ExtractImages()

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

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

Entry point for the application.

Parameters
args:String[]

The command-line arguments.

org.apache.pdfbox.tools back to summary

private Class ExtractImages.ImageGraphicsEngine

extends PDFGraphicsStreamEngine
Class Inheritance

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
public void
appendRectangle(Point2D
starting coordinate of the rectangle
p0
,
Point2D
second coordinate of the rectangle
p1
,
Point2D
third coordinate of the rectangle
p2
,
Point2D
last coordinate of the rectangle
p3
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.appendRectangle.

Append a rectangle to the current path.

public void
clip(int
The winding rule which will be used for clipping.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.clip.

Modify the current clipping path by intersecting it with the current path.

public void
public void
curveTo(float
the X coordinate of the first Bézier control point
x1
,
float
the Y coordinate of the first Bézier control point
y1
,
float
the X coordinate of the second Bézier control point
x2
,
float
the Y coordinate of the second Bézier control point
y2
,
float
the X coordinate of the final end point
x3
,
float
the Y coordinate of the final end point
y3
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.curveTo.

Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.

public void
drawImage(PDImage
The image to draw.
pdImage
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.drawImage.

Draw the image.

public void
endPath()

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.endPath.

Ends the current path without filling or stroking it.

public void
fillAndStrokePath(int
The winding rule this path will use.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillAndStrokePath.

Fills and then strokes the path.

public void
fillPath(int
The winding rule this path will use.
windingRule
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

Fill the path.

public Point2D
getCurrentPoint()

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.getCurrentPoint.

Returns the current point of the current path.

private boolean
hasMasks(PDImage pdImage)

public void
lineTo(float
the X-coordinate of the ending-point of the line to be drawn
x
,
float
the Y-coordinate of the ending-point of the line to be drawn
y
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.lineTo.

Draws a line from the current point to (x,y).

public void
moveTo(float
the x-coordinate to move to
x
,
float
the y-coordinate to move to
y
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.moveTo.

Starts a new path at (x,y).

private void
public void
run()

public void
shadingFill(COSName
The name of the Shading Dictionary to use for this fill instruction.
shadingName
)

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.shadingFill.

Fill with Shading.

protected void
showGlyph(Matrix
the current text rendering matrix, Trm
textRenderingMatrix
,
PDFont
the current font
font
,
int
internal PDF character code for the glyph
code
,
Vector
the displacement (i.e. advance) of the glyph in text space
displacement
)

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

Called when a glyph is to be processed.

public void
private void
write2file(PDImage
the image.
pdImage
,
String
the filename prefix.
prefix
,
boolean
if true, force saving JPEG/JPX streams as they are in the PDF file.
directJPEG
,
boolean
if true, images are extracted with their original colorspace if possible.
noColorConvert
)

Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg".

Inherited from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine:
getPage

Constructor Detail

ImageGraphicsEngineback to summary
protected ImageGraphicsEngine(PDPage page)

Method Detail

appendRectangleback to summary
public void appendRectangle(Point2D p0, Point2D p1, Point2D p2, Point2D p3) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.appendRectangle.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.appendRectangle.

Append a rectangle to the current path.

Parameters
p0:Point2D

starting coordinate of the rectangle

p1:Point2D

second coordinate of the rectangle

p2:Point2D

third coordinate of the rectangle

p3:Point2D

last coordinate of the rectangle

Annotations
@Override
Exceptions
IOException:
if the rectangle could not be appended
clipback to summary
public void clip(int windingRule) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.clip.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.clip.

Modify the current clipping path by intersecting it with the current path. The clipping path will not be updated until the succeeding painting operator is called.

Parameters
windingRule:int

The winding rule which will be used for clipping.

Annotations
@Override
Exceptions
IOException:
if the clipping path could not be modified
closePathback to summary
public void closePath() throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.closePath.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.closePath.

Closes the current path.

Annotations
@Override
Exceptions
IOException:
if the current path could not be closed
curveToback to summary
public void curveTo(float x1, float y1, float x2, float y2, float x3, float y3) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.curveTo.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.curveTo.

Draws a curve from the current point to (x3,y3) using (x1,y1) and (x2,y2) as control points.

Parameters
x1:float

the X coordinate of the first Bézier control point

y1:float

the Y coordinate of the first Bézier control point

x2:float

the X coordinate of the second Bézier control point

y2:float

the Y coordinate of the second Bézier control point

x3:float

the X coordinate of the final end point

y3:float

the Y coordinate of the final end point

Annotations
@Override
Exceptions
IOException:
if the curve could not be drawn
drawImageback to summary
public void drawImage(PDImage pdImage) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.drawImage.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.drawImage.

Draw the image.

Parameters
pdImage:PDImage

The image to draw.

Annotations
@Override
Exceptions
IOException:
if the image could not be drawn
endPathback to summary
public void endPath() throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.endPath.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.endPath.

Ends the current path without filling or stroking it. The clipping path is updated here.

Annotations
@Override
Exceptions
IOException:
if the current path could not be ended
fillAndStrokePathback to summary
public void fillAndStrokePath(int windingRule) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillAndStrokePath.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillAndStrokePath.

Fills and then strokes the path.

Parameters
windingRule:int

The winding rule this path will use.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled and stroke
fillPathback to summary
public void fillPath(int windingRule) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.fillPath.

Fill the path.

Parameters
windingRule:int

The winding rule this path will use.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled
getCurrentPointback to summary
public Point2D getCurrentPoint() throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.getCurrentPoint.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.getCurrentPoint.

Returns the current point of the current path.

Returns:Point2D

the current point or null

Annotations
@Override
Exceptions
IOException:
if the something went wrong when providing the current point
hasMasksback to summary
private boolean hasMasks(PDImage pdImage) throws IOException
lineToback to summary
public void lineTo(float x, float y) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.lineTo.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.lineTo.

Draws a line from the current point to (x,y).

Parameters
x:float

the X-coordinate of the ending-point of the line to be drawn

y:float

the Y-coordinate of the ending-point of the line to be drawn

Annotations
@Override
Exceptions
IOException:
if the line could not be drawn
moveToback to summary
public void moveTo(float x, float y) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.moveTo.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.moveTo.

Starts a new path at (x,y).

Parameters
x:float

the x-coordinate to move to

y:float

the y-coordinate to move to

Annotations
@Override
Exceptions
IOException:
if the something went wrong when moving to the given coordinate
processColorback to summary
private void processColor(PDColor color) throws IOException
runback to summary
public void run() throws IOException
shadingFillback to summary
public void shadingFill(COSName shadingName) throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.shadingFill.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.shadingFill.

Fill with Shading.

Parameters
shadingName:COSName

The name of the Shading Dictionary to use for this fill instruction.

Annotations
@Override
Exceptions
IOException:
if the path could not be filled using the given shading
showGlyphback to summary
protected void showGlyph(Matrix textRenderingMatrix, PDFont font, int code, Vector displacement) throws IOException

Overrides org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

Doc from org.apache.pdfbox.contentstream.PDFStreamEngine.showGlyph.

Called when a glyph is to be processed. This method is intended for overriding in subclasses, the default implementation does nothing.

Parameters
textRenderingMatrix:Matrix

the current text rendering matrix, Trm

font:PDFont

the current font

code:int

internal PDF character code for the glyph

displacement:Vector

the displacement (i.e. advance) of the glyph in text space

Annotations
@Override
Exceptions
IOException:
if the glyph cannot be processed
strokePathback to summary
public void strokePath() throws IOException

Implements abstract org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.strokePath.

Doc from org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine.strokePath.

Stroke the path.

Annotations
@Override
Exceptions
IOException:
If there is an IO error while stroking the path.
write2fileback to summary
private void write2file(PDImage pdImage, String prefix, boolean directJPEG, boolean noColorConvert) throws IOException

Writes the image to a file with the filename prefix + an appropriate suffix, like "Image.jpg". The suffix is automatically set depending on the image compression in the PDF.

Parameters
pdImage:PDImage

the image.

prefix:String

the filename prefix.

directJPEG:boolean

if true, force saving JPEG/JPX streams as they are in the PDF file.

noColorConvert:boolean

if true, images are extracted with their original colorspace if possible.

Exceptions
IOException:
When something is wrong with the corresponding file.