Package org.apache.pdfbox.tools
Class PDFText2HTML
- java.lang.Object
-
- org.apache.pdfbox.contentstream.PDFStreamEngine
-
- org.apache.pdfbox.text.LegacyPDFStreamEngine
-
- org.apache.pdfbox.text.PDFTextStripper
-
- org.apache.pdfbox.tools.PDFText2HTML
-
public class PDFText2HTML extends PDFTextStripper
Wrap stripped text in simple HTML, trying to form HTML paragraphs. Paragraphs broken by pages, columns, or figures are not mended.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PDFText2HTML.FontState
A helper class to maintain the current font state.
-
Field Summary
Fields Modifier and Type Field Description private PDFText2HTML.FontState
fontState
private static int
INITIAL_PDF_TO_HTML_BYTES
-
Fields inherited from class org.apache.pdfbox.text.PDFTextStripper
charactersByArticle, document, LINE_SEPARATOR, output
-
-
Constructor Summary
Constructors Constructor Description PDFText2HTML()
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description private static void
appendEscaped(java.lang.StringBuilder builder, char character)
protected void
endArticle()
Write out the article separator.void
endDocument(PDDocument document)
This method is available for subclasses of this class.private static java.lang.String
escape(java.lang.String chars)
Escape some HTML characters.protected java.lang.String
getTitle()
This method will attempt to guess the title of the document using either the document properties or the first lines of text.protected void
startArticle(boolean isLTR)
Write out the article separator (div tag) with proper text direction information.protected void
startDocument(PDDocument document)
This method is available for subclasses of this class.protected void
writeHeader()
Deprecated.protected void
writeParagraphEnd()
Writes the paragraph end "</p>" to the output.protected void
writeString(java.lang.String chars)
Write a string to the output stream and escape some HTML characters.protected void
writeString(java.lang.String text, java.util.List<TextPosition> textPositions)
Write a string to the output stream, maintain font state, and escape some HTML characters.-
Methods inherited from class org.apache.pdfbox.text.PDFTextStripper
endPage, getAddMoreFormatting, getArticleEnd, getArticleStart, getAverageCharTolerance, getCharactersByArticle, getCurrentPageNo, getDropThreshold, getEndBookmark, getEndPage, getIndentThreshold, getLineSeparator, getListItemPatterns, getOutput, getPageEnd, getPageStart, getParagraphEnd, getParagraphStart, getSeparateByBeads, getSortByPosition, getSpacingTolerance, getStartBookmark, getStartPage, getSuppressDuplicateOverlappingText, getText, getWordSeparator, matchPattern, processPage, processPages, processTextPosition, setAddMoreFormatting, setArticleEnd, setArticleStart, setAverageCharTolerance, setDropThreshold, setEndBookmark, setEndPage, setIndentThreshold, setLineSeparator, setListItemPatterns, setPageEnd, setPageStart, setParagraphEnd, setParagraphStart, setShouldSeparateByBeads, setSortByPosition, setSpacingTolerance, setStartBookmark, setStartPage, setSuppressDuplicateOverlappingText, setWordSeparator, startArticle, startPage, writeCharacters, writeLineSeparator, writePage, writePageEnd, writePageStart, writeParagraphSeparator, writeParagraphStart, writeText, writeWordSeparator
-
Methods inherited from class org.apache.pdfbox.text.LegacyPDFStreamEngine
computeFontHeight, showGlyph
-
Methods inherited from class org.apache.pdfbox.contentstream.PDFStreamEngine
addOperator, applyTextAdjustment, beginMarkedContentSequence, beginText, decreaseLevel, endMarkedContentSequence, endText, getAppearance, getCurrentPage, getGraphicsStackSize, getGraphicsState, getInitialMatrix, getLevel, getResources, getTextLineMatrix, getTextMatrix, increaseLevel, operatorException, processAnnotation, processChildStream, processOperator, processOperator, processSoftMask, processTilingPattern, processTilingPattern, processTransparencyGroup, processType3Stream, registerOperatorProcessor, restoreGraphicsStack, restoreGraphicsState, saveGraphicsStack, saveGraphicsState, setLineDashPattern, setTextLineMatrix, setTextMatrix, showAnnotation, showFontGlyph, showFontGlyph, showForm, showGlyph, showText, showTextString, showTextStrings, showTransparencyGroup, showType3Glyph, showType3Glyph, transformedPoint, transformWidth, unsupportedOperator
-
-
-
-
Field Detail
-
INITIAL_PDF_TO_HTML_BYTES
private static final int INITIAL_PDF_TO_HTML_BYTES
- See Also:
- Constant Field Values
-
fontState
private final PDFText2HTML.FontState fontState
-
-
Method Detail
-
writeHeader
@Deprecated protected void writeHeader() throws java.io.IOException
Deprecated.Write the header to the output document. Now also writes the tag defining the character encoding.- Throws:
java.io.IOException
- If there is a problem writing out the header to the document.
-
startDocument
protected void startDocument(PDDocument document) throws java.io.IOException
Description copied from class:PDFTextStripper
This method is available for subclasses of this class. It will be called before processing of the document start.- Overrides:
startDocument
in classPDFTextStripper
- Parameters:
document
- The PDF document that is being processed.- Throws:
java.io.IOException
- If an IO error occurs.
-
endDocument
public void endDocument(PDDocument document) throws java.io.IOException
This method is available for subclasses of this class. It will be called after processing of the document finishes.- Overrides:
endDocument
in classPDFTextStripper
- Parameters:
document
- The PDF document that is being processed.- Throws:
java.io.IOException
- If an IO error occurs.
-
getTitle
protected java.lang.String getTitle()
This method will attempt to guess the title of the document using either the document properties or the first lines of text.- Returns:
- returns the title.
-
startArticle
protected void startArticle(boolean isLTR) throws java.io.IOException
Write out the article separator (div tag) with proper text direction information.- Overrides:
startArticle
in classPDFTextStripper
- Parameters:
isLTR
- true if direction of text is left to right- Throws:
java.io.IOException
- If there is an error writing to the stream.
-
endArticle
protected void endArticle() throws java.io.IOException
Write out the article separator.- Overrides:
endArticle
in classPDFTextStripper
- Throws:
java.io.IOException
- If there is an error writing to the stream.
-
writeString
protected void writeString(java.lang.String text, java.util.List<TextPosition> textPositions) throws java.io.IOException
Write a string to the output stream, maintain font state, and escape some HTML characters. The font state is only preserved per word.- Overrides:
writeString
in classPDFTextStripper
- Parameters:
text
- The text to write to the stream.textPositions
- the corresponding text positions- Throws:
java.io.IOException
- If there is an error writing to the stream.
-
writeString
protected void writeString(java.lang.String chars) throws java.io.IOException
Write a string to the output stream and escape some HTML characters.- Overrides:
writeString
in classPDFTextStripper
- Parameters:
chars
- String to be written to the stream- Throws:
java.io.IOException
- If there is an error writing to the stream.
-
writeParagraphEnd
protected void writeParagraphEnd() throws java.io.IOException
Writes the paragraph end "</p>" to the output. Furthermore, it will also clear the font state. Write something (if defined) at the end of a paragraph.- Overrides:
writeParagraphEnd
in classPDFTextStripper
- Throws:
java.io.IOException
- if something went wrong
-
escape
private static java.lang.String escape(java.lang.String chars)
Escape some HTML characters.- Parameters:
chars
- String to be escaped- Returns:
- returns escaped String.
-
appendEscaped
private static void appendEscaped(java.lang.StringBuilder builder, char character)
-
-