使用java打开Office 1.1.4导出到带有背景图像的PDF

使用java打开Office 1.1.4导出到带有背景图像的PDF,java,pdf,openoffice.org,Java,Pdf,Openoffice.org,我有一个问题需要解决,我们使用OpenOffice 1.1.4模板化报表,并通过编程将其导出为PDF。 创建模板的团队最近将表格中的标题图像和一些图像更改为背景图像,然后才刚刚插入,因为这一更改当前程序不会使用这些图像创建PDF。我们可以手动从OpenOffice导出,其中包括图像。有人能帮我做一个改变,我可能需要得到这些背景图片包括请 当前代码: private void print(XInterface xComponent, PrintRequestDTO printReq

我有一个问题需要解决,我们使用OpenOffice 1.1.4模板化报表,并通过编程将其导出为PDF。 创建模板的团队最近将表格中的标题图像和一些图像更改为背景图像,然后才刚刚插入,因为这一更改当前程序不会使用这些图像创建PDF。我们可以手动从OpenOffice导出,其中包括图像。有人能帮我做一个改变,我可能需要得到这些背景图片包括请

当前代码:

private void print(XInterface xComponent,
        PrintRequestDTO printReq, File sourceFile,
        Vector<String> pages) throws java.lang.Exception {

    String pageRange;

    // XXX create the PDF via OOo export facility
    com.sun.star.frame.XStorable pdfCreator = (com.sun.star.frame.XStorable) UnoRuntime
            .queryInterface(
                    com.sun.star.frame.XStorable.class,
                    xComponent);

    PropertyValue[] outputOpts = new PropertyValue[2];

    outputOpts[0] = new PropertyValue();
    outputOpts[0].Name = "CompressionMode";
    outputOpts[0].Value = "1"; // XXX Change this perhaps?

    outputOpts[1] = new PropertyValue();
    outputOpts[1].Name = "PageRange";

    if (printReq.getPageRange() == null) {

        pageRange = "1-";

    }
    else {

        if (printReq.getPageRange().length() > 0) {

            pageRange = printReq.getPageRange();

        }
        else {

            pageRange = "1-";

        }

    }

    log.debug("Print Instruction - page range = "
            + pageRange);

    PropertyValue[] filterOpts = new PropertyValue[3];

    filterOpts[0] = new PropertyValue();
    filterOpts[0].Name = "FilterName";
    filterOpts[0].Value = "writer_pdf_Export"; // MS Word 97

    filterOpts[1] = new PropertyValue();
    filterOpts[1].Name = "Overwrite";
    filterOpts[1].Value = new Boolean(true);

    filterOpts[2] = new PropertyValue();
    filterOpts[2].Name = "FilterData";
    filterOpts[2].Value = outputOpts;

    if (pages.size() == 0) { // ie no forced page breaks
        // set page range
        outputOpts[1].Value = pageRange;
        filterOpts[2] = new PropertyValue();
        filterOpts[2].Name = "FilterData";
        filterOpts[2].Value = outputOpts;

        File outputFile = new File(
                sourceFile.getParent(),
                printReq.getOutputFileName()
                        + ".pdf");

        StringBuffer sPDFUrl = new StringBuffer(
                "file:///");
        sPDFUrl.append(outputFile.getCanonicalPath()
                .replace('\\', '/'));

        log.debug("PDF file = " + sPDFUrl.toString());

        if (pdfCreator != null) {

            sleep();
            pdfCreator.storeToURL(sPDFUrl.toString(),
                    filterOpts);

        }
    }
    else if (pages.size() > 1) {
        throw new PrintDocumentException(
                "Only one forced split catered for currently");
    }
    else { // a forced split exists.
        log.debug("Page break found in "
                + (String) pages.firstElement());
        String[] newPageRanges = calculatePageRanges(
                (String) pages.firstElement(), pageRange);

        int rangeCount = newPageRanges.length;
        for (int i = 0; i < rangeCount; i++) {
            outputOpts[1].Value = newPageRanges[i];
            log.debug("page range = " + newPageRanges[i]);
            filterOpts[2] = new PropertyValue();
            filterOpts[2].Name = "FilterData";
            filterOpts[2].Value = outputOpts;
            String fileExtension = (i == 0 && rangeCount > 1) ? "__Summary.pdf"
                    : ".pdf";
            File outputFile = new File(
                    sourceFile.getParent(),
                    printReq.getOutputFileName()
                            + fileExtension);

            StringBuffer sPDFUrl = new StringBuffer(
                    "file:///");
            sPDFUrl.append(outputFile.getCanonicalPath()
                    .replace('\\', '/'));
            log.debug("PDF file = " + sPDFUrl.toString());

            if (pdfCreator != null) {
                log.debug("about to create the PDF file");
                sleep();
                pdfCreator.storeToURL(
                        sPDFUrl.toString(), filterOpts);
                log.debug("done");
            }
        }
    }       
}

提前感谢。

在找到正确的属性后,我能够打开隐藏属性设置为false的文件,这意味着当文件导出为PDF时,它包含背景图像。遗憾的是,我找不到另一个隐藏文件的解决方案,但至少它可以工作。

很高兴让文档可见的建议起到了帮助。因为它也解决了这个问题,所以您有一个计时/线程问题。我怀疑您会发现另一个狡猾的选择,即在执行save to PDF之前进行睡眠,也会允许图像显示。这两种解决方案都不好


最有可能的最佳修复方法是升级到新版本的OpenOffice,您的API调用应该仍然有效。另一种选择是尝试调用API,要求文档自我刷新。

当应用程序运行时,在保存为PDF之前,您能否看到在Open Office中加载的文件?您可能需要在加载文档时设置可见性。如果是,图像是否可见?否文件隐藏。我确实这样想,并试图让它可见,但我无法让它这样做。如果你能帮我把它打开看,我会很感激的?