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 the libvips library 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.
35 36 37 38 39 |
# File 'lib/tahweel/pdf_splitter.rb', line 35 def initialize(pdf_path, dpi: DEFAULT_DPI) @pdf_path = pdf_path @dpi = dpi @image_paths = [] 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.
}
29 |
# File 'lib/tahweel/pdf_splitter.rb', line 29 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 libvips is installed (skips 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(&) check_libvips_installed! validate_file_exists! setup_output_directory process_pages(&) result end |