IBM Watson Document Conversion not working

南楼画角 提交于 2019-12-25 08:46:46

问题


I recently implemented the Document Conversion API from IBM Watson. I always get an encoding error for converting pdf document!!!

#!/usr/bin/env python
#coding: utf-8


import json
from watson_developer_cloud import DocumentConversionV1
from io import open
document_conversion = DocumentConversionV1(
  username='{XXXXXXXXXXX}',
  password='{XXXXXXXXXXXXX}',
  version='2015-12-15'
)
config = {
  'conversion_target': 'ANSWER_UNITS',
  # Use a custom configuration.
  'word': {
    'heading': {
      'fonts': [
        {'level': 1, 'min_size': 24},
        {'level': 2, 'min_size': 16, 'max_size': 24}
      ]
    }
  }
}

with open(('sample.pdf'), 'r') as document:
  response = document_conversion.convert_document(document=document, config=config)
  print(json.dumps(response, indent=2))

enter image description here


回答1:


enter code hereYour error is the config JSON. Your still using the word config instead of the pdf config JSON:

{
"pdf": {
    "heading": {
        "fonts": [
            {"level": 1, "min_size": 24},
            {"level": 2, "min_size": 18, "max_size": 23, "bold": true},
            {"level": 3, "min_size": 14, "max_size": 17, "italic": false},
            {"level": 4, "min_size": 12, "max_size": 13, "name": "Times New Roman"}
        ]
    }
}}

If you want to use answer units please add this to your config file as well:

var config = {
conversion_target: "answer_units",
"pdf": {
    "heading": {
        "fonts": [{
            "level": 1,
            "min_size": 24,
            "max_size": 80
        },
            {
                "level": 2,
                "min_size": 18,
                "max_size": 24,
                "bold": false,
                "italic": false
            },
            {
                "level": 2,
                "min_size": 18,
                "max_size": 24,
                "bold": true
            },
            {
                "level": 3,
                "min_size": 13,
                "max_size": 18,
                "bold": false,
                "italic": false
            },
            {
                "level": 3,
                "min_size": 13,
                "max_size": 18,
                "bold": true
            },
            {
                "level": 4,
                "min_size": 11,
                "max_size": 13,
                "bold": true,
                "italic": false
            }
        ]
    }
}

}

description: https://www.ibm.com/watson/developercloud/doc/document-conversion/customizing.html



来源:https://stackoverflow.com/questions/44407842/ibm-watson-document-conversion-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!