无法通过JAVA代码将任何文件转换为pdf,尽管我可以通过地址通过Alfresco PDF渲染将其转换为:http://localhost:8090

问题描述 投票:0回答:1

我有这段代码,我不知道这是否是处理的方式,我的代码应该将任何文档(现在我正在使用 docx 进行测试)转换为 pdf。

这是我的代码:

@Override
protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
    CopyService copyService =serviceRegistry.getCopyService();
    NodeService nodeService =serviceRegistry.getNodeService();
    RenditionService2 renditionService2 =serviceRegistry.getRenditionService2();
    NodeRef newUponNodeRef = copyService.copy(actionedUponNodeRef, nodeService.getPrimaryParent(actionedUponNodeRef).getParentRef(),nodeService.getPrimaryParent(actionedUponNodeRef).getTypeQName(),nodeService.getPrimaryParent(actionedUponNodeRef).getQName());
    TransformDefinition transformationDefinition = new TransformDefinition(Mimetype.MIMETYPE_PDF, null, null, null, null);
    renditionService2.render(newUponNodeRef, transformationDefinition);
        
}

这是我的日志:

docker-cd-ged-mar-acs-1       |  2022-11-21 15:24:40,207  ERROR [content.transform.LocalTransformServiceRegistry] [QuartzScheduler_Worker-1] Transformer "outlookMsgToLibreofficeViaText" references the transformOptions (tikaOptions) which do not exist. Read from resource alfresco/transforms/0100-basePipelines.json
docker-cd-ged-mar-acs-1       |  2022-11-21 15:24:40,207  ERROR [content.transform.LocalTransformServiceRegistry] [QuartzScheduler_Worker-1] Transformer "htmlToImageViaTXT" references the transformOptions (pdfRendererOptions) which do not exist. Read from resource alfresco/transforms/0100-basePipelines.json
docker-cd-ged-mar-acs-1       |  2022-11-21 15:25:50,251  ERROR [content.transform.LocalTransformServiceRegistry] [QuartzScheduler_Worker-1] Transformer "textToImageViaPdf" references the transformOptions (pdfRendererOptions) which do not exist. Read from resource alfresco/transforms/0100-basePipelines.json

我期待通过代码直接转换为 pdf。

java transform alfresco
1个回答
0
投票

我使用文档中的代码 - https://docs.alfresco.com/content-services/latest/develop/reference/java-foundation-ref/

ContentService contentService = serviceRegistry.getContentService();
SynchronousTransformClient synchronousTransformClient = serviceRegistry.getSynchronousTransformClient();
ContentReader srcReader = contentService.getReader(nodeRef, ContentModel.PROP_CONTENT);
ContentWriter pdfWriter = contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
pdfWriter.setMimetype(Mimetype.MIMETYPE_PDF); // new mimetype
pdfWriter.setEncoding(srcReader.getEncoding()); // original encoding
synchronousTransformClient.transform(srcReader, pdfWriter, Collections.emptyMap(), null, null);

如果我在没有transform-core-aio的情况下在本地运行它,它会抛出:

Transformation of application/vnd.openxmlformats-officedocument.wordprocessingml.document size 14850 to application/pdf unsupported

但是在带有transform-core-aio的服务器上它运行良好。

© www.soinside.com 2019 - 2024. All rights reserved.