I am looking for a macro, capable of exporting the currently selected object or group to a fixed-dpi dpi bitmap with transparent background (e.g. with "image/png" media type, 300 DPI)" to a fixed file name, or directly to a clipboard, so that I can paste the image directly into external program.
Having read several old threads, I was able to write such macro using GraphicsExportFilter service.
Following code defines the Property-Value variable containing settings for graphics export filter for some MediaType:
Code: Select all
' ... variable declaration and size calculations are omitted ...
Dim aFilterData(7) As New com.sun.star.beans.PropertyValue
aFilterData(0).Name = "PixelWidth"
aFilterData(0).Value = pixelWidth
aFilterData(1).Name = "PixelHeight"
aFilterData(1).Value = pixelHeight
aFilterData(2).Name = "LogicalWidth"
aFilterData(2).Value = logicalWidth
aFilterData(3).Name = "LogicalHeight"
aFilterData(3).Value = logicalHeight
aFilterData(4).Name = "Quality"
aFilterData(4).Value = 100
aFilterData(5).Name = "ColorMode"
aFilterData(5).Value = 1
aFilterData(6).Name = "ExportMode"
aFilterData(6).Value = 1
aFilterData(7).Name = "Resolution"
aFilterData(7).Value = 300
Following code defines another Property-Value variable with media type and filter settings (above):
Code: Select all
Dim aURL As New com.sun.star.util.URL
aURL.Complete = ConvertToURL( fileName )
Dim aArgs(2) As New com.sun.star.beans.PropertyValue
aArgs(0).Name = "MediaType"
aArgs(0).Value = "image/png"
aArgs(1).Name = "URL"
aArgs(1).Value = aURL
aArgs(2).Name = "FilterData"
aArgs(2).Value = aFilterData ' ... defined above
Code: Select all
oDoc = ThisComponent
oView = oDoc.CurrentController
oObj = oView.Selection
oExporter = createUnoService("com.sun.star.drawing.GraphicExportFilter")
oExporter.SetSourceDocument( oObj )
oExporter.Filter( aArgs )
1) Some documentation on FilterData properties/values accepted by .Filter() method of GraphicExportFilter service. (Context: what do these properties/values mean, and which one turns on the transparency of produced PNGs?)
2) Some documentation or perhaps a code snippet, capable of exporting the same PNG image not to a file, but to a clipboard?
Any idea?
Thanks in advance,
Sergey
PS: I'm aware of File/Export... dialog. I'm looking for a way to reduce the export procedure to a single keyboard shortcut.