Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM ***** BASIC *****
- option explicit
- sub Main
- Dim file_path as String
- SetDirectory()
- end sub
- Sub GetFileName(oFileDialog as variant)
- Dim iAccept as integer
- Dim sFile as string
- Dim sDirectory as string
- iAccept = oFileDialog.Execute()
- If iAccept = 1 Then
- sFile = oFileDialog.Files(0)
- msgbox ("selected file: " & sFile)
- End If
- ExportPNG(sfile)
- End Sub
- Sub SetDirectory
- Dim ListAny(0) as Long
- ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION
- dim oFilePickerDlg as variant
- oFilePickerDlg = createUnoService("com.sun.star.ui.dialogs.FilePicker")
- oFilePickerDlg.Initialize(ListAny())
- oFilePickerDlg.appendFilter("Portable Network Graphic (.png)", "*.png" )
- oFilePickerDlg.SetTitle("Export as...")
- Rem Adapt path to your needs
- dim sDirectory as string
- sDirectory = ConvertToURL(Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/"))
- print(sDirectory)
- if oFilePickerDlg.ImplementationName="com.sun.star.comp.fpicker.VistaFileDialog" then
- dim oConfigProvider as variant
- oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
- dim aNodePath(0) as new com.sun.star.beans.PropertyValue
- aNodePath(0).Name = "nodepath"
- aNodePath(0).Value = "/org.openoffice.Office.Common/Path/Info"
- dim oRegistryKeyContent as variant
- oRegistryKeyContent = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath())
- oRegistryKeyContent.WorkPathChanged = true
- oRegistryKeyContent.commitChanges
- end if
- oFilePickerDlg.setDisplayDirectory(sDirectory)
- GetFileName(oFilePickerDlg)
- oFilePickerDlg.Dispose()
- End Sub
- Sub ExportPNG(path as string)
- print(path)
- dim document as object
- dim dispatcher as object
- rem ----------------------------------------------------------------------
- rem get access to the document
- document = ThisComponent.CurrentController.Frame
- dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
- 'if
- 'end if
- dim selectionArg(1) as new com.sun.star.beans.PropertyValue
- selectionArg(0).Name = "Selection"
- selectionArg(0).Value = ThisComponent.CurrentController.getSelection()
- dim args1(4) as new com.sun.star.beans.PropertyValue
- args1(0).Name = "URL"
- args1(0).Value = path
- args1(1).Name = "FilterName"
- args1(1).Value = "impress_png_Export"
- args1(2).Name = "filterNames"
- args1(2).Value = Array("*.png")
- args1(3).Name = "FilterData"
- args1(3).Value = SelectionArg()
- dispatcher.executeDispatch(document, ".uno:ExportTo", "", 0, args1())
- end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement