Sub SplitSlides( cImpressDocToSplit, cDir, startnum ) ' Open the document to find out how many pages it has. oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDocToSplit ), "_blank", 0, Array(MakePropertyValue( "Hidden", True ),) ) if NOT isNull (oDoc) Then nNumPages = oDoc.getDrawPages().getCount() ' Now that we know how many pages it has, close it. oDoc.close( True ) ' Now loop once for each page. nHighestPageNumber = nNumPages-1 ' nPageToSave = 2 For nPageToSave = 0 To nHighestPageNumber ' Open the document. oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL (cImpressDocToSplit ), "_blank", 0, Array(MakePropertyValue( "Hidden", True ),) ) ' Delete all pages except the one we're interested in keeping ' on this loop. DeleteAllPagesExcept( oDoc, nPageToSave ) ' Prepare to save the document in png form. ' First get the new filename to save it under. cNewName = CSTR( "//" + cDir + "/" + Format(nPageToSave + startnum,"00000000") + ".png") ' Save it as a PNG. oDoc.storeToURL( cNewName, _ Array( MakePropertyValue( "FilterName", "impress_png_Export" ) ) ) ' Close the document without saving it. oDoc.close( True ) Next Endif End Sub ' Delete all pages of an Impress or Draw document, ' EXCEPT for a certian page that we want to keep. Function DeleteAllPagesExcept( oDoc, nPageToKeep ) nNumPages = oDoc.getDrawPages().getCount() nHighestPageNumber = nNumPages-1 ' Delete the last page, then the page before that, ' then the page before that, until we get to the ' page to keep. ' This deletes all pages AFTER the page to keep. nPageToDelete = nHighestPageNumber Do while nPageToDelete > nPageToKeep ' Get the page. oPage = oDoc.getDrawPages().getByIndex( nPageToDelete ) ' Tell the document to remove it. oDoc.getDrawPages().remove( oPage ) nPageToDelete = nPageToDelete - 1 Loop ' Delete all the pages before the page to keep. For i = 0 To nPageToKeep - 1 ' Delete the first page. nPageToDelete = 0 ' Get the page. oPage = oDoc.getDrawPages().getByIndex( nPageToDelete ) ' Tell the document to remove it. oDoc.getDrawPages().remove( oPage ) Next End Function 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