Class: MuPDF::Page
- Inherits:
-
Object
- Object
- MuPDF::Page
- Defined in:
- lib/mupdf/page.rb
Overview
A wrapper for a PDF page within a PDF document.
Constant Summary collapse
- REGEX =
%r{<page pagenum="(?<pagenum>\d+)">(?<content>.*?)</page>}m
- MEDIA_BOX_REGEX =
%r{<MediaBox (?<content>.*?) />}
- CROP_BOX_REGEX =
%r{<CropBox (?<content>.*?) />}
- ART_BOX_REGEX =
%r{<ArtBox (?<content>.*?) />}
- BLEED_BOX_REGEX =
%r{<BleedBox (?<content>.*?) />}
- TRIM_BOX_REGEX =
%r{<TrimBox (?<content>.*?) />}
Instance Attribute Summary collapse
- #art_box ⇒ MuPDFBox?
- #bleed_box ⇒ MuPDFBox?
- #crop_box ⇒ MuPDFBox?
- #media_box ⇒ MuPDFBox?
- #number ⇒ Integer
- #trim_box ⇒ MuPDFBox?
Class Method Summary collapse
- .parse(text) ⇒ Array<MuPDF::Page>
- .parse_art_box(text) ⇒ MuPDF::Box?
- .parse_bleed_box(text) ⇒ MuPDF::Box?
- .parse_crop_box(text) ⇒ MuPDF::Box?
- .parse_media_box(text) ⇒ MuPDF::Box?
- .parse_trim_box(text) ⇒ MuPDF::Box?
Instance Method Summary collapse
- #height ⇒ BigDecimal?
-
#initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ String
- #width ⇒ BigDecimal?
Constructor Details
#initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) ⇒ Page
Returns a new instance of Page.
109 110 111 112 113 114 115 116 |
# File 'lib/mupdf/page.rb', line 109 def initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) @media_box = media_box @crop_box = crop_box @art_box = art_box @bleed_box = bleed_box @trim_box = trim_box @number = number end |
Instance Attribute Details
#art_box ⇒ MuPDFBox?
89 90 91 |
# File 'lib/mupdf/page.rb', line 89 def art_box @art_box end |
#bleed_box ⇒ MuPDFBox?
93 94 95 |
# File 'lib/mupdf/page.rb', line 93 def bleed_box @bleed_box end |
#crop_box ⇒ MuPDFBox?
85 86 87 |
# File 'lib/mupdf/page.rb', line 85 def crop_box @crop_box end |
#media_box ⇒ MuPDFBox?
81 82 83 |
# File 'lib/mupdf/page.rb', line 81 def media_box @media_box end |
#number ⇒ Integer
101 102 103 |
# File 'lib/mupdf/page.rb', line 101 def number @number end |
#trim_box ⇒ MuPDFBox?
97 98 99 |
# File 'lib/mupdf/page.rb', line 97 def trim_box @trim_box end |
Class Method Details
.parse(text) ⇒ Array<MuPDF::Page>
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/mupdf/page.rb', line 16 def self.parse(text) text.scan(REGEX).map do |number, content| new( media_box: parse_media_box(content), crop_box: parse_crop_box(content), art_box: parse_art_box(content), bleed_box: parse_bleed_box(content), trim_box: parse_trim_box(content), number: Integer(number) ) end end |
.parse_art_box(text) ⇒ MuPDF::Box?
52 53 54 55 56 57 |
# File 'lib/mupdf/page.rb', line 52 def self.parse_art_box(text) match = ART_BOX_REGEX.match(text) return unless match MuPDF::Box.parse(match[:content], kind: :art) end |
.parse_bleed_box(text) ⇒ MuPDF::Box?
62 63 64 65 66 67 |
# File 'lib/mupdf/page.rb', line 62 def self.parse_bleed_box(text) match = BLEED_BOX_REGEX.match(text) return unless match MuPDF::Box.parse(match[:content], kind: :bleed) end |
.parse_crop_box(text) ⇒ MuPDF::Box?
42 43 44 45 46 47 |
# File 'lib/mupdf/page.rb', line 42 def self.parse_crop_box(text) match = CROP_BOX_REGEX.match(text) return unless match MuPDF::Box.parse(match[:content], kind: :crop) end |
.parse_media_box(text) ⇒ MuPDF::Box?
32 33 34 35 36 37 |
# File 'lib/mupdf/page.rb', line 32 def self.parse_media_box(text) match = MEDIA_BOX_REGEX.match(text) return unless match MuPDF::Box.parse(match[:content], kind: :media) end |
.parse_trim_box(text) ⇒ MuPDF::Box?
72 73 74 75 76 77 |
# File 'lib/mupdf/page.rb', line 72 def self.parse_trim_box(text) match = TRIM_BOX_REGEX.match(text) return unless match MuPDF::Box.parse(match[:content], kind: :trim) end |
Instance Method Details
#height ⇒ BigDecimal?
129 130 131 |
# File 'lib/mupdf/page.rb', line 129 def height @media_box&.height end |
#inspect ⇒ String
119 120 121 |
# File 'lib/mupdf/page.rb', line 119 def inspect "#<#{self.class.name} number=#{@number} width=#{width} height=#{height}>" end |
#width ⇒ BigDecimal?
124 125 126 |
# File 'lib/mupdf/page.rb', line 124 def width @media_box&.width end |