Categories
Cool Webapps howto Interesting Links PHP Tricks

Using iPaper API to convert office documents to flash movie on the fly :)

Embedding documents in web applications is a challenging work. Because you need to convert these documents into flash movie and only then you can embed them in your web applications. There are many converters available out their for use. Some of them are proprietary, Some of them comes for free. There are command line tools as well as web services also to perform these conversions and make your life easier. In this post I am going to introduce you to IPaper, an excellent service from Scribd. Using IPaper API you can upload and convert your documents to flash movie on the fly, and then you can embed them using Scribd’s excellent document viewer. Scribd offers a collection of client libraries and fortunately, we have a PHP lib in that collection.

Scribd API can convert numbers of document types including the followings

* Adobe PDF (.pdf)
* Adobe PostScript (.ps)
* Microsoft Word (.doc, .docx)
* Microsoft PowerPoint (.ppt, .pps, .pptx)
* Microsoft Excel (.xls, xlsx)
* OpenOffice Text Document (.odt, .sxw)
* OpenOffice Presentation Document (.odp, .sxi)
* OpenOffice Spreadsheet (.ods, .sxc)
* All OpenDocument formats
* Plain text (.txt)
* Rich text format (.rtf)

To use IPaper API, you need to create a developer account in ScribD and get your API key and secret key. Also, download the PHP client library from http://www.scribd.com/developers/libraries

You are ready to go once you get your Scribd api key and secret key. You can upload different types of files to scribd server and of course you can make them private or publicly accessible. After successful upload and conversion you will receive a doc_id and access_key from Scribd web service. Using those data you can embed your document in your web app. Lets have a look. In the following code examples, you may find the getEmbedUrl() and getEmbedCode() functions handy. You can also use SWFObject for quick embedding 🙂

[sourcecode lang=”php”]
<?php
include_once("scribd.php");

$UpdloadData = createIPaper("gpl.pdf","pdf","public");
$EmbedUrl = getEmbedUrl($UpdloadData);
echo $EmbedUrl;
$EmbedCode = getEmbedCode($UpdloadData);
echo $EmbedCode;

function createIPaper($File, $FileType, $Access="private")
{
$scribd_api_key = "<your API key>";
$scribd_secret = "<your Secret key>";

if (empty($FileType))
throw new Exception("Filetype cannot be empty");
$Scribd = new Scribd($scribd_api_key,$scribd_secret);

$UploadData = $Scribd->upload($File,$FileType,$Access,1);
return $UploadData;
}

function getEmbedUrl($UploadData)
{
if($UploadData){
$EmbedUrl = "http://d1.scribdassets.com/ScribdViewer.swf?document_id={$UploadData[‘doc_id’]}&access_key={$UploadData[‘access_key’]}&page=1&version=1&viewMode=list";
return $EmbedUrl;
}
}

function getEmbedCode($UploadData, $Width=450, $Height=500)
{
$EmbedCode = <<<EOD
<object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"
id="doc_512761847372423" name="doc_512761847372423"
classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
align="middle"
height="{$Height}"
width="{$Width}" >
<param name="movie" value="http://d1.scribdassets.com/ScribdViewer.swf?document_id={$UploadData[‘doc_id’]}&access_key={$UploadData[‘access_key’]}&page=1&version=1&viewMode=list">
<param name="quality" value="high">
<param name="play" value="true">
<param name="loop" value="true">
<param name="scale" value="showall">
<param name="wmode" value="opaque">
<param name="devicefont" value="false">
<param name="bgcolor" value="#ffffff">
<param name="menu" value="true">
<param name="allowFullScreen" value="true">
<param name="allowScriptAccess" value="always">
<param name="salign" value="">
<param name="mode" value="list">
<embed src="http://d1.scribdassets.com/ScribdViewer.swf?document_id={$UploadData[‘doc_id’]}&access_key={$UploadData[‘access_key’]}&page=1&version=1&viewMode=list"
quality="high"
pluginspage="http://www.macromedia.com/go/getflashplayer"
play="true"
loop="true"
scale="showall"
wmode="opaque"
devicefont="false"
bgcolor="#ffffff"
name="doc_512761847372423_object"
menu="true"
allowfullscreen="true"
allowscriptaccess="always"
salign=""
type="application/x-shockwave-flash"
align="middle"
mode="list"
height="{$Height}"
width="{$Width}">
</embed>
</object>
EOD;
return $EmbedCode;
}
?>
[/sourcecode]

and here is how it will look after embedding

View this document on Scribd

download the source code from here http://www.box.net/shared/5dav7hnkm9

By the way, IPaper PHP client library has some cool methods like uploadFromUrl() – Check them out )

Stay in touch, In next post I will show you how to use some other exciting tools which you can use and host in your own server :). that will be fun to host your own service like this 🙂

Thanks to Rana for helping me out with iPaper.

16 replies on “Using iPaper API to convert office documents to flash movie on the fly :)”

That’s a great thing.

I got a question. Do you know any plugin for self-hosted wordpress which would help me highlight codes such as the codes highlighted in this page?

using IPaper API can be handy, time saver, easier to use/integrate, on the spot delivery also it can be usable to make your site more robust look.

World have IPaper API and we have this article 😉

i m goin to integrate it in my site just doin some copy, paste 😉

Cool writings. Thnx Guru :)_)

Hi, very cool article. You wrote “I will show you how to use some other exciting tools which you can use and host in your own server 🙂 . that will be fun to host your own service like this”.

Can you provide some information about that here in comments? I’m very interested to know how to do that 🙂

Hello,

Is there any way to modify uploaded pdf (or svg) documents on the fly?

Lets say, a team-member uploads a report in pdf format. Another team-member reads this file from net and comments on it by modifying this pdf document on the fly?

Regards,
rafiq7s

how to use scribd with my website to convert already uploaded files(in my website) into flash files without navigating to other website.I am working on asp.net/C#

Nice post.
I got a little problem. I replaced file name with file path this way:
UpdloadData = createIPaper(“http://myip/gpl.pdf”,”pdf”,”public”);

It does not load the file in a viewer. Any work around?

You mentioned a couple of other tools available – Could you list those other tools?
Specifically I’m looking for free command line tools for PPT conversion

Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *