python读取pdf内容转word,如何使用python将txt文件或PDF文件转换成Word文档?

您可以使用GroupDocs.Conversion Cloud,它提供了Python SDK文本/PDF到DOC/DOCX converrion和许多其他常见的文件格式,从一种格式到另一种格式,而不依赖于任何第三方工具或软件。

下面是示例Python代码。# Import module

import groupdocs_conversion_cloud

# Get your app_sid and app_key at https://dashboard.groupdocs.cloud (free registration is required).

app_sid = "xxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx"

app_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

# Create instance of the API

convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)

file_api = groupdocs_conversion_cloud.FileApi.from_keys(app_sid, app_key)

try:

#upload soruce file to storage

filename = 'Sample.pdf'

remote_name = 'Sample.pdf'

output_name= 'sample.doc'

strformat='doc'

request_upload = groupdocs_conversion_cloud.UploadFileRequest(remote_name,filename)

response_upload = file_api.upload_file(request_upload)

#Convert PDF to Word document

settings = groupdocs_conversion_cloud.ConvertSettings()

settings.file_path =remote_name

settings.format = strformat

settings.output_path = output_name

loadOptions = groupdocs_conversion_cloud.PdfLoadOptions()

loadOptions.hide_pdf_annotations = True

loadOptions.remove_embedded_files = False

loadOptions.flatten_all_fields = True

settings.load_options = loadOptions

convertOptions = groupdocs_conversion_cloud.DocxConvertOptions()

convertOptions.from_page = 1

convertOptions.pages_count = 1

settings.convert_options = convertOptions

.

request = groupdocs_conversion_cloud.ConvertDocumentRequest(settings)

response = convert_api.convert_document(request)

print("Document converted successfully: " + str(response))

except groupdocs_conversion_cloud.ApiException as e:

print("Exception when calling get_supported_conversion_types: {0}".format(e.message))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值