Class: PDF::Core::Page

Inherits:
Object show all
Defined in:
lib/asciidoctor/pdf/ext/pdf-core/page.rb

Constant Summary collapse

InitialPageContent =
%(q\n)

Instance Method Summary collapse

Instance Method Details

#empty?Boolean

Returns whether the current page is empty based on tare content stream (i.e., no content has been written). Returns false if a page has not yet been created.

Returns:

  • (Boolean)


13
14
15
# File 'lib/asciidoctor/pdf/ext/pdf-core/page.rb', line 13

def empty?
  content.stream.filtered_stream == (@tare_content_stream ||= InitialPageContent) && document.page_number > 0
end

#importedObject Also known as: imported_page

Flags this page as imported.



19
20
21
# File 'lib/asciidoctor/pdf/ext/pdf-core/page.rb', line 19

def imported
  @imported_page = true
end

#reset_contentObject

Reset the content of the page. Note that this method may leave behind an orphaned background image.



27
28
29
30
31
32
33
34
35
36
# File 'lib/asciidoctor/pdf/ext/pdf-core/page.rb', line 27

def reset_content
  return if content.stream.filtered_stream == InitialPageContent
  xobjects.clear
  ext_gstates.clear
  new_content = document.state.store[document.ref({})]
  new_content << 'q' << ?\n
  content.replace new_content
  @tare_content_stream = InitialPageContent
  nil
end

#tare_content_streamObject

Record the page’s current state as the tare content stream (i.e., empty, meaning no content has been written).



7
8
9
# File 'lib/asciidoctor/pdf/ext/pdf-core/page.rb', line 7

def tare_content_stream
  @tare_content_stream = content.stream.filtered_stream
end