Advertisement
Guest User

Export selection as png

a guest
Mar 9th, 2016
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. REM ***** BASIC *****
  2.  
  3. option explicit
  4.  
  5. sub Main
  6.  
  7. Dim file_path as String
  8.  
  9. SetDirectory()
  10.  
  11. end sub
  12.  
  13. Sub GetFileName(oFileDialog as variant)
  14.  
  15. Dim iAccept as integer
  16. Dim sFile as string
  17. Dim sDirectory as string
  18. iAccept = oFileDialog.Execute()
  19. If iAccept = 1 Then
  20. sFile = oFileDialog.Files(0)
  21. msgbox ("selected file: " & sFile)
  22. End If
  23. ExportPNG(sfile)
  24. End Sub
  25.  
  26. Sub SetDirectory
  27. Dim ListAny(0) as Long
  28. ListAny(0) = com.sun.star.ui.dialogs.TemplateDescription.FILESAVE_AUTOEXTENSION
  29. dim oFilePickerDlg as variant
  30. oFilePickerDlg = createUnoService("com.sun.star.ui.dialogs.FilePicker")
  31. oFilePickerDlg.Initialize(ListAny())
  32. oFilePickerDlg.appendFilter("Portable Network Graphic (.png)", "*.png" )
  33. oFilePickerDlg.SetTitle("Export as...")
  34. Rem Adapt path to your needs
  35. dim sDirectory as string
  36. sDirectory = ConvertToURL(Tools.Strings.DirectoryNameoutofPath(ThisComponent.url, "/"))
  37. print(sDirectory)
  38.  
  39. if oFilePickerDlg.ImplementationName="com.sun.star.comp.fpicker.VistaFileDialog" then
  40. dim oConfigProvider as variant
  41. oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
  42. dim aNodePath(0) as new com.sun.star.beans.PropertyValue
  43. aNodePath(0).Name = "nodepath"
  44. aNodePath(0).Value = "/org.openoffice.Office.Common/Path/Info"
  45. dim oRegistryKeyContent as variant
  46. oRegistryKeyContent = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath())
  47. oRegistryKeyContent.WorkPathChanged = true
  48. oRegistryKeyContent.commitChanges
  49. end if
  50. oFilePickerDlg.setDisplayDirectory(sDirectory)
  51. GetFileName(oFilePickerDlg)
  52. oFilePickerDlg.Dispose()
  53. End Sub
  54.  
  55. Sub ExportPNG(path as string)
  56. print(path)
  57.  
  58. dim document as object
  59. dim dispatcher as object
  60. rem ----------------------------------------------------------------------
  61. rem get access to the document
  62. document = ThisComponent.CurrentController.Frame
  63. dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
  64.  
  65. 'if
  66.  
  67. 'end if
  68.  
  69. dim selectionArg(1) as new com.sun.star.beans.PropertyValue
  70. selectionArg(0).Name = "Selection"
  71. selectionArg(0).Value = ThisComponent.CurrentController.getSelection()
  72.  
  73. dim args1(4) as new com.sun.star.beans.PropertyValue
  74. args1(0).Name = "URL"
  75. args1(0).Value = path
  76. args1(1).Name = "FilterName"
  77. args1(1).Value = "impress_png_Export"
  78. args1(2).Name = "filterNames"
  79. args1(2).Value = Array("*.png")
  80. args1(3).Name = "FilterData"
  81. args1(3).Value = SelectionArg()
  82.  
  83. dispatcher.executeDispatch(document, ".uno:ExportTo", "", 0, args1())
  84. end sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement