0

我希望我的问题不是太独特。我正在使用 Django 框架和 xhtml2pdf 库。

{% for part_workorder in partsReceived %}
    {%if part_workorder.cert_document %}

    <div class="imgHolder">
        <img src="{{part_workorder.cert_document.path }}" />
    </div><img src="{{part_workorder.cert_document.path }}" />

我的每个“部分”都与使用 xhtml2pdf 库插入 pdf 的认证文档相关联。这非常适合 jpeg 和 png。

当我的认证文件之一是 pdf 时,问题就出现了。是页面留空。也许这是因为我插入到生成的 pdf(使用 xhtml2pdf 创建)中的 pdf(证明文件)不止一页。

我的解决方案:使用模板标签(将路径作为参数传递)并将图像分解为多个 jpeg,返回一个图像数组。

不完整的解决方案:

from pdf2image import convert_from_path

register = template.Library()


@register.filter
def get64(path):
    images = convert_from_path(path)
    for i in range(len(images)):
        images[i].save('page' + str(i) + '.jpg', 'JPEG')
        print(images[i])
        # Save pages as images in the pdf

我知道这不是正确的尝试...

任何建议和帮助将不胜感激!

4

0 回答 0