Packages

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)

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 def extractParamMap(): ParamMap
    Definition Classes
    Params
  23. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  24. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  25. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  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[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @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
    @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 def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  62. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  63. def onWrite(path: String, spark: SparkSession): Unit
    Attributes
    protected
    Definition Classes
    ParamsAndFeaturesWritable
  64. final val onlyPageNum: BooleanParam
    Definition Classes
    HasPdfProperties
  65. final val originCol: Param[String]
    Definition Classes
    HasPdfProperties
  66. final val outputCol: Param[String]
    Definition Classes
    HasOutputCol
  67. def outputDataType: StructType
    Attributes
    protected
  68. final val pageNumCol: Param[String]
    Definition Classes
    HasPdfProperties
  69. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  70. final val partitionNum: IntParam
    Definition Classes
    HasPdfProperties
  71. def pdfToText(content: Array[Byte], onlyPageNum: Boolean, splitPage: Boolean, storeSplittedPdf: Boolean, sort: Boolean, textStripper: String): Seq[(String, Int, Int, Array[Byte], String, Int)]
    Definition Classes
    PdfToTextTrait
  72. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  73. def set[T](feature: StructFeature[T], value: T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  74. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  75. def set[T](feature: SetFeature[T], value: Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  76. def set[T](feature: ArrayFeature[T], value: Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  77. final def set(paramPair: ParamPair[_]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  78. final def set(param: String, value: Any): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  79. final def set[T](param: Param[T], value: T): PdfToText.this.type
    Definition Classes
    Params
  80. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  81. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  82. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  83. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  84. final def setDefault(paramPairs: ParamPair[_]*): PdfToText.this.type
    Attributes
    protected
    Definition Classes
    Params
  85. final def setDefault[T](param: Param[T], value: T): PdfToText.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  86. def setInputCol(value: String): PdfToText.this.type

    value

    Name of input annotation col

  87. def setOnlyPageNum(value: Boolean): PdfToText.this.type

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

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

    value

    Name of extraction output col

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

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

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

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

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

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

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