Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create a powerpoint presentation with Rails

I'm in a situation in which I have to build a PowerPoint presentation programatically and serve the resulting ppt file through a web application, preferably using Rails, JavaScript or Ruby. Is this possible? If so, how and with which tools?

I'm open to any and all suggestions on how to best tackle this problem. Thanks!

like image 851
MalSu Avatar asked Nov 15 '12 21:11

MalSu


2 Answers

This ruby gem seems more mature than the one mentioned in the current accepted answer.

https://github.com/pythonicrubyist/powerpoint http://rubygems.org/gems/powerpoint

require 'powerpoint'

@deck = Powerpoint::Presentation.new

# Creating an introduction slide:
title = 'Bicycle Of the Mind'
subtitle = 'created by Steve Jobs'
@deck.add_intro title, subtitle

# Creating a text-only slide:
# Title must be a string.
# Content must be an array of strings that will be displayed as bullet items.
title = 'Why Mac?'
content = ['Its cool!', 'Its light.']
@deck.add_textual_slide title, content

# Creating an image Slide:
# It will contain a title as string.
# and an embeded image
title = 'Everyone loves Macs:'
image_path = 'samples/images/sample_gif.gif'
@deck.add_pictorial_slide title, image_path

# Specifying coordinates and image size for an embeded image.
# x and y values define the position of the image on the slide.
# cx and cy define the width and height of the image.
# x, y, cx, cy are in points. Each pixel is 12700 points.
# coordinates parameter is optional.
coords = {x: 124200, y: 3356451, cx: 2895600, cy: 1013460}
@deck.add_pictorial_slide title, image_path, coords

# Saving the pptx file to the current directory.
@deck.save('test.pptx')
like image 74
Greg Dean Avatar answered Nov 08 '22 12:11

Greg Dean


http://tomasvarsavsky.com/2009/04/04/simple-word-document-templating-using-ruby-and-xml/

If you can create the template and populate the values, consider this approach.

Office Open XML file formats

The new Office file formats (.docx, .xlsx, .pptx files) are basically a zipped collection of XML files. We focused on Word files (.docx) but this approach would work with any of the other types of files as well. The specification for the format weighs in at several thousand pages. Producing a file from scratch without a purpose built library that handles all the intricacies of the format would be quite a task. Instead, we drafted the templates in Word and placed markers to tell our templating engine where to insert values. We created document properties which reference data values and added these as fields into the document in the place where the values should be inserted. For example, we could have fields like:

label_tag #{data[:user].name}
label_tag #{data[:user].address}
label_tag #{data[:booking].number}
label_tag #{data[:booking].items.collect{|i| i.name}.join(‘,’)}

Otherwise, there was an attempt (WIP uploaded three years ago, I do not expect it to be completed, but should be benfecial in creating an approach to create slides) on creating PowerPoint slides. Here is a sample of the code

https://github.com/jpoz/rubypoint/blob/master/lib/rubypoint/presentation.rb

def new_slide
  RubyPoint::Slide.new(self)
end
like image 31
Sully Avatar answered Nov 08 '22 13:11

Sully