javascript - 无法访问刚刚创建的文件 - JavaScript - Adobe Document Services API
问题描述
我是 JavaScript 新手,我一直在努力找出自己做错了什么,并在网上寻找资源来帮助解决我的问题。
利用 Adobe 的文档服务 API,我将 pdf 拆分为 99 页增量(由于他们的 OCR 调用仅支持 <100 页的文件),然后尝试在下一个 API 调用中使用刚刚生成并在本地保存的拆分页面(光学字符识别)。但是,当我尝试执行此操作时,出现如下错误:
Exception encountered while executing operation Error: no such file or directory, {**localdirectory**}
单独运行两个 API 调用时,它工作正常,所以我知道这不是我的语法。这使我认为文件在脚本中在技术上仍然是“打开的”,但我发现没有任何帮助解决这个问题。我尝试过要求“fs”,但 Adobe 打开文件的方式似乎与 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 对象数组,可能是 Adobe 自己的结构?
在 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`))
解决方案
推荐阅读
- node.js - NodeJS“请求路径包含未转义的字符”使用代理时不起作用
- javascript - Swift HTTPbody 的 Javascript 等价物
- php - 如何将 Google Cloud Vision API 凭据密钥文件指向 yii2 框架中的 GOOGLE_APPLICATION_CREDENTIALS 变量
- php - WP Query - 分页按钮未显示
- lua - 在 OpenGL 示例中检测到多个 vm 错误
- c++ - OpenCV 鼠标事件总是在鼠标滚动时收到事件 10 和 *flag* 0?
- sql - 划分顺序记录
- java - JavaFX,Apache NetBeans 10,没有可见的类
- laravel-mix - 为什么我的 app.css 不包含 normalize.css
- nativescript - nativescript-vue dataform 不更新源数据