class HexaPDF::Type::Form
Represents a form XObject of a PDF document.
See: PDF1.7 s8.10
Attributes
Returns the path to the PDF file that was used when creating the form object.
This value is only set when the form object was created by using the image loading facility (i.e. when treating a single page PDF file as image) and not when the form object was created in any other way (i.e. manually created or already part of a loaded PDF file).
Public Instance Methods
Returns the rectangle defining the bounding box of the form.
# File lib/hexapdf/type/form.rb, line 73 def box self[:BBox] end
Returns the canvas for the form XObject.
The canvas object is cached once it is created so that its graphics state is correctly retained without the need for parsing its contents.
If the bounding box of the form XObject doesn't have its origin at (0, 0), the canvas origin is translated into the bottom left corner so that this detail doesn't matter when using the canvas. This means that the canvas' origin is always at the bottom left corner of the bounding box.
Note that a canvas can only be retrieved for initially empty form XObjects!
# File lib/hexapdf/type/form.rb, line 138 def canvas cache(:canvas) do unless stream.empty? raise HexaPDF::Error, "Cannot create a canvas for a form XObjects with contents" end canvas = Content::Canvas.new(self) if box.left != 0 || box.bottom != 0 canvas.save_graphics_state.translate(box.left, box.bottom) end self.stream = canvas.stream_data set_filter(:FlateDecode) canvas end end
Replaces the contents of the form XObject with the given string.
This also clears the cache to avoid returning invalid objects.
Note: This is the same as stream=
but here for interface compatibility with Page
.
# File lib/hexapdf/type/form.rb, line 99 def contents=(data) self.stream = data clear_cache end
Returns the height of the bounding box (see box
).
# File lib/hexapdf/type/form.rb, line 83 def height box.height end
Processes the content stream of the form XObject with the given processor object.
The original_resources
argument has to be set to a page's resources if this form XObject is processed as part of this page.
See: HexaPDF::Content::Processor
# File lib/hexapdf/type/form.rb, line 116 def process_contents(processor, original_resources: nil) processor.resources = if self[:Resources] self[:Resources] elsif original_resources original_resources else document.wrap({}, type: :XXResources) end Content::Parser.parse(contents, processor) end
Returns the resource dictionary which is automatically created if it doesn't exist.
# File lib/hexapdf/type/form.rb, line 105 def resources self[:Resources] ||= document.wrap({ProcSet: [:PDF, :Text, :ImageB, :ImageC, :ImageI]}, type: :XXResources) end
Returns the width of the bounding box (see box
).
# File lib/hexapdf/type/form.rb, line 78 def width box.width end