0

我的任务是导出文档的本机内容和再现内容。我正在使用 IDfExportOperation 导出文档本机内容。但要求也是导出再现格式。怎么做?你能帮我么?

4

2 回答 2

1

使用以下代码,您可以获得本机和再现内容。对于再现,您需要getRenditions()使用IDfSysObject.

public void execute(IDfSession dfSession, String objectId) throws DfException {
    boolean result;

    // Use the factory method to create an IDfExportOperation instance
    IDfExportOperation exportOperation = clientX.getExportOperation();

    IDfSysObject sysObject = (IDfSysObject) dfSession.getObject(new DfId(objectId));

    if (sysObject != null) {
        exportOperation.setDestinationDirectory("C:/path/to/folder");
        IDfDocument document = (IDfDocument) sysObject;
        // set the document name format
        document.setObjectName("[" + document.getVersionLabel(0) + "]" + "-" + document.getObjectName());

        IDfExportNode exportNode;

        if (document.isVirtualDocument()) {
            IDfVirtualDocument virtualDocument = document.asVirtualDocument("CURRENT", false);
            exportOperation.setDestinationDirectory("C:/path/to/folder");
            // Create an export node, adding the document/sysObject to the export operation object.
            exportNode = (IDfExportNode) exportOperation.add(virtualDocument);
        } else {
            // Create an export node, adding the document/sysObject to the export operation object.
            exportNode = (IDfExportNode) exportOperation.add(document);
        }
        // Get the document's format
        exportNode.setFormat(document.getContentType());
        result = exportOperation.execute();

        if (!result) {
            IDfList errors = exportOperation.getErrors();
            for (int i = 0; i < errors.getCount(); i++) {
                IDfOperationError operationError = (IDfOperationError) errors.get(i);
                System.out.println.error("Error in export operation :( with error code: " + operationError
                        .getErrorCode() + " and error message: " + operationError.getMessage());
            }
        } else {
            System.out.println.info("Exported document successfully :) with doc id: " + objectId + " having format "
                    + document.getContentType());
        }
        System.out.println.info("Processing rendition for the doc " + objectId);
        // get rendition
        IDfCollection dfCollection = document.getRenditions("r_object_id,rendition,full_format");
        try {
            while (dfCollection.next()) {
                String rendition = dfCollection.getString("rendition");

                if (Integer.parseInt(rendition) > 0) {
                    String format= dfCollection.getString("full_format");
                    if (format != null) {
                        String fileName = "C:/path/to/folder" + document.getObjectName() + "."
                                + format;
                        if (format.equalsIgnoreCase("pdf"))
                            sysObject.getFileEx(fileName, format, 0, false);
                            System.out.println.info("Rendition exported successfully for doc id:" + objectId);
                        }
                    }
                }
            }
        } catch (DfException dfe) {
            dfe.printStackTrace();
        } finally {
            if (dfCollection != null) {
                dfCollection.close();
            }
        }
    } else {
        System.out.println.info("Could not find doc id " + objectId + " in repository.");
    }
}
于 2020-08-06T14:01:21.143 回答
0

我使用 r_object_id 来查询 dmr_content 对象,将 parent_id 与 r-object_id 匹配,其中 full_format='redition-type'。

将该 object_id 传递给 IDfExportOperation。

于 2020-08-04T20:23:17.260 回答