Class: Pdfrb::Linearization::Writer

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/linearization/writer.rb

Overview

Writes a PDF in linearized format (ISO 32000-2 ยง7.6.2, Annex F).

Approach: serialize all objects to a temp buffer, compute final offsets, then assemble the file with the linearization parameter dict as the first indirect object. The lin dict values (/L, /H, /O, /E, /N, /T) are filled from the computed layout.

This produces a structurally valid linearized PDF with page-offset hints. Full optimization (shared-object tables, minimal-download ordering) is future work.

Defined Under Namespace

Classes: Layout

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Writer

Returns a new instance of Writer.



31
32
33
34
# File 'lib/pdfrb/linearization/writer.rb', line 31

def initialize(document)
  @document = document
  @serializer = Pdfrb::Serializer.new
end

Instance Method Details

#write(io) ⇒ void

This method returns an undefined value.

Parameters:

  • io (IO)

    target output.



38
39
40
41
42
43
44
45
46
47
# File 'lib/pdfrb/linearization/writer.rb', line 38

def write(io)
  io.binmode

  pages = collect_pages
  return write_non_linearized(io) if pages.length < 2

  layout = compute_layout(pages)
  assembled = assemble_file(pages, layout)
  io.write(assembled)
end