Class PDFParserConfig
- java.lang.Object
-
- org.apache.tika.parser.pdf.PDFParserConfig
-
- All Implemented Interfaces:
java.io.Serializable
public class PDFParserConfig extends java.lang.Object implements java.io.Serializable
Config for PDFParser. This allows parameters to be set programmatically:- Calls to PDFParser, i.e. parser.getPDFParserConfig().setEnableAutoSpace() (as before)
- Constructor of PDFParser
- Passing to PDFParser through a ParseContext: context.set(PDFParserConfig.class, config);
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PDFParserConfig.OCR_STRATEGY
-
Constructor Summary
Constructors Constructor Description PDFParserConfig()
PDFParserConfig(java.io.InputStream is)
Loads properties from InputStream and then tries to close InputStream.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
configure(org.apache.tika.parser.pdf.PDF2XHTML pdf2XHTML)
Configures the given pdf2XHTML.boolean
equals(java.lang.Object o)
AccessChecker
getAccessChecker()
java.lang.Float
getAverageCharTolerance()
boolean
getCatchIntermediateIOExceptions()
boolean
getDetectAngles()
java.lang.Float
getDropThreshold()
boolean
getEnableAutoSpace()
boolean
getExtractAcroFormContent()
boolean
getExtractActions()
boolean
getExtractAnnotationText()
boolean
getExtractBookmarksText()
boolean
getExtractFontNames()
boolean
getExtractInlineImages()
boolean
getExtractMarkedContent()
boolean
getExtractUniqueInlineImagesOnly()
boolean
getIfXFAExtractOnlyXFA()
long
getMaxMainMemoryBytes()
The maximum amount of memory to use when loading a pdf into a PDDocument.int
getOcrDPI()
Dots per inch used to render the page image for OCRjava.lang.String
getOcrImageFormatName()
String representation of the image format used to render the page image for OCR (examples: png, tiff, jpeg)float
getOcrImageQuality()
Image quality used to render the page image for OCR.float
getOcrImageScale()
Deprecated.as of Tika 1.23, this is no longer used in rendering page images; usesetOcrDPI(int)
org.apache.pdfbox.rendering.ImageType
getOcrImageType()
Image type used to render the page image for OCR.PDFParserConfig.OCR_STRATEGY
getOcrStrategy()
boolean
getSetKCMS()
boolean
getSortByPosition()
java.lang.Float
getSpacingTolerance()
boolean
getSuppressDuplicateOverlappingText()
int
hashCode()
boolean
isCatchIntermediateIOExceptions()
Deprecated.void
setAccessChecker(AccessChecker accessChecker)
void
setAverageCharTolerance(java.lang.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)
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
setExtractInlineImages(boolean extractInlineImages)
If true, extract 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
setMaxMainMemoryBytes(int maxMainMemoryBytes)
Deprecated.void
setMaxMainMemoryBytes(long maxMainMemoryBytes)
void
setOcrDPI(int ocrDPI)
Dots per inch used to render the page image for OCR.void
setOcrImageFormatName(java.lang.String ocrImageFormatName)
void
setOcrImageQuality(float ocrImageQuality)
Image quality used to render the page image for OCR.void
setOcrImageScale(float ocrImageScale)
Deprecated.(as of Tika 1.23, this is no longer used in rendering page images)void
setOcrImageType(java.lang.String ocrImageTypeString)
Image type used to render the page image for OCR.void
setOcrImageType(org.apache.pdfbox.rendering.ImageType ocrImageType)
Image type used to render the page image for OCR.void
setOcrStrategy(java.lang.String ocrStrategyString)
Which strategy to use for OCRvoid
setOcrStrategy(PDFParserConfig.OCR_STRATEGY ocrStrategy)
Which strategy to use for OCRvoid
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(java.lang.Float spacingTolerance)
SeePDFTextStripper.setSpacingTolerance(float)
void
setSuppressDuplicateOverlappingText(boolean suppressDuplicateOverlappingText)
If true, the parser should try to remove duplicated text over the same region.java.lang.String
toString()
-
-
-
Constructor Detail
-
PDFParserConfig
public PDFParserConfig()
-
PDFParserConfig
public PDFParserConfig(java.io.InputStream is)
Loads properties from InputStream and then tries to close InputStream. If there is an IOException, this silently swallows the exception and goes back to the default.- Parameters:
is
-
-
-
Method Detail
-
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
-
getExtractMarkedContent
public boolean getExtractMarkedContent()
-
configure
public void configure(org.apache.tika.parser.pdf.PDF2XHTML pdf2XHTML)
Configures the given pdf2XHTML.- Parameters:
pdf2XHTML
-
-
getExtractAcroFormContent
public boolean getExtractAcroFormContent()
- See Also:
setExtractAcroFormContent(boolean)
-
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
-
-
getIfXFAExtractOnlyXFA
public boolean getIfXFAExtractOnlyXFA()
- Returns:
- how to handle XFA data if it exists
- See Also:
setIfXFAExtractOnlyXFA(boolean)
-
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
-
-
getExtractBookmarksText
public boolean getExtractBookmarksText()
- See Also:
setExtractBookmarksText(boolean)
-
setExtractBookmarksText
public void setExtractBookmarksText(boolean extractBookmarksText)
If true, extract bookmarks (document outline) text. Te default istrue
- Parameters:
extractBookmarksText
-
-
setExtractFontNames
public void setExtractFontNames(boolean extractFontNames)
Extract font names into a metadata field- Parameters:
extractFontNames
-
-
getExtractFontNames
public boolean getExtractFontNames()
-
getExtractInlineImages
public boolean getExtractInlineImages()
- See Also:
setExtractInlineImages(boolean)
-
setExtractInlineImages
public void setExtractInlineImages(boolean extractInlineImages)
If true, extract 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. Set totrue
with caution. The default isfalse
.- Parameters:
extractInlineImages
-- See Also:
setExtractUniqueInlineImagesOnly(boolean)
-
getExtractUniqueInlineImagesOnly
public boolean getExtractUniqueInlineImagesOnly()
-
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
-
-
getEnableAutoSpace
public boolean getEnableAutoSpace()
- See Also:
setEnableAutoSpace(boolean)
-
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.
-
getSuppressDuplicateOverlappingText
public boolean getSuppressDuplicateOverlappingText()
-
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.
-
getExtractAnnotationText
public boolean getExtractAnnotationText()
- See Also:
setExtractAnnotationText(boolean)
-
setExtractAnnotationText
public void setExtractAnnotationText(boolean extractAnnotationText)
If true (the default), text in annotations will be extracted.
-
getSortByPosition
public boolean getSortByPosition()
- See Also:
setSortByPosition(boolean)
-
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
public java.lang.Float getAverageCharTolerance()
- See Also:
setAverageCharTolerance(Float)
-
setAverageCharTolerance
public void setAverageCharTolerance(java.lang.Float averageCharTolerance)
SeePDFTextStripper.setAverageCharTolerance(float)
-
getSpacingTolerance
public java.lang.Float getSpacingTolerance()
- See Also:
setSpacingTolerance(Float)
-
setSpacingTolerance
public void setSpacingTolerance(java.lang.Float spacingTolerance)
SeePDFTextStripper.setSpacingTolerance(float)
-
getDropThreshold
public java.lang.Float getDropThreshold()
-
setDropThreshold
public void setDropThreshold(float dropThreshold)
-
getAccessChecker
public AccessChecker getAccessChecker()
-
setAccessChecker
public void setAccessChecker(AccessChecker accessChecker)
-
isCatchIntermediateIOExceptions
public boolean isCatchIntermediateIOExceptions()
Deprecated.- Returns:
- whether or not to catch IOExceptions
-
getCatchIntermediateIOExceptions
public boolean getCatchIntermediateIOExceptions()
- 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
-
-
setOcrStrategy
public void setOcrStrategy(PDFParserConfig.OCR_STRATEGY ocrStrategy)
Which strategy to use for OCR- Parameters:
ocrStrategy
-
-
setOcrStrategy
public void setOcrStrategy(java.lang.String ocrStrategyString)
Which strategy to use for OCR- Parameters:
ocrStrategyString
-
-
getOcrStrategy
public PDFParserConfig.OCR_STRATEGY getOcrStrategy()
- Returns:
- strategy to use for OCR
-
getOcrImageFormatName
public java.lang.String getOcrImageFormatName()
String representation of the image format used to render the page image for OCR (examples: png, tiff, jpeg)- Returns:
-
setOcrImageFormatName
public void setOcrImageFormatName(java.lang.String ocrImageFormatName)
- Parameters:
ocrImageFormatName
- name of image format used to render page image- See Also:
getOcrImageFormatName()
-
getOcrImageType
public org.apache.pdfbox.rendering.ImageType getOcrImageType()
Image type used to render the page image for OCR.- Returns:
- image type
- See Also:
setOcrImageType(ImageType)
-
setOcrImageType
public void setOcrImageType(org.apache.pdfbox.rendering.ImageType ocrImageType)
Image type used to render the page image for OCR.- Parameters:
ocrImageType
-
-
setOcrImageType
public void setOcrImageType(java.lang.String ocrImageTypeString)
Image type used to render the page image for OCR.- See Also:
setOcrImageType(ImageType)
-
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
-
getOcrImageScale
public float getOcrImageScale()
Deprecated.as of Tika 1.23, this is no longer used in rendering page images; usesetOcrDPI(int)
Scale to use if rendering a page and then running OCR on that rendered image. Default is 2.0f.
-
setOcrImageScale
public void setOcrImageScale(float ocrImageScale)
Deprecated.(as of Tika 1.23, this is no longer used in rendering page images)- Parameters:
ocrImageScale
-
-
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
-
-
getExtractActions
public boolean getExtractActions()
- Returns:
- whether or not to extract PDActions
- See Also:
setExtractActions(boolean)
-
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.- Returns:
-
setMaxMainMemoryBytes
@Deprecated public void setMaxMainMemoryBytes(int maxMainMemoryBytes)
Deprecated.- Parameters:
maxMainMemoryBytes
-
-
setMaxMainMemoryBytes
public void setMaxMainMemoryBytes(long maxMainMemoryBytes)
-
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
-
getSetKCMS
public boolean getSetKCMS()
-
setDetectAngles
public void setDetectAngles(boolean detectAngles)
-
getDetectAngles
public boolean getDetectAngles()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-