StabRise/spark-pdf
StabRise/spark-pdf has 83 GitHub stars and 4 forks. Star changes are not measured yet. Last checked 2026-11-14 03:47 UTC. Last push 2025-04-27.
What you can do
- Read PDF documents to the Spark DataFrame
- Support efficient read PDF files lazy per page
- Support big files, up to 10k pages
- Support scanned PDF files (call OCR for text recognition from the images)
Crecimiento de estrellas medido
- in 24h
- Recopilando historial
- in 7 days
- Recopilando historial
- in 15 days
- Recopilando historial
- in 1 month
- Recopilando historial
Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.
Acerca de
PDF DataSource for Apache Spark, allow to read PDF files directly to the DataFrame and ocr it
DatosREADME.md
Original⭐ Star us on GitHub — it motivates us a lot!
Source Code: https://github.com/StabRise/spark-pdf
Quick Start Jupyter Notebook Spark 3.5.x on Databricks: PdfDataSourceDatabricks.ipynb
Quick Start Jupyter Notebook Spark 3.x.x: PdfDataSource.ipynb
Quick Start Jupyter Notebook Spark 4.0.x: PdfDataSourceSpark4.ipynb
With Spark Connect: PdfDataSourceSparkConnect.ipynb
Welcome to the Spark PDF
The project provides a custom data source for the Apache Spark that allows you to read PDF files into the Spark DataFrame.
If you found useful this project, please give a star to the repository.
👉 Works on Databricks now. See the Databricks example. Solved issue with read from the volume (Unity Catalog).
Key features:
- Read PDF documents to the Spark DataFrame
- Support efficient read PDF files lazy per page
- Support big files, up to 10k pages
- Support scanned PDF files (call OCR for text recognition from the images)
- No need to install Tesseract OCR, it's included in the package
- 👉 Compatible with ScaleDP, an Open-Source Library for Processing Documents using AI/ML in Apache Spark.
- Works with Spark Connect
Requirements
- Java 8, 11, 17
- Apache Spark 3.3.2, 3.4.1, 3.5.0, 4.0.0
- Ghostscript 9.50 or later (only for the GhostScript reader)
Spark 4.0.0 is supported in the version 0.1.11 and later (need Java 17 and Scala 2.13).
Installation
Binary package is available in the Maven Central Repository.
- Spark 3.5.*: com.stabrise:spark-pdf-spark35_2.12:0.1.17
- Spark 3.4.*: com.stabrise:spark-pdf-spark34_2.12:0.1.11 (issue with publishing fresh version)
- Spark 3.3.*: com.stabrise:spark-pdf-spark33_2.12:0.1.17
- Spark 4.0.*: com.stabrise:spark-pdf-spark40_2.13:0.1.17
Options for the data source:
imageType: Oputput image type. Can be: "BINARY", "GREY", "RGB". Default: "RGB".resolution: Resolution for rendering PDF page to the image. Default: "300" dpi.pagePerPartition: Number pages per partition in Spark DataFrame. Default: "5".reader: Supports:pdfBox- based on PdfBox java lib,gs- based on GhostScript (need installation GhostScipt to the system)ocrConfig: Tesseract OCR configuration. Default: "psm=3". For more information see Tesseract OCR Paramspassword: Password for protected PDF files
Output Columns in the DataFrame:
The DataFrame contains the following columns:
path: path to the filepage_number: page number of the documenttext: extracted text from the text layer of the PDF pageimage: image representation of the pagedocument: the OCR-extracted text from the rendered image (calls Tesseract OCR)partition_number: partition number
Output Schema:
root
|-- path: string (nullable = true)
|-- filename: string (nullable = true)
|-- page_number: integer (nullable = true)
|-- partition_number: integer (nullable = true)
|-- text: string (nullable = true)
|-- image: struct (nullable = true)
| |-- path: string (nullable = true)
| |-- resolution: integer (nullable = true)
| |-- data: binary (nullable = true)
| |-- imageType: string (nullable = true)
| |-- exception: string (nullable = true)
| |-- height: integer (nullable = true)
| |-- width: integer (nullable = true)
|-- document: struct (nullable = true)
| |-- path: string (nullable = true)
| |-- text: string (nullable = true)
| |-- outputType: string (nullable = true)
| |-- bBoxes: array (nullable = true)
| | |-- element: struct (containsNull = true)
| | | |-- text: string (nullable = true)
| | | |-- score: float (nullable = true)
| | | |-- x: integer (nullable = true)
| | | |-- y: integer (nullable = true)
| | | |-- width: integer (nullable = true)
| | | |-- height: integer (nullable = true)
| |-- exception: string (nullable = true)
Example of usage
Scala
import org.apache.spark.sql.SparkSession
val spark = SparkSession.builder()
.appName("Spark PDF Example")
.master("local[*]")
.config("spark.jars.packages", "com.stabrise:spark-pdf-spark35_2.12:0.1.16")
.getOrCreate()
val df = spark.read.format("pdf")
.option("imageType", "BINARY")
.option("resolution", "200")
.option("pagePerPartition", "2")
.option("reader", "pdfBox")
.option("ocrConfig", "psm=11")
.option("password", "pdf_password")
.load("path to the pdf file(s)")
df.select("path", "document").show()
Python
from pyspark.sql import SparkSession
spark = SparkSession.builder \
.master("local[*]") \
.appName("SparkPdf") \
.config("spark.jars.packages", "com.stabrise:spark-pdf-spark35_2.12:0.1.16") \
.getOrCreate()
df = spark.read.format("pdf") \
.option("imageType", "BINARY") \
.option("resolution", "200") \
.option("pagePerPartition", "2") \
.option("reader", "pdfBox") \
.option("ocrConfig", "psm=11") \
.option("password", "pdf_password") \
.load("path to the pdf file(s)")
df.select("path", "document").show()
Disclaimer
This project is not affiliated with, endorsed by, or connected to the Apache Software Foundation or Apache Spark.
Explorar proyectos relacionados
Asabeneh/30-Days-Of-Python
El reto de programación 30 Days of Python es una guía paso a paso para aprender el lenguaje de programación Python en 30 días. Este reto puede llevar más de 100 días. Sigue tu propio ritmo. Estos vídeos también pueden ayudarte: https://www.youtube.com/channel/UC7PNRuno1rzYPb1xLa4yktw
78,715 estrellasgrafana/grafana
Plataforma abierta y componible de observabilidad y visualización de datos. Visualiza métricas, registros y trazas de múltiples fuentes, como Prometheus, Loki, Elasticsearch, InfluxDB, Postgres y muchas más.
77,894 estrellasredis/redis
Para los desarrolladores que crean aplicaciones en tiempo real basadas en datos, Redis es la opción preferida, la más rápida y la de más funciones como caché, servidor de estructuras de datos y motor de consultas de documentos y vectores.
77,491 estrellasapache/superset
Apache Superset es una plataforma de visualización y exploración de datos.
75,523 estrellas