我最近实现了 IBM Watson 的文档转换 API。我总是在转换 pdf 文档时遇到编码错误!!!
#!/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))