首页 > 解决方案 > 无法访问刚刚创建的文件 - JavaScript - Adob​​e Document Services API

问题描述

我是 JavaScript 新手,我一直在努力找出自己做错了什么,并在网上寻找资源来帮助解决我的问题。

利用 Adob​​e 的文档服务 API,我将 pdf 拆分为 99 页增量(由于他们的 OCR 调用仅支持 <100 页的文件),然后尝试在下一个 API 调用中使用刚刚生成并在本地保存的拆分页面(光学字符识别)。但是,当我尝试执行此操作时,出现如下错误:

Exception encountered while executing operation Error: no such file or directory, {**localdirectory**}

单独运行两个 API 调用时,它工作正常,所以我知道这不是我的语法。这使我认为文件在脚本中在技术上仍然是“打开的”,但我发现没有任何帮助解决这个问题。我尝试过要求“fs”,但 Adob​​e 打开文件的方式似乎与 fs 所需的不同。

下面的代码片段。

基本文件的初始拆分:

const splitPDFOperation = PDFServicesSdk.SplitPDF.Operation.createNew(),
        input = PDFServicesSdk.FileRef.createFromLocalFile(
            'localfile.pdf',
            PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf
        );
    // Set operation input from a source file.
    splitPDFOperation.setInput(input);

    // Set the maximum number of pages each of the output files can have.
    splitPDFOperation.setPageCount(99);

    // Execute the operation and Save the result to the specified location.
    splitPDFOperation.execute(executionContext)
        .then(result => {
            for(let i = 0; i < result.length; i++){
                result[i].saveAsFile(`output/split/${i}.pdf`);
            }
            step2(result);
        })

编辑:我相信“结果”是一个 FileRef 对象数组,可能是 Adob​​e 自己的结构?

在 step2() 内部:

for(let i = 0; i < splitfile.length; i++){
    console.log(``);
    input = PDFServicesSdk.FileRef.createFromLocalFile(`localdir/output/split/${i}.pdf`,
    PDFServicesSdk.SplitPDF.SupportedSourceFormat.pdf);
    ocrOperation.setInput(input);

    // Provide any custom configuration options for the operation.
    const options = new PDFServicesSdk.OCR.options.OCROptions.Builder()
        .withOcrType(PDFServicesSdk.OCR.options.OCRSupportedType.SEARCHABLE_IMAGE_EXACT)
        .withOcrLang(PDFServicesSdk.OCR.options.OCRSupportedLocale.EN_US)
        .build();
    ocrOperation.setOptions(options);

    // Execute the operation and Save the result to the specified location.
    ocrOperation.execute(executionContext)
        .then(result => result.saveAsFile(`output/split/ocr/${i}.pdf`))

上述大部分代码片段的文档/来源

标签: javascriptapiadobe

解决方案


推荐阅读