Am 17.02.2011 10:18, schrieb cdfleischmann:
Hello all, I have attempted to replicate the BASIC Macro I found called http://openoffice.2283327.n4.nabble.com/file/n3310397/ExportAllGraphics300dpi.odt ExportAllGraphics300dpi.odt which successfullyexports graphics out of the writer document successfully creating images with a DPI set to 300. I tried to replicate the same but in Java, retrieving the image from OpenOffice Draw, produces the following code: // Get the shape size. Size aSizeInMM_100TH = xShape.getSize(); long WidthInMM = aSizeInMM_100TH.Width / 100; long HeightInMM = aSizeInMM_100TH.Height / 100; double DPMm = 300 / 25.6; long WidthPix = Math.round(WidthInMM * DPMm); long HeightPix = Math.round(HeightInMM * DPMm); if (xExporter != null) { PropertyValue filter[] = new PropertyValue[7]; filter[0] = new PropertyValue(); filter[0].Name ="Color"; filter[0].Value = 7; // 0: Original; 1: 1-Bit threshold value; 2: 1-Bit dithering; 3: 4-Bit Greyscale; 4: 4-Bit Color Palette; 5: 8-Bit Greyscale; 6: 8-Bit Color Palette; 7: True Color filter[1] = new PropertyValue(); filter[1].Name ="ExportMode"; filter[1].Value = 2; // 0: Original; 1: DPI; 2: Size filter[2] = new PropertyValue(); filter[2].Name ="Resolution"; filter[2].Value = 300; // in DPI, only used for ExportMode DPI. For the actual export dimensions, PixelWidth and PixelHeight are used, Resolution is only written into the file header filter[3] = new PropertyValue(); filter[3].Name = "PixelWidth"; filter[3].Value = WidthPix; filter[4] = new PropertyValue(); filter[4].Name = "PixelHeight"; filter[4].Value = HeightPix; filter[5] = new PropertyValue(); filter[5].Name = "LogicalWidth"; filter[5].Value = WidthInMM * 100; // LogicalWidth: integer, only usable with ExportMode Size, only influences the DPI header. filter[6] = new PropertyValue(); filter[6].Name = "LogicalHeight"; filter[6].Value = HeightInMM * 100; // LogicalHeight: integer, only usable with ExportMode Size, only influences the DPI header. System.out.println("filter is: " + Arrays.toString(filter)); PropertyValue aProps[] = new PropertyValue[3]; aProps[0] = new PropertyValue(); aProps[0].Name = "MediaType"; aProps[0].Value = "image/png"; aProps[1] = new PropertyValue(); aProps[1].Name = "URL"; // Write the image as a jpg out to a temporary file. String realPath = getServletContext().getRealPath("file.png"); StringBuilder destUrl = new StringBuilder("file:///"); destUrl.append(realPath.replace('\\', '/')); aProps[1].Value = destUrl.toString(); aProps[2] = new PropertyValue(); aProps[2].Name = "FilterData"; aProps[2].Value = filter; System.out.println("aProps is: " + Arrays.toString(filter)); System.out.println("TRYING TO GET XCOMPONENT"); XComponent xComp = (XComponent) UnoRuntime.queryInterface(XComponent.class, xShape); System.out.println("GOT XCOMPONENT"); System.out.println("TRYING TO SET setSourceDocument"); xExporter.setSourceDocument(xComp); System.out.println("SET setSourceDocument"); System.out.println("TRYING TO GET XFilter"); XFilter xFilter = (XFilter) UnoRuntime.queryInterface(XFilter.class, xExporter); System.out.println("GOT XFilter"); System.out.println("FILTERING"); System.out.println(xFilter.filter(aProps)); System.out.println("FILTERED"); I am however exporting graphics from OpenOffice Draw, not writer, could that be the problem? Is there some setting I am missing to set the DPI when exporting graphics from openoffice draw... Any hints/tips or tricks greatly appreciated. This problems seems to be the same with OpenOffice 3.1 as it is for 3.3. I have tried openoffice running on my old OpenSolaris install which seems to export at 96 DPI regardless of the DPI or SIZE setting, and on my openoffice 3.3 install with OS X, I get 110 DPI with the same code?
I think the problem is that a java long is 64 bit, try replace it with an int that should work. Regards, Christian --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
