Class: Tahweel::PdfSplitter
- Inherits:
-
Object
- Object
- Tahweel::PdfSplitter
- Defined in:
- lib/tahweel/pdf_splitter.rb
Overview
Handles the logic for splitting a PDF file into individual image pages. Uses Poppler utils (pdftoppm, pdfinfo) for high-performance image processing.
Constant Summary collapse
- DEFAULT_DPI =
Default DPI used when converting PDF pages to images. 150 DPI is a good balance between quality and file size for general documents.
150
Class Method Summary collapse
-
.split(pdf_path, dpi: DEFAULT_DPI) {|Hash| ... } ⇒ Hash
Convenience class method to initialize and execute the split operation in one go.
Instance Method Summary collapse
-
#initialize(pdf_path, dpi: DEFAULT_DPI) ⇒ PdfSplitter
constructor
Initializes a new PdfSplitter instance.
-
#split {|Hash| ... } ⇒ Hash
Executes the PDF splitting process.
Constructor Details
#initialize(pdf_path, dpi: DEFAULT_DPI) ⇒ PdfSplitter
Initializes a new PdfSplitter instance.
37 38 39 40 |
# File 'lib/tahweel/pdf_splitter.rb', line 37 def initialize(pdf_path, dpi: DEFAULT_DPI) @pdf_path = pdf_path @dpi = dpi end |
Class Method Details
.split(pdf_path, dpi: DEFAULT_DPI) {|Hash| ... } ⇒ Hash
Convenience class method to initialize and execute the split operation in one go.
}
31 |
# File 'lib/tahweel/pdf_splitter.rb', line 31 def self.split(pdf_path, dpi: DEFAULT_DPI, &) = new(pdf_path, dpi:).split(&) |
Instance Method Details
#split {|Hash| ... } ⇒ Hash
Executes the PDF splitting process.
This method performs the following steps:
- Checks if Poppler utils are available (installs if missing on Windows).
- Validates the existence of the source PDF file.
- Creates a unique temporary directory for output.
- Iterates through each page of the PDF and converts it to a PNG image.
}
61 62 63 64 65 66 67 |
# File 'lib/tahweel/pdf_splitter.rb', line 61 def split(&) validate_file_exists! PopplerInstaller.ensure_installed! setup_output_directory process_pages(&) result end |