class PPTX::Slide

Public Class Methods

new(package) click to toggle source
Calls superclass method PPTX::OPC::Part::new
# File lib/pptx/slide.rb, line 5
def initialize(package)
  part_name = package.next_part_with_prefix('ppt/slides/slide', '.xml')
  super(package, part_name)
  relationships.add('../slideLayouts/slideLayout7.xml', RELTYPE_SLIDE_LAYOUT)
end

Public Instance Methods

add_filled_rectangle(transform, color) click to toggle source

Add rectangle filled with given color. Give color in RGB hex format (e.g. '558ed5')

# File lib/pptx/slide.rb, line 39
def add_filled_rectangle(transform, color)
  shape = Shapes::FilledRectangle.new(transform, color)
  shape_tree_xml.add_child(shape.build_node)
end
add_picture(transform, name, image) click to toggle source
# File lib/pptx/slide.rb, line 44
def add_picture(transform, name, image)
  # TODO do something with name or remove
  rid = relationships.add(relative_part_name(image.part_name), PPTX::RELTYPE_IMAGE)

  shape = Shapes::Picture.new(transform, rid)
  shape_tree_xml.add_child(shape.build_node)
end
add_slide_number(transform, number, formatting={}) click to toggle source

Add a slide number that is recognized by Powerpoint as such and automatically updated See textbox for formatting.

# File lib/pptx/slide.rb, line 70
def add_slide_number(transform, number, formatting={})
  shape = Shapes::SlideNumber.new(transform, number, formatting)
  shape_tree_xml.add_child(shape.build_node)
end
add_textbox(transform, content, formatting={}) click to toggle source

Add a text box at the given position with the given dimensions

Pass distance values in EMUs (use PPTX::CM) Formatting values a are mostly raw OOXML Text Run Properties (rPr) element attributes. Examples:

  • sz: font size (use PPTX::POINT)

  • b: 1 for bold

  • i: 1 for italic

There are two custom properties:

  • color: aabbcc (hex RGB color)

  • align: ctr|dist|just|justLow|l|r|thaiDist (ST_TextAlignType (Text Alignment Types))

# File lib/pptx/slide.rb, line 63
def add_textbox(transform, content, formatting={})
  shape = Shapes::Textbox.new(transform, content, formatting)
  shape_tree_xml.add_child(shape.build_node)
end
base_xml() click to toggle source
# File lib/pptx/slide.rb, line 11
def base_xml
  '''<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <p:sld xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
           xmlns:p="http://schemas.openxmlformats.org/presentationml/2006/main"
           xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
        <p:cSld>
            <p:spTree>
                <p:nvGrpSpPr>
                    <p:cNvPr id="1" name=""/>
                    <p:cNvGrpSpPr/>
                    <p:nvPr/>
                </p:nvGrpSpPr>
                <p:grpSpPr/>
            </p:spTree>
        </p:cSld>
        <p:clrMapOvr>
            <a:masterClrMapping/>
        </p:clrMapOvr>
    </p:sld>
    '''
end
content_type() click to toggle source
# File lib/pptx/slide.rb, line 33
def content_type
  'application/vnd.openxmlformats-officedocument.presentationml.slide+xml'
end
shape_tree_xml() click to toggle source
# File lib/pptx/slide.rb, line 75
def shape_tree_xml
  @shape_tree_xml ||= doc.xpath('/p:sld/p:cSld/p:spTree').first
end