*/ storeProperties)上面的方法主要三个内容:
Java代码
1. document = loadDocument(inputUrl, loadProperties); 2. refreshDocument(document);
3. storeDocument(document, outputUrl, storeProperties);
loadDocument是加载office文档的,通过loadProperties传递的参数。支持的参数都定义在jar包里面的document-formats.xml里面了,没有 纸张设置的参数。
我们要做的只能增加几个参数。这个参数的具体内容需要查阅openoffice的文档。
因为loadDocument方法是private的,我们只能想别的办法,好在 refreshDocument不是private
我们可以新建一个class继承OpenOfficeDocumentConverter 并override refreshDocument方法。
Java代码
1. public final static Size A5, A4, A3; 2. public final static Size B4, B5, B6; 3. public final static Size KaoqinReport; 4. 5. static {
6. A5 = new Size(14800, 21000);
7. A4 = new Size(21000, 29700); 8. A3 = new Size(29700, 42000); 9.
10. B4 = new Size(25000, 35300); 11. B5 = new Size(17600, 25000); 12. B6 = new Size(12500, 17600); 13.
14. KaoqinReport = new Size(25400, 27940); 15. } 16. 17. /*
18. * XComponent:xCalcComponent 19. *
20. * @seecom.artofsolving.jodconverter.openoffice.converter.
21. * AbstractOpenOfficeDocumentConverter
22. * #refreshDocument(com.sun.star.lang.XComponent) 23. */
24. @Override
25. protected void refreshDocument(XComponent document) {
26. super.refreshDocument(document); 27.
28. // The default paper format and orientation is A4 and portrait. To
29. // change paper orientation 30. // re set page size
31. XPrintable xPrintable = (XPrintable) UnoRuntime.queryInterface(XPrintable.class, document);
32. PropertyValue[] printerDesc = new PropertyValue[2];
33.
34. // Paper Orientation
35. // printerDesc[0] = new PropertyValue(); 36. // printerDesc[0].Name = \"PaperOrientation\"; 37. // printerDesc[0].Value = PaperOrientation.PORTRAIT;
38.
39. // Paper Format
40. printerDesc[0] = new PropertyValue(); 41. printerDesc[0].Name = \"PaperFormat\"; 42. printerDesc[0].Value = PaperFormat.USER; 43.
44. // Paper Size
45. printerDesc[1] = new PropertyValue(); 46. printerDesc[1].Name = \"PaperSize\"; 47. printerDesc[1].Value = KaoqinReport; 48. 49. try {
50. xPrintable.setPrinter(printerDesc); 51. } catch (IllegalArgumentException e) { 52. e.printStackTrace(); 53. } 54. 55. }
如果是excel有多个sheet,上面的部分只会影响第一个sheet,其他sheet还会以A4的大小输出。
上面的代码在JODConverter v2.x下面测试通过