2010-07-25 45 views
4

我使用Ruby來顯示網頁中的PowerPoint文件的內容。我已經找到使用win32ole的解決方案,但是我在linux環境中,它不起作用。我認爲該應用程序可能會觸發一個openoffice命令進行轉換。如何將ppt轉換爲Ruby中的圖像?

回答

4

您可以使用RjbJODConverter將您的powerpoint導出到閃存(或any other format)。

這裏是一個代碼PICE做到這一點:

require 'rubygems' 
require 'rjb' 

classpath = nil 

Rjb::load(classpath, ['-Djava.awt.headless=true']) 

jFile = Rjb::import('java.io.File') 
jSocketOpenOfficeConnection = Rjb::import('com.artofsolving.jodconverter.openoffice.connection.SocketOpenOfficeConnection') 
jOpenOfficeDocumentConverter = Rjb::import('com.artofsolving.jodconverter.openoffice.converter.OpenOfficeDocumentConverter') 

input = jFile.new("your-doc.ppt") 
output = jFile.new("your-doc.swf") 

# connect to an OpenOffice.org instance running on port 8100 
connection = jSocketOpenOfficeConnection.new(8100) 
connection.connect() 

# convert 
converter = jOpenOfficeDocumentConverter.new(connection) 
converter.convert(input, output) 

# close the connection 
connection.disconnect() 

您需要啓動一個OOo.org服務器:

soffice -headless -accept="socket,host=127.0.0.1,port=8100;urp;" -nofirststartwizard 

並以jodconverter-cli-X.X.X.jar添加到您的CLASSPATH

7

我建議使用Docsplit

安裝寶石,然後你可以這樣做:

Docsplit.extract_images(filename, :size => '920x', :format => [:png])