Package org.apache.tika.parser.pdf
Class PDFParserConfig
java.lang.Object
org.apache.tika.parser.pdf.PDFParserConfig
- All Implemented Interfaces:
Serializable
Config for PDFParser.
This allows parameters to be set programmatically:
- Calls to PDFParser, i.e. parser.getPDFParserConfig().setEnableAutoSpace() (as before)
- Passing to PDFParser through a ParseContext: context.set(PDFParserConfig.class, config);
- See Also:
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
static enum
static enum
static class
Encapsulate the numbers used to control OCR Strategy when set to autostatic enum
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptioncloneAndUpdate
(PDFParserConfig updates) void
configure
(org.apache.tika.parser.pdf.PDF2XHTML pdf2XHTML) Configures the given pdf2XHTML.int
long
The maximum amount of memory to use when loading a pdf into a PDDocument.int
Dots per inch used to render the page image for OCRString representation of the image format used to render the page image for OCR (examples: png, tiff, jpeg)float
Image quality used to render the page image for OCR.Image type used to render the page image for OCR.boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
boolean
void
setAccessChecker
(AccessChecker accessChecker) void
setAverageCharTolerance
(Float averageCharTolerance) SeePDFTextStripper.setAverageCharTolerance(float)
void
setCatchIntermediateIOExceptions
(boolean catchIntermediateIOExceptions) The PDFBox parser will throw an IOException if there is a problem with a stream.void
setDetectAngles
(boolean detectAngles) void
setDropThreshold
(Float dropThreshold) SeePDFTextStripper.setDropThreshold(float)
void
setEnableAutoSpace
(boolean enableAutoSpace) If true (the default), the parser should estimate where spaces should be inserted between words.void
setExtractAcroFormContent
(boolean extractAcroFormContent) If true (the default), extract content from AcroForms at the end of the document.void
setExtractActions
(boolean v) Whether or not to extract PDActions from the file.void
setExtractAnnotationText
(boolean extractAnnotationText) If true (the default), text in annotations will be extracted.void
setExtractBookmarksText
(boolean extractBookmarksText) If true, extract bookmarks (document outline) text.void
setExtractFontNames
(boolean extractFontNames) Extract font names into a metadata fieldvoid
setExtractIncrementalUpdateInfo
(boolean extractIncrementalUpdateInfo) void
setExtractInlineImageMetadataOnly
(boolean extractInlineImageMetadataOnly) Use this when you want to know how many images of what formats are in a PDF but you don't need to render the images (e.g. for OCR).void
setExtractInlineImages
(boolean extractInlineImages) Iftrue
, extract the literal inline embedded OBXImages.void
setExtractMarkedContent
(boolean extractMarkedContent) If the PDF contains marked content, try to extract text and its marked structure.void
setExtractUniqueInlineImagesOnly
(boolean extractUniqueInlineImagesOnly) Multiple pages within a PDF file might refer to the same underlying image.void
setIfXFAExtractOnlyXFA
(boolean ifXFAExtractOnlyXFA) If false (the default), extract content from the full PDF as well as the XFA form.void
setImageGraphicsEngineFactory
(ImageGraphicsEngineFactory imageGraphicsEngineFactory) EXPERT: Customize the class that handles inline images within a PDF page.void
setImageStrategy
(String imageStrategy) void
setImageStrategy
(PDFParserConfig.IMAGE_STRATEGY imageStrategy) void
setMaxIncrementalUpdates
(int maxIncrementalUpdates) The maximum number of incremental updates to parse.void
setMaxMainMemoryBytes
(long maxMainMemoryBytes) void
setOcrDPI
(int ocrDPI) Dots per inch used to render the page image for OCR.void
setOcrImageFormatName
(String ocrImageFormatName) void
setOcrImageQuality
(float ocrImageQuality) Image quality used to render the page image for OCR.void
setOcrImageType
(String ocrImageTypeString) Image type used to render the page image for OCR.void
setOcrImageType
(PDFParserConfig.TikaImageType ocrImageType) Image type used to render the page image for OCR.void
setOcrRenderingStrategy
(String ocrRenderingStrategyString) void
setOcrRenderingStrategy
(PDFParserConfig.OCR_RENDERING_STRATEGY ocrRenderingStrategy) When rendering the page for OCR, do you want to include the rendering of the electronic text, ALL, or do you only want to run OCR on the images and vector graphics (NO_TEXT)?void
setOcrStrategy
(String ocrStrategyString) Which strategy to use for OCRvoid
setOcrStrategy
(PDFParserConfig.OCR_STRATEGY ocrStrategy) Which strategy to use for OCRvoid
setOcrStrategyAuto
(String ocrStrategyAuto) void
setParseIncrementalUpdates
(boolean parseIncrementalUpdates) void
setRenderer
(Renderer renderer) void
setSetKCMS
(boolean setKCMS) Whether to callSystem.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider")
.void
setSortByPosition
(boolean sortByPosition) If true, sort text tokens by their x/y position before extracting text.void
setSpacingTolerance
(Float spacingTolerance) SeePDFTextStripper.setSpacingTolerance(float)
void
setSuppressDuplicateOverlappingText
(boolean suppressDuplicateOverlappingText) If true, the parser should try to remove duplicated text over the same region.void
setThrowOnEncryptedPayload
(boolean throwOnEncryptedPayload)
-
Constructor Details
-
PDFParserConfig
public PDFParserConfig()
-
-
Method Details
-
isExtractInlineImageMetadataOnly
public boolean isExtractInlineImageMetadataOnly()- Returns:
- whether or not to extract only inline image metadata and not render the images
-
setExtractInlineImageMetadataOnly
public void setExtractInlineImageMetadataOnly(boolean extractInlineImageMetadataOnly) Use this when you want to know how many images of what formats are in a PDF but you don't need to render the images (e.g. for OCR). This is far faster thanextractInlineImages
because it doesn't have to render the images, which can be very slow. This does not extract metadata from within each image, rather it extracts the XMP that may be stored external to an image in PDImageXObjects.- Parameters:
extractInlineImageMetadataOnly
-- Since:
- 1.25
-
isExtractMarkedContent
public boolean isExtractMarkedContent() -
setExtractMarkedContent
public void setExtractMarkedContent(boolean extractMarkedContent) If the PDF contains marked content, try to extract text and its marked structure. If the PDF does not contain marked content, backoff to the regular PDF2XHTML for text extraction. As of 1.24, this is an "alpha" version.- Parameters:
extractMarkedContent
-- Since:
- 1.24
-
configure
public void configure(org.apache.tika.parser.pdf.PDF2XHTML pdf2XHTML) Configures the given pdf2XHTML.- Parameters:
pdf2XHTML
-
-
isExtractAcroFormContent
public boolean isExtractAcroFormContent()- See Also:
-
setExtractAcroFormContent
public void setExtractAcroFormContent(boolean extractAcroFormContent) If true (the default), extract content from AcroForms at the end of the document. If an XFA is found, try to process that, otherwise, process the AcroForm.- Parameters:
extractAcroFormContent
-
-
isIfXFAExtractOnlyXFA
public boolean isIfXFAExtractOnlyXFA()- Returns:
- how to handle XFA data if it exists
- See Also:
-
setIfXFAExtractOnlyXFA
public void setIfXFAExtractOnlyXFA(boolean ifXFAExtractOnlyXFA) If false (the default), extract content from the full PDF as well as the XFA form. This will likely lead to some duplicative content.- Parameters:
ifXFAExtractOnlyXFA
-
-
isExtractBookmarksText
public boolean isExtractBookmarksText()- See Also:
-
setExtractBookmarksText
public void setExtractBookmarksText(boolean extractBookmarksText) If true, extract bookmarks (document outline) text. Te default istrue
- Parameters:
extractBookmarksText
-
-
isExtractFontNames
public boolean isExtractFontNames() -
setExtractFontNames
public void setExtractFontNames(boolean extractFontNames) Extract font names into a metadata field- Parameters:
extractFontNames
-
-
isExtractInlineImages
public boolean isExtractInlineImages()- See Also:
-
setExtractInlineImages
public void setExtractInlineImages(boolean extractInlineImages) Iftrue
, extract the literal inline embedded OBXImages. Beware: some PDF documents of modest size (~4MB) can contain thousands of embedded images totaling > 2.5 GB. Also, at least as of PDFBox 1.8.5, there can be surprisingly large memory consumption and/or out of memory errors. Along the same lines, note that this does not extract "logical" images. Some PDF writers break up a single logical image into hundreds of little images. With this option set totrue
, you might get those hundreds of little images. NOTE ALSO: this extracts the raw images without clipping, rotation, masks, color inversion, etc. The images that this extracts may look nothing like what a human would expect given the appearance of the PDF. Set totrue
only with the greatest caution. The default isfalse
.- Parameters:
extractInlineImages
-- See Also:
-
isExtractUniqueInlineImagesOnly
public boolean isExtractUniqueInlineImagesOnly() -
setExtractUniqueInlineImagesOnly
public void setExtractUniqueInlineImagesOnly(boolean extractUniqueInlineImagesOnly) Multiple pages within a PDF file might refer to the same underlying image. IfextractUniqueInlineImagesOnly
is set tofalse
, the parser will call the EmbeddedExtractor each time the image appears on a page. This might be desired for some use cases. However, to avoid duplication of extracted images, set this totrue
. The default istrue
. Note that uniqueness is determined only by the underlying PDF COSObject id, not by file hash or similar equality metric. If the PDF actually contains multiple copies of the same image -- all with different object ids -- then all images will be extracted. For this parameter to have any effect,extractInlineImages
must be set totrue
.Because of TIKA-1742 -- to avoid infinite recursion -- no matter the setting of this parameter, the extractor will only pull out one copy of each image per page. This parameter tries to capture uniqueness across the entire document.
- Parameters:
extractUniqueInlineImagesOnly
-
-
isEnableAutoSpace
public boolean isEnableAutoSpace()- See Also:
-
setEnableAutoSpace
public void setEnableAutoSpace(boolean enableAutoSpace) 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. -
isSuppressDuplicateOverlappingText
public boolean isSuppressDuplicateOverlappingText() -
setSuppressDuplicateOverlappingText
public void setSuppressDuplicateOverlappingText(boolean suppressDuplicateOverlappingText) 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. -
isExtractAnnotationText
public boolean isExtractAnnotationText()- See Also:
-
setExtractAnnotationText
public void setExtractAnnotationText(boolean extractAnnotationText) If true (the default), text in annotations will be extracted. -
isSortByPosition
public boolean isSortByPosition()- See Also:
-
setSortByPosition
public void setSortByPosition(boolean sortByPosition) 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. -
getAverageCharTolerance
- See Also:
-
setAverageCharTolerance
SeePDFTextStripper.setAverageCharTolerance(float)
-
getSpacingTolerance
- See Also:
-
setSpacingTolerance
SeePDFTextStripper.setSpacingTolerance(float)
-
getDropThreshold
- See Also:
-
setDropThreshold
SeePDFTextStripper.setDropThreshold(float)
-
getAccessChecker
-
setAccessChecker
-
isCatchIntermediateIOExceptions
public boolean isCatchIntermediateIOExceptions()- Returns:
- whether or not to catch IOExceptions
-
setCatchIntermediateIOExceptions
public void setCatchIntermediateIOExceptions(boolean catchIntermediateIOExceptions) The PDFBox parser will throw an IOException if there is a problem with a stream. If this is set totrue
, Tika's PDFParser will catch these exceptions and try to parse the rest of the document. After the parse is completed, Tika's PDFParser will throw the first caught exception.- Parameters:
catchIntermediateIOExceptions
-
-
getOcrStrategy
- Returns:
- strategy to use for OCR
-
getOcrStrategyAuto
- Returns:
- ocr auto strategy to use when ocr_strategy = Auto
-
setOcrStrategy
Which strategy to use for OCR- Parameters:
ocrStrategy
-
-
setOcrStrategyAuto
-
setOcrStrategy
Which strategy to use for OCR- Parameters:
ocrStrategyString
-
-
getOcrRenderingStrategy
-
setOcrRenderingStrategy
-
setOcrRenderingStrategy
When rendering the page for OCR, do you want to include the rendering of the electronic text, ALL, or do you only want to run OCR on the images and vector graphics (NO_TEXT)?- Parameters:
ocrRenderingStrategy
-
-
getOcrImageFormatName
String representation of the image format used to render the page image for OCR (examples: png, tiff, jpeg)- Returns:
-
setOcrImageFormatName
- Parameters:
ocrImageFormatName
- name of image format used to render page image- See Also:
-
getOcrImageType
Image type used to render the page image for OCR.- Returns:
- image type
- See Also:
-
setOcrImageType
Image type used to render the page image for OCR.- Parameters:
ocrImageType
-
-
setOcrImageType
Image type used to render the page image for OCR.- See Also:
-
getOcrDPI
public int getOcrDPI()Dots per inch used to render the page image for OCR- Returns:
- dots per inch
-
setOcrDPI
public void setOcrDPI(int ocrDPI) Dots per inch used to render the page image for OCR. This does not apply to all image formats.- Parameters:
ocrDPI
-
-
getOcrImageQuality
public float getOcrImageQuality()Image quality used to render the page image for OCR. This does not apply to all image formats- Returns:
-
setOcrImageQuality
public void setOcrImageQuality(float ocrImageQuality) Image quality used to render the page image for OCR. This does not apply to all image formats -
isExtractActions
public boolean isExtractActions()- Returns:
- whether or not to extract PDActions
- See Also:
-
setExtractActions
public void setExtractActions(boolean v) Whether or not to extract PDActions from the file. Most Action types are handled inline; javascript macros are processed as embedded documents.- Parameters:
v
-
-
getMaxMainMemoryBytes
public long getMaxMainMemoryBytes()The maximum amount of memory to use when loading a pdf into a PDDocument. Additional buffering is done using a temp file. The default is 512MB.- Returns:
-
setMaxMainMemoryBytes
public void setMaxMainMemoryBytes(long maxMainMemoryBytes) -
isSetKCMS
public boolean isSetKCMS() -
setSetKCMS
public void setSetKCMS(boolean setKCMS) Whether to call
System.setProperty("sun.java2d.cmm", "sun.java2d.cmm.kcms.KcmsServiceProvider")
. KCMS is the unmaintained, legacy provider and is far faster than the newer replacement. However, there are stability and security risks with using the unmaintained legacy provider.Note, of course, that this is not thread safe. If the value is
false
in your first thread, and the second thread changes this totrue
, the system property in the first thread will now betrue
.Default is
false
.- Parameters:
setKCMS
- whether or not to set KCMS
-
isDetectAngles
public boolean isDetectAngles() -
setDetectAngles
public void setDetectAngles(boolean detectAngles) -
cloneAndUpdate
- Throws:
TikaException
-
setRenderer
-
getRenderer
-
setImageStrategy
-
setImageStrategy
-
setImageGraphicsEngineFactory
EXPERT: Customize the class that handles inline images within a PDF page.- Parameters:
imageGraphicsEngineFactory
-
-
getImageGraphicsEngineFactory
-
getImageStrategy
-
isExtractIncrementalUpdateInfo
public boolean isExtractIncrementalUpdateInfo() -
setExtractIncrementalUpdateInfo
public void setExtractIncrementalUpdateInfo(boolean extractIncrementalUpdateInfo) -
isParseIncrementalUpdates
public boolean isParseIncrementalUpdates() -
setParseIncrementalUpdates
public void setParseIncrementalUpdates(boolean parseIncrementalUpdates) -
getMaxIncrementalUpdates
public int getMaxIncrementalUpdates() -
setMaxIncrementalUpdates
public void setMaxIncrementalUpdates(int maxIncrementalUpdates) The maximum number of incremental updates to parse.- Parameters:
maxIncrementalUpdates
-
-
setThrowOnEncryptedPayload
public void setThrowOnEncryptedPayload(boolean throwOnEncryptedPayload) -
isThrowOnEncryptedPayload
public boolean isThrowOnEncryptedPayload()
-