class PdfToText extends Transformer with DefaultParamsWritable with HasInputValidator with HasInputCol with HasOutputCol with HasLocalProcess with PdfToTextTrait with HasPdfToTextProperties

Extract text from PDF document to a single string or to several strings per each page. Input is a column with binary representation of PDF document. For the output it generates column with text and page number. Explode each page as separate row if split to page enabled.

It can be configured with the following properties:

  • pageNumCol: Page number output column name.
  • originCol: Input column name with original path of file.
  • partitionNum: Number of partitions. By default, it is set to 0.
  • storeSplittedPdf: Force to store bytes content of split pdf. By default, it is set to false.
  • splitPage: Enable/disable splitting per page to identify page numbers and improve performance. By default, it is set to true.
  • onlyPageNum: Extract only page numbers. By default, it is set to false.
  • textStripper: Text stripper type used for output layout and formatting.
  • sort: Enable/disable sorting content on the page. By default, it is set to false.

Example

    val pdfToText = new PdfToText()
      .setStoreSplittedPdf(true)
      .setSplitPage(true)
    val filesDf = spark.read.format("binaryFile").load("Documents/files/pdf")
    val pipelineModel = new Pipeline()
      .setStages(Array(pdfToText))
      .fit(filesDf)

    val pdfDf = pipelineModel.transform(filesDf)

pdfDf.show()
+--------------------+--------------------+------+--------------------+
|                path|    modificationTime|length|                text|
+--------------------+--------------------+------+--------------------+
|file:/Users/paula...|2025-05-15 11:33:...| 25803|This is a Title \...|
|file:/Users/paula...|2025-05-15 11:33:...| 15629|                  \n|
|file:/Users/paula...|2025-05-15 11:33:...| 15629|                  \n|
|file:/Users/paula...|2025-05-15 11:33:...| 15629|                  \n|
|file:/Users/paula...|2025-05-15 11:33:...|  9487|   This is a page.\n|
|file:/Users/paula...|2025-05-15 11:33:...|  9487|This is another p...|
|file:/Users/paula...|2025-05-15 11:33:...|  9487| Yet another page.\n|
|file:/Users/paula...|2025-05-15 11:56:...|  1563|Hello, this is li...|
+--------------------+--------------------+------+--------------------+

pdfDf.printSchema()
root
 |-- path: string (nullable = true)
 |-- modificationTime: timestamp (nullable = true)
 |-- length: long (nullable = true)
 |-- text: string (nullable = true)
 |-- height_dimension: integer (nullable = true)
 |-- width_dimension: integer (nullable = true)
 |-- content: binary (nullable = true)
 |-- exception: string (nullable = true)
 |-- pagenum: integer (nullable = true)
Linear Supertypes
HasPdfToTextProperties, ParamsAndFeaturesWritable, HasFeatures, PdfToTextTrait, PdfUtils, HasLocalProcess, HasOutputCol, HasInputCol, HasInputValidator, DefaultParamsWritable, MLWritable, Transformer, PipelineStage, Logging, Params, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. PdfToText
  2. HasPdfToTextProperties
  3. ParamsAndFeaturesWritable
  4. HasFeatures
  5. PdfToTextTrait
  6. PdfUtils
  7. HasLocalProcess
  8. HasOutputCol
  9. HasInputCol
  10. HasInputValidator
  11. DefaultParamsWritable
  12. MLWritable
  13. Transformer
  14. PipelineStage
  15. Logging
  16. Params
  17. Serializable
  18. Identifiable
  19. AnyRef
  20. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new PdfToText()
  2. new PdfToText(uid: String)

