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
- #pagenum ⇒ 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 ⇒ Integer
-
#initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) ⇒ Page
constructor
A new instance of Page.
- #inspect ⇒ String
- #width ⇒ Integer
Constructor Details
#initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) ⇒ Page
Returns a new instance of Page.
99 100 101 102 103 104 105 106 |
# File 'lib/mupdf/page.rb', line 99 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
79 80 81 |
# File 'lib/mupdf/page.rb', line 79 def art_box @art_box end |
#bleed_box ⇒ MuPDFBox
83 84 85 |
# File 'lib/mupdf/page.rb', line 83 def bleed_box @bleed_box end |
#crop_box ⇒ MuPDFBox
75 76 77 |
# File 'lib/mupdf/page.rb', line 75 def crop_box @crop_box end |
#media_box ⇒ MuPDFBox
71 72 73 |
# File 'lib/mupdf/page.rb', line 71 def media_box @media_box end |
#pagenum ⇒ Integer
91 92 93 |
# File 'lib/mupdf/page.rb', line 91 def pagenum @pagenum end |
#trim_box ⇒ MuPDFBox
87 88 89 |
# File 'lib/mupdf/page.rb', line 87 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
48 49 50 51 |
# File 'lib/mupdf/page.rb', line 48 def self.parse_art_box(text) match = ART_BOX_REGEX.match(text) MuPDF::Box.parse(match[:content], kind: :art) end |
.parse_bleed_box(text) ⇒ MuPDF::Box
56 57 58 59 |
# File 'lib/mupdf/page.rb', line 56 def self.parse_bleed_box(text) match = BLEED_BOX_REGEX.match(text) MuPDF::Box.parse(match[:content], kind: :bleed) end |
.parse_crop_box(text) ⇒ MuPDF::Box
40 41 42 43 |
# File 'lib/mupdf/page.rb', line 40 def self.parse_crop_box(text) match = CROP_BOX_REGEX.match(text) MuPDF::Box.parse(match[:content], kind: :crop) end |
.parse_media_box(text) ⇒ MuPDF::Box
32 33 34 35 |
# File 'lib/mupdf/page.rb', line 32 def self.parse_media_box(text) match = MEDIA_BOX_REGEX.match(text) MuPDF::Box.parse(match[:content], kind: :media) end |
.parse_trim_box(text) ⇒ MuPDF::Box
64 65 66 67 |
# File 'lib/mupdf/page.rb', line 64 def self.parse_trim_box(text) match = TRIM_BOX_REGEX.match(text) MuPDF::Box.parse(match[:content], kind: :trim) end |
Instance Method Details
#height ⇒ Integer
119 120 121 |
# File 'lib/mupdf/page.rb', line 119 def height @media_box.height end |
#inspect ⇒ String
109 110 111 |
# File 'lib/mupdf/page.rb', line 109 def inspect "#<#{self.class.name} number=#{@number}>" end |
#width ⇒ Integer
114 115 116 |
# File 'lib/mupdf/page.rb', line 114 def width @media_box.width end |