Advertisement
Guest User

Export Aa PNG

a guest
Oct 22nd, 2014
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Global prevName As String
  2.  
  3. Sub ExportToPNG()' oDoc, cFilename )
  4.  
  5.  
  6. BasicLibraries.loadLibrary("Tools")
  7.  
  8. oDoc = ThisComponent
  9.  
  10. cExportUrl = oDoc.getURL()
  11. oDocCtrl = oDoc.getCurrentController()
  12. oDrawPage = oDocCtrl.getCurrentPage()
  13.  
  14. If Len(prevName) = 0 Then
  15.     prevName = oDrawPage.getName()
  16. End If
  17.  
  18.  
  19. inputtedName = InputBox("Export PNG to:", "File name", prevName)' oDrawPage.getName())
  20. prevName = inputtedName
  21. cExportUrl = Tools.Strings.DirectoryNameoutofPath(ThisComponent.getURL(),"/") + "/" + inputtedName
  22. 'cExportUrl = Left( cExportUrl, Len(cExportUrl)-4 ) + "_" + oDrawPage.getName()
  23.  
  24. Dim sFileUrl As String
  25.  
  26. sFileUrl = "file://"+inputtedName 'ConvertToURL( cExportUrl + ".png" )
  27. oDrawPage = oDoc.getDrawPages().getByIndex(0)
  28.  
  29. 'creating filter data
  30. Dim aFilterData (7) as new com.sun.star.beans.PropertyValue
  31. 'properties valid for all filters
  32. aFilterData(0).Name  = "PixelWidth"        '
  33. aFilterData(0).Value = 2480'oDrawPage.Width*(72/2540)   'convert => mm => inches => pixels (72 points per inch)
  34. aFilterData(1).Name  = "PixelHeight"
  35. aFilterData(1).Value = 3509 'oDrawPage.Height*(72/2540)   'convert => mm => inches => pixels (72 points per inch)
  36.  
  37. 'filter data for the image/jpeg MediaType
  38. 'aFilterData(2).Name  ="Quality"
  39. 'aFilterData(2).Value = 90
  40. 'aFilterData(3).Name  ="ColorMode"
  41. 'aFilterData(3).Value = 0
  42.  
  43. 'filter data for the image/png MediaType
  44. aFilterData(2).Name  ="Compression"
  45. aFilterData(2).Value = 9
  46. aFilterData(3).Name  ="Interlaced"
  47. aFilterData(3).Value = 0
  48.  
  49. 'filter data for the image/gif MediaType
  50. 'aFilterData(2).Name  ="Translucent"
  51. 'aFilterData(2).Value = true
  52. 'aFilterData(3).Name  ="Interlaced"
  53. 'aFilterData(3).Value = 0
  54.  
  55. 'filter data for the image/bmp MediaType
  56. 'aFilterData(2).Name  ="Color"
  57. 'aFilterData(2).Value = 7
  58. 'aFilterData(3).Name  ="ExportMode"
  59. 'aFilterData(3).Value = 0
  60. 'aFilterData(4).Name  ="Resolution"
  61. 'aFilterData(4).Value = 300
  62. 'aFilterData(5).Name  ="RLE_Coding"
  63. 'aFilterData(5).Value = true
  64. 'aFilterData(6).Name  ="LogicalWidth"
  65. 'aFilterData(6).Value = 2000
  66. 'aFilterData(7).Name  ="LogicalHeight"
  67. 'aFilterData(7).Value = 2000
  68.  
  69. Dim aArgs (2) as new com.sun.star.beans.PropertyValue
  70.  
  71. aArgs(0).Name  = "MediaType"
  72. aArgs(0).Value = "image/png"
  73. aArgs(1).Name  = "URL"
  74. aArgs(1).Value = sFileUrl
  75. aArgs(2).Name  = "FilterData"
  76. aArgs(2).Value = aFilterData()
  77.  
  78. xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
  79. xExporter.setSourceDocument( oDrawPage )
  80.  
  81. xExporter.filter( aArgs() )
  82.  
  83. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement