Method: Origami::PDF#each_object

Defined in:
lib/origami/pdf.rb

#each_object(compressed: false, recursive: false) ⇒ Object

Iterates over the objects of the document. compressed: iterates over the objects inside object streams. recursive: iterates recursively inside objects like arrays and dictionaries.



332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
# File 'lib/origami/pdf.rb', line 332

def each_object(compressed: false, recursive: false)
    return enum_for(__method__, compressed: compressed,
                                recursive: recursive
                   ) unless block_given?

    walk_object = -> (object) do
        case object
        when Dictionary
            object.each_value do |value|
                yield(value)
                walk_object.call(value)
            end

        when Array
            object.each do |child|
                yield(child)
                walk_object.call(child)
            end

        when Stream
            yield(object.dictionary)
            walk_object.call(object.dictionary)
        end
    end

    @revisions.each do |revision|
        revision.each_object do |object|
            yield(object)

            walk_object.call(object) if recursive

            if object.is_a?(ObjectStream) and compressed
                object.each do |child_obj|
                    yield(child_obj)

                    walk_object.call(child_obj) if recursive
                end
            end
        end
    end
end