Package org.apache.tika.parser.pdf
Class PDFParser
java.lang.Object
org.apache.tika.parser.pdf.PDFParser
- All Implemented Interfaces:
Serializable,org.apache.tika.config.Initializable,org.apache.tika.parser.Parser,org.apache.tika.parser.RenderingParser
public class PDFParser
extends Object
implements org.apache.tika.parser.Parser, org.apache.tika.parser.RenderingParser, org.apache.tika.config.Initializable
PDF parser.
This parser can process also encrypted PDF documents if the required
password is given as a part of the input metadata associated with a
document. If no password is given, then this parser will try decrypting
the document using the empty password that's often used with PDFs. If
the PDF contains any embedded documents (for example as part of a PDF
package) then this parser will use the
EmbeddedDocumentExtractor
to handle them.
As of Tika 1.6, it is possible to extract inline images with
the EmbeddedDocumentExtractor as if they were regular
attachments. By default, this feature is turned off because of
the potentially enormous number and size of inline images. To
turn this feature on, see
PDFParserConfig.setExtractInlineImages(boolean).
Please note that many pdfs do not store table structures.
So you should not expect table markup for what looks like a table. It
takes significant computation to identify and then correctly extract
tables from PDFs. As of this writing, the PDFParser extracts
text within tables, but it does not compute table cell boundaries or
table row boundaries. Please see
tabula for one project that
tries to maintain the structure of tables represented in PDFs.
If your PDFs contain marked content or tags, consider
PDFParserConfig.setExtractMarkedContent(boolean)- See Also:
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcheckInitialization(org.apache.tika.config.InitializableProblemHandler handler) floatfloatintlongintfloatprotected org.apache.pdfbox.pdmodel.PDDocumentgetPDDocument(InputStream inputStream, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext parseContext) protected org.apache.pdfbox.pdmodel.PDDocumentgetPDDocument(InputStream stream, org.apache.tika.io.TikaInputStream tstream, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context) protected org.apache.pdfbox.pdmodel.PDDocumentgetPDDocument(Path path, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext parseContext) org.apache.tika.renderer.RendererfloatSet<org.apache.tika.mime.MediaType>getSupportedTypes(org.apache.tika.parser.ParseContext context) voidinitialize(Map<String, org.apache.tika.config.Param> params) This is a no-op.booleanbooleanbooleanbooleanbooleanbooleanbooleanIf true, text in annotations will be extracted.booleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanbooleanvoidparse(InputStream stream, ContentHandler handler, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context) voidsetAllowExtractionForAccessibility(boolean allowExtractionForAccessibility) voidsetAverageCharTolerance(float averageCharTolerance) voidsetCatchIntermediateExceptions(boolean catchIntermediateExceptions) voidsetDetectAngles(boolean detectAngles) voidsetDropThreshold(float dropThreshold) voidsetEnableAutoSpace(boolean v) If true (the default), the parser should estimate where spaces should be inserted between words.voidsetExtractAcroFormContent(boolean extractAcroFormContent) voidsetExtractActions(boolean extractActions) voidsetExtractAnnotationText(boolean v) If true (the default), text in annotations will be extracted.voidsetExtractBookmarksText(boolean extractBookmarksText) voidsetExtractFontNames(boolean extractFontNames) voidsetExtractIncrementalUpdateInfo(boolean setExtractIncrementalUpdateInfo) Whether or not to scan a PDF for incremental updates.voidsetExtractInlineImageMetadataOnly(boolean extractInlineImageMetadataOnly) voidsetExtractInlineImages(boolean extractInlineImages) voidsetExtractMarkedContent(boolean extractMarkedContent) voidsetExtractUniqueInlineImagesOnly(boolean extractUniqueInlineImagesOnly) voidsetIfXFAExtractOnlyXFA(boolean ifXFAExtractOnlyXFA) voidsetImageGraphicsEngineFactory(ImageGraphicsEngineFactory imageGraphicsEngineFactory) voidsetImageStrategy(String imageStrategy) voidsetMaxIncrementalUpdates(int maxIncrementalUpdates) Set the maximum number of incremental updates to parsevoidsetMaxMainMemoryBytes(long maxMainMemoryBytes) voidsetOcrDPI(int dpi) voidsetOcrImageFormatName(String formatName) voidsetOcrImageQuality(float imageQuality) voidsetOcrImageType(String imageType) voidsetOcrRenderingStrategy(String ocrRenderingStrategy) voidsetOcrStrategy(String ocrStrategyString) voidsetOcrStrategyAuto(String ocrStrategyAuto) voidsetParseIncrementalUpdates(boolean parseIncrementalUpdates) If set to true, this will parse incremental updates if they exist within a PDF.voidsetPDFParserConfig(PDFParserConfig config) voidsetRenderer(org.apache.tika.renderer.Renderer renderer) voidsetSetKCMS(boolean setKCMS) voidsetSortByPosition(boolean v) If true, sort text tokens by their x/y position before extracting text.voidsetSpacingTolerance(float spacingTolerance) voidsetSuppressDuplicateOverlappingText(boolean v) If true, the parser should try to remove duplicated text over the same region.voidsetThrowOnEncryptedPayload(boolean throwOnEncryptedPayload) If the file is a 'Collection' and contains an embedded file with a defined 'AssociatedFile' value of 'EncryptedPayload', then throw anEncryptedDocumentException.
-
Field Details
-
MEDIA_TYPE
public static final org.apache.tika.mime.MediaType MEDIA_TYPE
-
-
Constructor Details
-
PDFParser
public PDFParser()
-
-
Method Details
-
getSupportedTypes
public Set<org.apache.tika.mime.MediaType> getSupportedTypes(org.apache.tika.parser.ParseContext context) - Specified by:
getSupportedTypesin interfaceorg.apache.tika.parser.Parser
-
parse
public void parse(InputStream stream, ContentHandler handler, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context) throws IOException, SAXException, org.apache.tika.exception.TikaException - Specified by:
parsein interfaceorg.apache.tika.parser.Parser- Throws:
IOExceptionSAXExceptionorg.apache.tika.exception.TikaException
-
getPDDocument
protected org.apache.pdfbox.pdmodel.PDDocument getPDDocument(InputStream stream, org.apache.tika.io.TikaInputStream tstream, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext context) throws IOException, org.apache.tika.exception.EncryptedDocumentException - Throws:
IOExceptionorg.apache.tika.exception.EncryptedDocumentException
-
getPDDocument
protected org.apache.pdfbox.pdmodel.PDDocument getPDDocument(InputStream inputStream, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext parseContext) throws IOException - Throws:
IOException
-
getPDDocument
protected org.apache.pdfbox.pdmodel.PDDocument getPDDocument(Path path, String password, org.apache.pdfbox.io.RandomAccessStreamCache.StreamCacheCreateFunction streamCacheCreateFunction, org.apache.tika.metadata.Metadata metadata, org.apache.tika.parser.ParseContext parseContext) throws IOException - Throws:
IOException
-
getPDFParserConfig
-
setPDFParserConfig
-
isEnableAutoSpace
public boolean isEnableAutoSpace()- See Also:
-
setEnableAutoSpace
@Field public void setEnableAutoSpace(boolean v) If true (the default), the parser should estimate where spaces should be inserted between words. For many PDFs this is necessary as they do not include explicit whitespace characters. -
isExtractAnnotationText
public boolean isExtractAnnotationText()If true, text in annotations will be extracted. -
setExtractAnnotationText
@Field public void setExtractAnnotationText(boolean v) If true (the default), text in annotations will be extracted. -
isSuppressDuplicateOverlappingText
public boolean isSuppressDuplicateOverlappingText() -
setSuppressDuplicateOverlappingText
@Field public void setSuppressDuplicateOverlappingText(boolean v) If true, the parser should try to remove duplicated text over the same region. This is needed for some PDFs that achieve bolding by re-writing the same text in the same area. Note that this can slow down extraction substantially (PDFBOX-956) and sometimes remove characters that were not in fact duplicated (PDFBOX-1155). By default this is disabled. -
isSortByPosition
public boolean isSortByPosition()- See Also:
-
setSortByPosition
@Field public void setSortByPosition(boolean v) If true, sort text tokens by their x/y position before extracting text. This may be necessary for some PDFs (if the text tokens are not rendered "in order"), while for other PDFs it can produce the wrong result (for example if there are 2 columns, the text will be interleaved). Default is false. -
setOcrStrategy
-
getOcrStrategy
-
setOcrStrategyAuto
-
getOcrStrategyAuto
-
setOcrRenderingStrategy
-
getOcrRenderingStrategy
-
setOcrImageType
-
getOcrImageType
-
setOcrDPI
@Field public void setOcrDPI(int dpi) -
getOcrDPI
public int getOcrDPI() -
setOcrImageQuality
@Field public void setOcrImageQuality(float imageQuality) -
getOcrImageQuality
public float getOcrImageQuality() -
setOcrImageFormatName
-
getOcrImageFormatName
-
setExtractBookmarksText
@Field public void setExtractBookmarksText(boolean extractBookmarksText) -
isExtractBookmarksText
public boolean isExtractBookmarksText() -
setExtractInlineImages
@Field public void setExtractInlineImages(boolean extractInlineImages) -
isExtractInlineImages
public boolean isExtractInlineImages() -
setExtractInlineImageMetadataOnly
@Field public void setExtractInlineImageMetadataOnly(boolean extractInlineImageMetadataOnly) -
isExtractInlineImageMetadataOnly
public boolean isExtractInlineImageMetadataOnly() -
setAverageCharTolerance
@Field public void setAverageCharTolerance(float averageCharTolerance) -
getAverageCharTolerance
public float getAverageCharTolerance() -
setSpacingTolerance
@Field public void setSpacingTolerance(float spacingTolerance) -
getSpacingTolerance
public float getSpacingTolerance() -
setCatchIntermediateExceptions
@Field public void setCatchIntermediateExceptions(boolean catchIntermediateExceptions) -
isCatchIntermediateExceptions
public boolean isCatchIntermediateExceptions() -
setExtractAcroFormContent
@Field public void setExtractAcroFormContent(boolean extractAcroFormContent) -
isExtractAcroFormContent
public boolean isExtractAcroFormContent() -
setIfXFAExtractOnlyXFA
@Field public void setIfXFAExtractOnlyXFA(boolean ifXFAExtractOnlyXFA) -
isIfXFAExtractOnlyXFA
public boolean isIfXFAExtractOnlyXFA() -
setAllowExtractionForAccessibility
@Field public void setAllowExtractionForAccessibility(boolean allowExtractionForAccessibility) -
isAllowExtractionForAccessibility
public boolean isAllowExtractionForAccessibility() -
setExtractUniqueInlineImagesOnly
@Field public void setExtractUniqueInlineImagesOnly(boolean extractUniqueInlineImagesOnly) -
isExtractUniqueInlineImagesOnly
public boolean isExtractUniqueInlineImagesOnly() -
setExtractActions
@Field public void setExtractActions(boolean extractActions) -
isExtractActions
public boolean isExtractActions() -
setExtractFontNames
@Field public void setExtractFontNames(boolean extractFontNames) -
isExtractFontNames
public boolean isExtractFontNames() -
setSetKCMS
@Field public void setSetKCMS(boolean setKCMS) -
isSetKCMS
public boolean isSetKCMS() -
setDetectAngles
@Field public void setDetectAngles(boolean detectAngles) -
isDetectAngles
public boolean isDetectAngles() -
setExtractMarkedContent
@Field public void setExtractMarkedContent(boolean extractMarkedContent) -
isExtractMarkedContent
public boolean isExtractMarkedContent() -
setDropThreshold
@Field public void setDropThreshold(float dropThreshold) -
getDropThreshold
public float getDropThreshold() -
setMaxMainMemoryBytes
@Field public void setMaxMainMemoryBytes(long maxMainMemoryBytes) -
setExtractIncrementalUpdateInfo
@Field public void setExtractIncrementalUpdateInfo(boolean setExtractIncrementalUpdateInfo) Whether or not to scan a PDF for incremental updates.- Parameters:
setExtractIncrementalUpdateInfo-
-
getMaxMainMemoryBytes
public long getMaxMainMemoryBytes() -
isExtractIncrementalUpdateInfo
public boolean isExtractIncrementalUpdateInfo() -
setParseIncrementalUpdates
@Field public void setParseIncrementalUpdates(boolean parseIncrementalUpdates) If set to true, this will parse incremental updates if they exist within a PDF. If set totrue, this will overridesetExtractIncrementalUpdateInfo(boolean).- Parameters:
parseIncrementalUpdates-
-
isParseIncrementalUpdates
public boolean isParseIncrementalUpdates() -
setMaxIncrementalUpdates
@Field public void setMaxIncrementalUpdates(int maxIncrementalUpdates) Set the maximum number of incremental updates to parse- Parameters:
maxIncrementalUpdates-
-
getMaxIncrementalUpdates
public int getMaxIncrementalUpdates() -
setThrowOnEncryptedPayload
@Field public void setThrowOnEncryptedPayload(boolean throwOnEncryptedPayload) If the file is a 'Collection' and contains an embedded file with a defined 'AssociatedFile' value of 'EncryptedPayload', then throw anEncryptedDocumentException.Microsoft IRM v2 wraps the encrypted document inside a container PDF. See TIKA-4082.
The goal of this is to make the user experience the same for traditionally encrypted files and PDFs that are containers for `EncryptedPayload`s.
The default value is
false.- Parameters:
throwOnEncryptedPayload-
-
isThrowOnEncryptedPayload
public boolean isThrowOnEncryptedPayload() -
initialize
public void initialize(Map<String, org.apache.tika.config.Param> params) throws org.apache.tika.exception.TikaConfigExceptionThis is a no-op. There is no need to initialize multiple fields. The regular field loading should happen without this.- Specified by:
initializein interfaceorg.apache.tika.config.Initializable- Parameters:
params- params to use for initialization- Throws:
org.apache.tika.exception.TikaConfigException
-
checkInitialization
public void checkInitialization(org.apache.tika.config.InitializableProblemHandler handler) throws org.apache.tika.exception.TikaConfigException - Specified by:
checkInitializationin interfaceorg.apache.tika.config.Initializable- Throws:
org.apache.tika.exception.TikaConfigException
-
setRenderer
public void setRenderer(org.apache.tika.renderer.Renderer renderer) - Specified by:
setRendererin interfaceorg.apache.tika.parser.RenderingParser
-
getRenderer
public org.apache.tika.renderer.Renderer getRenderer() -
setImageGraphicsEngineFactory
@Field public void setImageGraphicsEngineFactory(ImageGraphicsEngineFactory imageGraphicsEngineFactory) -
getImageGraphicsEngineFactory
-
setImageStrategy
-
getImageStrategy
-