class Mindee::PDF::PDFExtractor::ExtractedPDF
An extracted sub-Pdf.
def as_input_source
-
(Mindee::Input::Source::BytesInputSource)
-
def as_input_source Mindee::Input::Source::BytesInputSource.new(@pdf_bytes.read, @filename) end
def initialize(pdf_bytes, filename)
-
filename
(String
) -- -
pdf_bytes
(StreamIO
) --
def initialize(pdf_bytes, filename) @pdf_bytes = pdf_bytes @filename = filename end
def page_count
-
(Integer)
-
def page_count current_pdf = Mindee::PDF::PDFProcessor.open_pdf(pdf_bytes) current_pdf.pages.size rescue TypeError, Origami::InvalidPDFError raise Errors::MindeePDFError, 'Could not retrieve page count from Extracted PDF object.' end
def write_to_file(output_path, override: false)
-
override
(bool
) -- Whether to override the destination file. -
output_path
(String
) -- Path to write to.
def write_to_file(output_path, override: false) raise Errors::MindeePDFError, 'Provided path is not a file' if File.directory?(output_path) raise Errors::MindeePDFError, 'Invalid save path provided' unless File.exist?( File.expand_path('..', output_path) ) && !override if File.extname(output_path).downcase == 'pdf' base_path = File.expand_path('..', output_path) output_path = File.expand_path("#{File.basename(output_path)}.pdf", base_path) end File.write(output_path, @pdf_bytes) end