module HexaPDF::ImageLoader::PDF
This module is used for loading the first page of a PDF
file.
Loaded PDF
graphics are represented by form XObjects instead of image XObjects. However, the image/xobject drawing methods of HexaPDF::Content::Canvas
know how to handle them correctly so that this doesn't matter from a user's point of view.
See: PDF1.7 s8.10
Constants
- MAGIC_FILE_MARKER
The magic marker that tells us if the file/IO contains an
PDF
file.
Public Class Methods
handles?(filename) → true or false
click to toggle source
handles?(io) → true or false
Returns true
if the given file or IO stream can be handled, ie. if it contains an image in JPEG
format.
# File lib/hexapdf/image_loader/pdf.rb, line 60 def self.handles?(file_or_io) if file_or_io.kind_of?(String) File.read(file_or_io, 5, mode: 'rb') == MAGIC_FILE_MARKER else file_or_io.rewind file_or_io.read(5) == MAGIC_FILE_MARKER end end
load(document, filename) → form_obj
click to toggle source
load(document, io) → form_obj
Creates a PDF
form XObject from the PDF
file or IO stream.
See: DefaultConfiguration for the meaning of 'image_loader.pdf.use_stringio'.
# File lib/hexapdf/image_loader/pdf.rb, line 76 def self.load(document, file_or_io) idoc = if file_or_io.kind_of?(String) && document.config['image_loader.pdf.use_stringio'] HexaPDF::Document.open(file_or_io) elsif file_or_io.kind_of?(String) HexaPDF::Document.new(io: File.open(file_or_io, 'rb')) else HexaPDF::Document.new(io: file_or_io) end form = idoc.pages[0].to_form_xobject document.add(document.import(form)) end