Class: MuPDF::Page

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(media_box:, crop_box:, art_box:, bleed_box:, trim_box:, number:) ⇒ Page

Returns a new instance of Page.

Parameters:



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_boxMuPDFBox

Returns:

  • (MuPDFBox)


79
80
81
# File 'lib/mupdf/page.rb', line 79

def art_box
  @art_box
end

#bleed_boxMuPDFBox

Returns:

  • (MuPDFBox)


83
84
85
# File 'lib/mupdf/page.rb', line 83

def bleed_box
  @bleed_box
end

#crop_boxMuPDFBox

Returns:

  • (MuPDFBox)


75
76
77
# File 'lib/mupdf/page.rb', line 75

def crop_box
  @crop_box
end

#media_boxMuPDFBox

Returns:

  • (MuPDFBox)


71
72
73
# File 'lib/mupdf/page.rb', line 71

def media_box
  @media_box
end

#pagenumInteger

Returns:

  • (Integer)


91
92
93
# File 'lib/mupdf/page.rb', line 91

def pagenum
  @pagenum
end

#trim_boxMuPDFBox

Returns:

  • (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>

Parameters:

  • text (String)

Returns:



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

Parameters:

  • text (String)

Returns:



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

Parameters:

  • text (String)

Returns:



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

Parameters:

  • text (String)

Returns:



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

Parameters:

  • text (String)

Returns:



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

Parameters:

  • text (String)

Returns:



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

#heightInteger

Returns:

  • (Integer)


119
120
121
# File 'lib/mupdf/page.rb', line 119

def height
  @media_box.height
end

#inspectString

Returns:

  • (String)


109
110
111
# File 'lib/mupdf/page.rb', line 109

def inspect
  "#<#{self.class.name} number=#{@number}>"
end

#widthInteger

Returns:

  • (Integer)


114
115
116
# File 'lib/mupdf/page.rb', line 114

def width
  @media_box.width
end