 | OO-Snippets: Export JPEGCommons| Keywords | filter, export, graphics, chart, JPEG, GraphicExportFilter |
|---|
| Language | OOBasic |
|---|
| Application | Office |
|---|
| Authors | Olivier Samyn (initial)
Sven Jacobi Michael Hoennig Tom Schindl
|
|---|
| Supported Versions | |
|---|
| Supported OS | |
|---|
| Question |
How can I export a chart to a JPEG file with approproate dimensions?
I'm developping a little application, trying to generate jpeg files from OpenOffice.org charts (I will maybe use it some day to generate stats reports displayed on a webpage...).
To do this, nothing more simple to connect to a OOo instance, open the calc document, select the chart and use a GraphicExportFilter to save the shape to a jpeg image. It works well.
But the remaining problem is to set the size of the exported image. All dimensions in OOO are expressed in mm. The JPEG export filter seems to convert those dimensions to the pixel unit using a "black box" formula.
I noticed that using a factor around 37.88 tends to give me a way to convert from the pixel to mm units. But it seems it's not exactly this factor and in some case there is a limit size (2048x2048 ?).
So my question is: what's this formula ? Is there some paper explaining this or some source file I can check out to know more about this ?
|
|---|
| Answer |
There exist a possibility to set the resolution, I am sorry it doesn't made it into the developers guide.
The feature is available up from OOo 1.1.
Each graphic filter is supporting a property sequence which is called "FilterData" therein you can set the size in pixel with the properties "PixelWidth" and "PixelHeight", the logical size (in 1/100mm) can be set with "LogicalWidth" and "LogicalHeight". The following basic macro is demonstrating this:
And here an example of how to use this macro: |
|---|
Sub Export( xObject, sFileUrl As String, aFilterData )
xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
xExporter.SetSourceDocument( xObject )
Dim aArgs (2) as new com.sun.star.beans.PropertyValue
Dim aURL as new com.sun.star.util.URL
aURL.complete = sFileUrl
aArgs(0).Name = "MediaType"
aArgs(0).Value = "image/jpeg"
aArgs(1).Name = "URL"
aArgs(1).Value = aURL
aArgs(2).Name = "FilterData"
aArgs(2).Value = aFilterData
xExporter.filter( aArgs() )
End Sub
Sub ExportCurrentPageOrSelection
Dim aFilterData (4) as new com.sun.star.beans.PropertyValue
aFilterData(0).Name = "PixelWidth"
aFilterData(0).Value = 1000
aFilterData(1).Name = "PixelHeight"
aFilterData(1).Value = 1000
aFilterData(2).Name ="LogicalWidth"
aFilterData(2).Value = 1000
aFilterData(3).Name ="LogicalHeight"
aFilterData(3).Value = 1000
aFilterData(4).Name ="Quality"
aFilterData(4).Value = 60
Dim sFileUrl As String
sFileUrl = "file:///d:/test2.jpg"
xDoc = thiscomponent
xView = xDoc.currentController
xSelection = xView.selection
If isEmpty( xSelection ) then
xObj = xView.currentPage
else
xObj = xSelection
End If
Export( xObj, sFileUrl, aFilterData() )
End Sub
|
Changelog| Date | User | Modification |
|---|
| 2004-06-22 | tomsontom | Modified to match new snippet-DTD | | 0000-00-00 | oli | Initial version |
|