Azure Function 通过逻辑应用从 HTML 生成 PDF

问题描述 投票:0回答:1

致敬,编码大师

我正在寻求有关 azure 函数的帮助,该函数可以从通过逻辑应用程序触发的 CSS 格式的 html 生成 pdf 文件。

解决方案必须使用开源 pdf 库,可能是 Puppeteer、wkhtmltopdf 或 jsPDF 之类的?

并且必须处理具有动态数据和关键格式的复杂 html 表格(例如长表格中优雅的分页符等)

感谢对此的任何和所有帮助......

提前致谢!

html azure-functions pdf-generation azure-logic-apps open-source
1个回答
0
投票

您不需要使用Azure Functions从html更改为pdf,您可以在逻辑应用程序中使用连接器(许多连接器可以将html转换为pdf),如下所示:

enter image description here

如果您想使用 Azure 函数,您可以使用下面的代码并将函数应用程序容器化,我按照我在 SO-Thread 中的回答:

import subprocess
import azure.functions as func

def main(req: func.HttpRequest) -> func.HttpResponse:
    cho_value = req.get_body().decode('utf-8')
    cho_htmlPath =r'C:\Users\bojja\Downloads\78282689.html'
    cho_outputFile = r'c:\Users\bojja\Downloads'
    with open(cho_htmlPath, 'w', encoding='utf-8') as k:
        k.write(cho_value)
    subprocess.run(['c:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe', cho_htmlPath, cho_outputFile])
    with open(cho_outputFile, 'rb') as resultfile:
        rescon = resultfile.read()
    return func.HttpResponse(rescon, mimetype='application/pdf', status_code=200)

然后您可以使用以下操作从逻辑应用程序调用函数应用程序:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.