Posts Tagged ‘PHP scripts’

Converting Word to FlashPaper files (doc>swf)

Why FlashPaper and not PDF? …well, as someone said it “sometimes we just need a simple way to display/share documents on the web … without waiting for a separate reader”. You may want to check this page, which provides an overview of some of the FlashPaper benefits.

Anyway, last year (April 2008) we added a set of transcript files (.swf) in a manuscript collection. To do that, we had to install the Macromedia plug-in, and it worked fine for single files; however, we needed to convert more than 200 files. Of course we could have done it one-by-one …but NO -too many clicks. Instead, we used a combination of MS-DOS and PHP code to batch convert *.doc to *.swf files.

Here is how:
1. created a DOS batch file (convert.bat) and added one line of code:

    for %%a in (*.doc) do call
    C:\PROGRA~1\MACROM~1\FLASHP~1\FlashPrinter.exe
    %%a -o %%a.swf %%a

This .bat file reads all the *.doc files in a directory, for every *.doc file, it calls the FlashPrinter.exe file and creates the new *.swf file

file01.doc > file.01.doc.swf

In other words, it worked but it kept three unnecessary characters “doc” in the new filename.

2. To fix this, …had to re-use an existing PHP script for renaming filenames and done!

<?
$dir = "/source_folder/";
if ($dir_list = opendir($dir)) {
    while (($filename = readdir($dir_list)) !== false) {
        if ($filename=="." || $filename=="..")
        continue;
        $new = ereg_replace('.doc.', '.', $filename);
        $old_file = $dir . $filename;
        $new_file = $dir . $new;
        rename("$old_file", "$new_file");
        }
    }
echo "done!\n";
?>

Why MS-DOS for the doc>swf conversion?, because I couldn’t get the exec() or passthru() PHP functions to work :(

Why PHP for renaming the files?, because I had a script already in place.

Why this entry now? because I recently learned that we’ll be using the same format for the transcripts of an Oral History Project.

In case you’re interested in some more MS-DOS tricks, here is a useful page.

No Comments »

Re-Indexing CONTENTdm fields

…for the upcoming MidWest CONTENTdm Users Group meeting at Purdue University, I’ll be presenting a basic web application for re-indexing metadata fields and creating new browse and search features.  You’re welcome to try any of the tools by accessing this page.  This is a good example of how a PHP script can transfrom a regular CONTENTdm custom XML file and create:

a)  a tagcloud or a navigation list for browsing
b)  an autosuggest for searching

…to view an actual digital collection with these features, visit the Miami Student Newspaper Collection.

No Comments »