Class: MuPDF::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/mupdf/document.rb

Overview

A wrapper for a PDF document allowing for MuPDF APIs.

Instance Method Summary collapse

Constructor Details

#initialize(pathname) ⇒ Document

Returns a new instance of Document.

Parameters:

  • pathname (Pathname)


7
8
9
# File 'lib/mupdf/document.rb', line 7

def initialize(pathname)
  @pathname = pathname
end

Instance Method Details

#draw(path:, page:, format: 'png', width: nil, height: nil, resolution: nil) ⇒ Object

Parameters:

  • path (String)

    the path where the conversion is saved

  • format (String) (defaults to: 'png')

    “png”, “svg”, “txt”, etc

  • page (Integer)

    the page

  • resultion (Integer)

    optional (default: 72)

  • width (Integer) (defaults to: nil)

    optional

  • height (Integer) (defaults to: nil)

    optional

Raises:



60
61
62
63
64
65
66
67
68
# File 'lib/mupdf/document.rb', line 60

def draw(path:, page:, format: 'png', width: nil, height: nil, resolution: nil)
  args = ['draw', '-o', path, '-F', format, String(@pathname), String(page)]

  args << '-w' << width if width
  args << '-h' << height if height
  args << '-r' << resolution if resolution

  MuPDF.mutool(*args)
end

#infoMuPDF::Info

Returns:

Raises:



22
23
24
25
26
27
# File 'lib/mupdf/document.rb', line 22

def info
  @info ||= begin
    result = MuPDF.mutool('info', String(@pathname))
    MuPDF::Info.parse(result)
  end
end

#inspectString

Returns:

  • (String)


12
13
14
# File 'lib/mupdf/document.rb', line 12

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

#pagesArray<MuPDF::Page>

Returns:

Raises:



40
41
42
43
44
45
# File 'lib/mupdf/document.rb', line 40

def pages
  @pages ||= begin
    result = MuPDF.mutool('pages', String(@pathname))
    MuPDF::Page.parse(result)
  end
end