【问题标题】:Why do I get "Could not push back" error when trying to use the IBM Bluemix Document Conversion service?为什么在尝试使用 IBM Bluemix Document Conversion 服务时出现“Could not push back”错误?
【发布时间】:2017-03-16 15:27:51
【问题描述】:

我正在尝试使用带有 Node.js 应用程序的 Bluemix Document Conversion 服务来转换文档。我在我的应用程序中得到的只是错误,但我使用的测试文档使用演示页面转换得很好。下面是一个演示该问题的最小应用程序(请注意,虽然此应用程序正在从磁盘转换 PDF,但“真正的”应用程序不能这样做,因此是 Buffer 对象)。

'use strict';

var fs = require('fs');
var DocumentConversionV1 = require('watson-developer-cloud/document-conversion/v1');
var bluemix=require('./my_bluemix');
var extend=require('util')._extend; //Node.js' built-in object extend function

var dcCredentials =  extend({
  url: '<url>',
  version: 'v1',
  username: '<username>',
  password: '<password>'
}, bluemix.getServiceCreds('document_conversion')); // VCAP_SERVICES
var document_conversion = new DocumentConversionV1(dcCredentials);

var contents = fs.readFileSync('./testdoc.pdf', 'utf8');

var parms={
   file: new Buffer(contents,'utf8'),
   conversion_target: 'ANSWER_UNITS',     // (JSON) ANSWER_UNITS, NORMALIZED_HTML, or NORMALIZED_TEXT
   content_type:'application/pdf',
   contentType:'application/pdf', //don't know which of these two works, seems to be inconsistent so I include both
   html_to_answer_units: {selectors: [ 'h1', 'h2','h3', 'h4']},
   };
console.log('First 100 chars of file:\n******************\n'+contents.substr(0,100)+'\n******************\n');
document_conversion.convert(parms, function(err,answerUnits)
   {
   if (!err)
      console.log('Returned '+answerUnits.length);
   else
      console.log('Error: '+JSON.stringify(err));
   });

针对测试 PDF (782K) 运行此程序的结果是:

$ node test.js
[DocumentConversion] WARNING: No version_date specified. Using a (possibly old) default. e.g. watson.document_conversion({ version_date: "2015-12-15" })
[DocumentConversion] WARNING: No version_date specified. Using a (possibly old) default. e.g. watson.document_conversion({ version_date: "2015-12-15" })
First 100 chars of file:
******************
%PDF-1.5
%����
1 0 obj
<</Type/Catalog/Pages 2 0 R/Lang(en-US) /StructTreeRoot 105 0 R/MarkInfo<<
******************

Error: {"code":400,"error":"Could not push back 82801 bytes in order to reparse stream. Try increasing push back buffer using system property org.apache.pdfbox.baseParser.pushBackSize"}
$

谁能告诉我

  1. 如何摆脱警告消息
  2. 为什么文档没有得到转换
  3. 如何“增加推回缓冲区”

其他文档给出了不同的错误,但我希望如果我能解决这个问题,那么其他错误也会消失。

【问题讨论】:

    标签: ibm-cloud ibm-watson document-conversion


    【解决方案1】:
    1. 您可以通过在配置中指定版本日期来消除警告消息。有关示例,请参见测试。 1

    2. 如果通过演示转换的文档在使用您的应用程序时转换失败,则可能是二进制数据传递给服务的方式出错。 (例如,它已损坏或被截断。)您可以在此处查看演示的 Node.js 源代码 2。它可能会帮助您找出错误或为您提供加载/发送文件的不同方法。

    3. 这是来自服务使用的底层库之一的错误。不幸的是,此时调用者无法调整它。

    【讨论】:

    • 事实证明,我的参数安排得很糟糕。正确的形式是 { file: { value: new Buffer(contents), options: { content_type:'application/pdf' } }, conversion_target: 'ANSWER_UNITS', config: { conversion_target:'ANSWER_UNITS', // 拆分 html 文件通过“h2”、“h3”和“h4”标签 html_to_answer_units: {selectors: [ 'h1', 'h2','h3', 'h4']} } 是的,conversion_target 参数必须在那里两次!
    猜你喜欢
    • 1970-01-01
    • 2021-09-13
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 2015-01-15
    • 2023-01-09
    • 1970-01-01
    • 2021-08-22
    相关资源
    最近更新 更多