Type Members

  1. implicit class ChainException extends AnyRef
    Definition Classes
    PdfUtils
  2. implicit class exceptionUtils extends AnyRef
    Definition Classes
    PdfUtils

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def $[T](param: Param[T]): T
    Attributes
    protected
    Definition Classes
    Params
  4. def $$[T](feature: StructFeature[T]): T
    Attributes
    protected
    Definition Classes
    HasFeatures
  5. def $$[K, V](feature: MapFeature[K, V]): Map[K, V]
    Attributes
    protected
    Definition Classes
    HasFeatures
  6. def $$[T](feature: SetFeature[T]): Set[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  7. def $$[T](feature: ArrayFeature[T]): Array[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. val MAX_CHARACTER_BEFORE_HEADER: Int
    Definition Classes
    PdfUtils
  10. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  11. def checkAndFixPdf(content: Array[Byte]): Array[Byte]
    Definition Classes
    PdfUtils
  12. final def clear(param: Param[_]): PdfToText.this.type
    Definition Classes
    Params
  13. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @HotSpotIntrinsicCandidate() @native()
  14. def compareDataTypes(dtype1: DataType, dtype2: DataType): Boolean
    Definition Classes
    HasInputValidator
  15. def copy(extra: ParamMap): Transformer
    Definition Classes
    PdfToText → Transformer → PipelineStage → Params
  16. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  17. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  18. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  19. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  20. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  21. def explainParams(): String
    Definition Classes
    Params
  22. final val extractCoordinates: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  23. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  24. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  25. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  26. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  27. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  28. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  29. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  30. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  31. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  32. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  33. final def getInputCol: String
    Definition Classes
    HasInputCol
  34. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  35. final def getOutputCol: String
    Definition Classes
    HasOutputCol
  36. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  37. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  38. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  39. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  40. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  41. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  42. final val inputCol: Param[String]
    Definition Classes
    HasInputCol
  43. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  44. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  45. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  46. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  47. def localProcess(input: Array[Map[String, Seq[IAnnotation]]]): Array[Map[String, Seq[IAnnotation]]]
    Definition Classes
    PdfToTextHasLocalProcess
  48. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  49. def logDebug(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  50. def logDebug(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  51. def logError(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  52. def logError(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  53. def logInfo(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  54. def logInfo(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  55. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  56. def logTrace(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. def logTrace(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  58. def logWarning(msg: => String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  59. def logWarning(msg: => String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  60. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  61. final val normalizeLigatures: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  62. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  63. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @HotSpotIntrinsicCandidate() @native()
  64. def onWrite(path: String, spark: SparkSession): Unit
    Attributes
    protected
    Definition Classes
    ParamsAndFeaturesWritable
  65. final val onlyPageNum: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  66. final val originCol: Param[String]
    Definition Classes
    HasPdfToTextProperties
  67. final val outputCol: Param[String]
    Definition Classes
    HasOutputCol
  68. def outputDataType: StructType
    Attributes
    protected
  69. final val pageNumCol: Param[String]
    Definition Classes
    HasPdfToTextProperties
  70. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  71. final val partitionNum: IntParam
    Definition Classes
    HasPdfToTextProperties
  72. def pdfToText(content: Array[Byte], onlyPageNum: Boolean, splitPage: Boolean, storeSplittedPdf: Boolean, sort: Boolean, textStripper: String, extractCoordinates: Boolean, normalizeLigatures: Boolean = false): Seq[(String, Seq[PageMatrix], Int, Int, Array[Byte], String, Int)]
    Definition Classes
    PdfToTextTrait
  73. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @throws("If the input path already exists but overwrite is not enabled.") @Since("1.6.0")
  74. def set[T](feature: StructFeature[T], value: T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  75. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  76. def set[T](feature: SetFeature[T], value: Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  77. def set[T](feature: ArrayFeature[T], value: Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  78. final def set(paramPair: ParamPair[_]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  79. final def set(param: String, value: Any): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  80. final def set[T](param: Param[T], value: T): PdfToText.this.type
    Definition Classes
    Params
  81. def setDefault[T](feature: StructFeature[T], value: () => T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  82. def setDefault[K, V](feature: MapFeature[K, V], value: () => Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  83. def setDefault[T](feature: SetFeature[T], value: () => Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  84. def setDefault[T](feature: ArrayFeature[T], value: () => Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  85. final def setDefault(paramPairs: ParamPair[_]*): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  86. final def setDefault[T](param: Param[T], value: T): PdfToText.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  87. def setExtractCoordinates(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  88. def setInputCol(value: String): PdfToText.this.type

    value

    Name of input annotation col

  89. def setNormalizeLigatures(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  90. def setOnlyPageNum(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  91. def setOriginCol(value: String): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  92. def setOutputCol(value: String): PdfToText.this.type

    value

    Name of extraction output col

  93. def setPageNumCol(value: String): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  94. def setPartitionNum(value: Int): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  95. def setSort(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  96. def setSplitPage(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  97. def setStoreSplittedPdf(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  98. def setTextStripper(value: String): PdfToText.this.type

    Definition Classes
    HasPdfToTextProperties
  99. final val sort: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  100. final val splitPage: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  101. final val storeSplittedPdf: BooleanParam
    Definition Classes
    HasPdfToTextProperties
  102. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  103. final val textStripper: Param[String]
    Definition Classes
    HasPdfToTextProperties
  104. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  105. def transform(df: Dataset[_]): DataFrame
    Definition Classes
    PdfToText → Transformer
  106. def transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since("2.0.0")
  107. def transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
    Definition Classes
    Transformer
    Annotations
    @varargs() @Since("2.0.0")
  108. def transformSchema(schema: StructType): StructType
    Definition Classes
    PdfToText → PipelineStage
  109. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  110. val uid: String
    Definition Classes
    PdfToTextHasInputValidator → Identifiable
  111. def validateInputCol(schema: StructType, colName: String, colType: DataType): Unit
    Definition Classes
    HasInputValidator
  112. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  113. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  114. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  115. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

    (Since version 9)

Inherited from HasPdfToTextProperties

Inherited from HasFeatures

Inherited from PdfToTextTrait

Inherited from PdfUtils

Inherited from HasLocalProcess

Inherited from HasOutputCol

Inherited from HasInputCol

Inherited from HasInputValidator

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from Transformer

Inherited from PipelineStage

Inherited from Logging

Inherited from Params

Inherited from Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

getParam

setParam

Ungrouped