小编Ale*_*ung的帖子

在 AWS Lambda 中将 doc/docx 转换为 pdf?

尝试过:

  • 预制 Lambda 应用程序 docx 到 pdf(该应用程序不再可部署) https://github.com/NativeDocuments/docx-to-pdf-on-AWS-Lambda
  • 安装 comtypes.client 和 win32com.client(在 lambda 中部署后似乎都不起作用)出现错误:无法导入模块“lambda_function”:无法导入名称“COMError”

可能性:

-当我从 s3 获取文档文件时,在浏览器 JS 中将其转换为 PDF。- 以某种方式修复部署包中的 comtypes 或 win32com。正在使用Python 3.6。

import json
import urllib
import boto3
from boto3.s3.transfer import TransferConfig
from botocore.exceptions import ClientError
import lxml
import comtypes.client
import io
import os
import sys
import threading
from docx import Document

def lambda_handler(event, context):

    bucket = event['Records'][0]['s3']['bucket']['name']
    key = urllib.parse.unquote_plus(event['Records'][0]['s3']['object']['key'], encoding='utf-8')

    try:
        response = s3.get_object(Bucket=bucket, Key=key)

        # Creating the Document
        f = io.BytesIO(response['Body'].read())
        document = …
Run Code Online (Sandbox Code Playgroud)

pdf-generation amazon-web-services aws-lambda

5
推荐指数
1
解决办法
6144
查看次数