Class PDFText2Markdown.FontState

java.lang.Object
org.apache.pdfbox.tools.PDFText2Markdown.FontState
Enclosing class:
PDFText2Markdown

private static class PDFText2Markdown.FontState extends Object
A helper class to maintain the current font state. Its public methods will emit opening and closing tags as needed and in the correct order.

Responsible for applying Markdown formatting based on font properties. Supports bold and italic text based on font descriptors.

  • Field Details

    • stateList

      private final List<String> stateList
    • stateSet

      private final Set<String> stateSet
  • Constructor Details

    • FontState

      private FontState()
  • Method Details

    • push

      public String push(String text, List<TextPosition> textPositions)
      Pushes new TextPositions into the font state. The state is only preserved correctly for each letter if the number of letters in text matches the number of TextPosition objects. Otherwise, it's done once for the complete array (just by looking at its first entry).
      Returns:
      A string that contains the text including tag changes caused by its font state.
    • clear

      public String clear()
      Closes all open Markdown formatting.
      Returns:
      A string that contains the closing tags of all currently open Markdown formatting.
    • push

      protected String push(StringBuilder buffer, char character, TextPosition textPosition)
    • open

      private String open(String tag)
    • close

      private String close(String tag)
    • closeUntil

      private int closeUntil(StringBuilder tagsBuilder, String endTag)
    • openTag

      private String openTag(String tag)
    • closeTag

      private String closeTag(String tag)
    • isBold

      private boolean isBold(PDFontDescriptor descriptor)
    • isItalic

      private boolean isItalic(PDFontDescriptor descriptor)