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

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
HasPdfProperties, ParamsAndFeaturesWritable, HasFeatures, PdfToTextTrait, PdfUtils, HasLocalProcess, HasOutputCol, HasInputCol, HasInputValidator, DefaultParamsWritable, MLWritable, Transformer, PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. PdfToText
  2. HasPdfProperties
  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. Serializable
  19. Identifiable
  20. AnyRef
  21. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

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( ... ) @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: Any): 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
    HasPdfProperties
  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 finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  28. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  29. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  30. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  31. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  32. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  34. final def getInputCol: String
    Definition Classes
    HasInputCol
  35. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  36. final def getOutputCol: String
    Definition Classes
    HasOutputCol
  37. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  38. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  39. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  40. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  41. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  42. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  43. final val inputCol: Param[String]
    Definition Classes
    HasInputCol
  44. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  45. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  46. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  47. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  48. def localProcess(input: Array[Map[String, Seq[IAnnotation]]]): Array[Map[String, Seq[IAnnotation]]]
    Definition Classes
    PdfToTextHasLocalProcess
  49. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  50. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  51. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  52. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  53. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  54. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  55. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  56. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  57. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  58. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  59. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  60. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  61. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  62. final val normalizeLigatures: BooleanParam
    Definition Classes
    HasPdfProperties
  63. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  64. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  65. def onWrite(path: String, spark: SparkSession): Unit
    Attributes
    protected
    Definition Classes
    ParamsAndFeaturesWritable
  66. final val onlyPageNum: BooleanParam
    Definition Classes
    HasPdfProperties
  67. final val originCol: Param[String]
    Definition Classes
    HasPdfProperties
  68. final val outputCol: Param[String]
    Definition Classes
    HasOutputCol
  69. def outputDataType: StructType
    Attributes
    protected
  70. final val pageNumCol: Param[String]
    Definition Classes
    HasPdfProperties
  71. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  72. final val partitionNum: IntParam
    Definition Classes
    HasPdfProperties
  73. 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
  74. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  75. def set[T](feature: StructFeature[T], value: T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  76. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  77. def set[T](feature: SetFeature[T], value: Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  78. def set[T](feature: ArrayFeature[T], value: Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  79. final def set(paramPair: ParamPair[_]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  80. final def set(param: String, value: Any): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  81. final def set[T](param: Param[T], value: T): PdfToText.this.type
    Definition Classes
    Params
  82. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  83. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  84. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  85. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  86. final def setDefault(paramPairs: ParamPair[_]*): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  87. final def setDefault[T](param: Param[T], value: T): PdfToText.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  88. def setExtractCoordinates(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  89. def setInputCol(value: String): PdfToText.this.type

    value

    Name of input annotation col

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

    Definition Classes
    HasPdfProperties
  91. def setOnlyPageNum(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  92. def setOriginCol(value: String): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  93. def setOutputCol(value: String): PdfToText.this.type

    value

    Name of extraction output col

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

    Definition Classes
    HasPdfProperties
  95. def setPartitionNum(value: Int): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  96. def setSort(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  97. def setSplitPage(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  98. def setStoreSplittedPdf(value: Boolean): PdfToText.this.type

    Definition Classes
    HasPdfProperties
  99. def setTextStripper(value: String): PdfToText.this.type

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

Inherited from HasPdfProperties

Inherited from ParamsAndFeaturesWritable

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 Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

getParam

setParam

Ungrouped