aspose-pdf 实现 PDF 转 word
时间: 2023-11-29 08:06:11 浏览: 139
Word转PDF aspose-words-21.11-jdk17.jar 和示例
以下是使用aspose-pdf实现PDF转Word的Python代码示例:
```python
import asposepdfcloud
from asposepdfcloud.apis.pdf_api import PdfApi
from asposepdfcloud.apis.words_api import WordsApi
from asposepdfcloud.configuration import Configuration
from asposepdfcloud.models import SaveOptions
# 设置API密钥和APP SID
configuration = Configuration()
configuration.app_sid = 'YOUR_APP_SID'
configuration.app_key = 'YOUR_APP_KEY'
# 初始化PDF和Word API
pdf_api = PdfApi(configuration)
words_api = WordsApi(configuration)
# 将PDF文件转换为Word
result_name = 'result.docx'
pdf_file = 'input.pdf'
format = 'docx'
body = SaveOptions(save_format=format)
response = pdf_api.put_pdf_in_request_to_doc(
result_name,
file=open(pdf_file, 'rb'),
options=body
)
# 将转换后的Word文件保存到本地
response = words_api.download_file(result_name)
with open(result_name, 'wb') as f:
f.write(response.content)
```
阅读全文