4

Javaでプログラムを書いています(Ubuntuを使用しています)。Jodconverter を使用してドキュメントを PDF に変換しています。ドキュメントを横向きモードに変換する必要がありますが、Jodconverter が向きの変更をサポートしていないことを読みました。OpenOffice API も試しましたが、同じ問題に直面しています。

ランドスケープに変換する Java ライブラリはありますか?

4

4 に答える 4

4

Open OfficeドキュメントでJodconverterを使用することに関する同様の質問から:

http://groups.google.com/group/jodconverter/browse_thread/thread/dc96df64c7d60ada/c1692fee92513b7a

簡単な答え: できません。ページの向きはドキュメントのプロパティ (メニュー [書式] > [Calc のページ]) であり、PDF エクスポート オプションではありません。そのため、XLS ドキュメントで既に設定されている必要があります。

于 2011-09-19T07:06:04.900 に答える
0

オーバーライドしてみるOfficeDocumentConverter

OfficeDocumentConverter converter = new OfficeDocumentConverter(officeManager) {

            private Map<String, Object> createDefaultLoadProperties() {
                Map<String, Object> loadProperties = new HashMap<String, Object>();
                loadProperties.put("Hidden", true);
                loadProperties.put("ReadOnly", true);
                loadProperties.put("UpdateDocMode", UpdateDocMode.QUIET_UPDATE);
                return loadProperties;
            }

            @Override
            public void convert(File inputFile, File outputFile, DocumentFormat outputFormat) throws OfficeException {
                String inputExtension = FilenameUtils.getExtension(inputFile.getName());
                DocumentFormat inputFormat = getFormatRegistry().getFormatByExtension(inputExtension);
                inputFormat.setLoadProperties(Collections.singletonMap("PaperOrientation", PaperOrientation.LANDSCAPE));
                StandardConversionTask conversionTask = new StandardConversionTask(inputFile, outputFile, outputFormat) {

                    @Override
                    protected void modifyDocument(XComponent document) throws OfficeException {
                        PropertyValue[] printerDesc = OfficeUtils.toUnoProperties(Collections.singletonMap("PaperOrientation", PaperOrientation.LANDSCAPE));
                        XPrintable xPrintable = cast(XPrintable.class, document);
                        try {
                            xPrintable.setPrinter(printerDesc);
                        } catch (com.sun.star.lang.IllegalArgumentException e) {
                            logger.error(e.getMessage());
                        }
                        super.modifyDocument(document);
                    }
                };
                conversionTask.setDefaultLoadProperties(createDefaultLoadProperties());
                conversionTask.setInputFormat(inputFormat);
                officeManager.execute(conversionTask);
            }

        };
于 2013-04-04T13:18:08.707 に答える
0

私は解決策を見つけました。Open Office API for Java を使用してドキュメントをランドスケープ PDF に変換しました。これが同じコードです。

System.out.println("starting...");
                String oooExeFolder = "/usr/lib/openoffice/program";
                XComponentContext xContext = BootstrapSocketConnector.bootstrap(oooExeFolder);

                XMultiComponentFactory xMCF = xContext.getServiceManager();

                Object oDesktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xContext);

                XComponentLoader xCLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, oDesktop);
                System.out.println("loading ");
                PropertyValue[] printerDesc = new PropertyValue[1];
                printerDesc[0] = new PropertyValue();
                printerDesc[0].Name = "PaperOrientation";
                printerDesc[0].Value = PaperOrientation.LANDSCAPE;
                // Create a document
                XComponent document = xCLoader.loadComponentFromURL(loadUrl, "_blank", 0, printerDesc);
                // Following property will convert doc into requested orientation.
                XPrintable xPrintable = (XPrintable) UnoRuntime.queryInterface(XPrintable.class, document);
                xPrintable.setPrinter(printerDesc);
                PropertyValue[] conversionProperties = new PropertyValue[3];
                conversionProperties[1] = new PropertyValue();
                conversionProperties[1].Name = "FilterName";
                conversionProperties[1].Value = "writer_pdf_Export";// 
                conversionProperties[0] = new PropertyValue();
                conversionProperties[0].Name = "Overwrite ";
                conversionProperties[0].Value = new Boolean(true);
                System.out.println("closing");
                XStorable xstorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
                xstorable.storeToURL(storeUrl, conversionProperties);
                System.out.println("closing");
                XCloseable xcloseable = (XCloseable) UnoRuntime.queryInterface(XCloseable.class, document);
                xcloseable.close(false);
于 2011-09-26T12:00:45.537 に答える
0

PDF にエクスポートし、 PDFboxなどの PDF ライブラリを使用してページを 90 度回転します。

PDPage.setRotation(int)すべてのページで試してください( PDDocument.getDocumentCatalog().getAllPages())。

于 2011-09-19T07:16:30.250 に答える