Oh god: I had to use VBA
I'm working on putting together the Camp KDE 2009 videos using the excellent Kdenlive, a non-linear video editor whose name is, well, an acronym for KDE Non LInear Video Editor. More on Kdenlive in a later blog post from me and/or Wade, but trust me -- with the latest versions it's much more stable, and it's getting very good.
Anyways, one of the reasons I'm using it is to splice the slides into the videos, because they're just not readable inside the videos for the most part. So I needed a way to turn each slide into some sort of an image.
It turns out that OO.o doesn't have this capability natively, but some users on the OO.o Forum came up with a script at the bottom of this page to export each slide into PDF. I modified it to do the following:
- Export to JPG instead of PDF (PNG export didn't work)
- Add extra 0s to numbers such that you always have three digits
The code is pasted below. One really fun (not) thing I found out: VBA (or just OO.o's implementation of it) doesn't really do type checking. As a result, if r is a string instead of an integer (which I had forgotten), the following code will always execute as True:
If r < 10 Then
Anyways, here is the code, in case it helps anyone at some point:
REM ***** BASIC *****
Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
oPropertyValue = createUnoStruct( "com.sun.star.beans.PropertyValue" )
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function
Sub SplitPDFs
dim oDoc as object
oDoc = ThisComponent
dim url as string
url = oDoc.getURL()
baseURL = Left( url, Len( url ) - 4 )
nNumPages = oDoc.getDrawPages().getCount()
For nPageToSave = 1 To nNumPages
dim r as string
r = Str(nPageToSave)+"-"+Str(nPageToSave)
If CInt(r) < 10 Then
oDoc.storeToUrl( baseURL+"00"+nPageToSave+".jpg" ), Array( _
MakePropertyValue( "FilterName", "impress_jpg_Export" ), _
MakePropertyValue( "Overwrite", "True"), _
MakePropertyValue( "FilterData", Array( _
MakePropertyValue( "PageRange", r ))))
Else
oDoc.storeToUrl( baseURL+"0"+nPageToSave+".jpg" ), Array( _
MakePropertyValue( "FilterName", "impress_jpg_Export" ), _
MakePropertyValue( "Overwrite", "True"), _
MakePropertyValue( "FilterData", Array( _
MakePropertyValue( "PageRange", r ))))
End If
Next
End Sub
January 21st, 2009 - 03:36
Hi, as far as I can remember you can export your OpenOffice slides as Flash SWF, then use any converter to get it into a nice usable file format, then just use kdelive to splice the stuff together.
January 21st, 2009 - 03:56
You might want to have a look at this page:
http://wiki.freebsd.org/VideoProductionAndPublishing
where they explain how they extract jpg from pdf with ImageMagick.
January 21st, 2009 - 11:54
This seems like an even more complicated solution than what I’m doing.
January 21st, 2009 - 11:55
What does that have to do with anything? The slides are odp, not pdf.
January 21st, 2009 - 12:53
Thanks for working on the videos! I’m really looking forward to watching them.
January 22nd, 2009 - 19:27
You can save as PDF in OO (for that matter, why is a script to export to PDF needed at all? It’s right there in the file menu!)
January 22nd, 2009 - 19:41
The script exports *each slide* as its own PDF (in my modified version, its own JPG).
January 23rd, 2009 - 16:15
I still don’t get it. You can save presentations as a PDF, you don’t need to use a script.
Granted with this script its easier since you don’t have to run an ImageMagick command.
January 25th, 2009 - 10:14
Bingo.
They have to be separated out either way. I chose to use this script since it was readily available. I just didn’t know it would require the (small amount of) headache it required, mainly as a result of non-type-checking.
January 26th, 2009 - 23:26
I hate VBA.
Python rocks!