将 PDF 插入 xhtml2pdf

问题描述

我希望我的问题不是太独特。我正在使用 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 时,问题就出现了。 is 页面留空。也许这是因为我插入生成的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

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

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

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...