在 php 中动态创建 PDF,支持 16 位颜色深度 png

发布于 2024-08-23 14:10:23 字数 407 浏览 7 评论 0原文

我正在尝试在应用程序中动态创建 pdf 文档,即用户单击链接,然后会向他们显示包含一些文本和一些图像的 pdf 文档。

我目前正在使用 FPDF v1.6 (http://www.fpdf.org/),它支持24 位(真彩色)png,但我遇到的问题是,这是一个遗留应用程序,有 1000 个 16 位颜色深度的 png,FPDF 不支持,而且我无法简单地进行转换,因为应用程序的其他部分使用这些图像。

我看到的唯一解决方案是:

  1. 即时转换 16 位 png 图像并将其嵌入到 pdf 中。
  2. 找到一个新的 pdf 类,它将接受 16 位颜色深度 png。

有人有什么想法吗?

I'm trying to create pdf documents on the fly in an application, i.e. a user clicks a link and a pdf document is displayed to them with some text and some images.

I'm currently using FPDF v1.6 (http://www.fpdf.org/) which supports 24bit (true colour) png's but the problem I have is that this is a legacy application and there's 1000's of png's that are of 16bit colour depth which FPDF does not support and I can't simply convert due to other parts of the application using these images.

The only solutions I see are:

  1. convert the 16bit png image on the fly and embed that into the pdf.
  2. find a new class pdf class that will accept 16bit colour depth png's.

Anyone have any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙与沫 2024-08-30 14:10:23

也许您可以尝试使用 TCPDF (从未将其与 16 位 PNG 一起使用,但应该很容易测试它)。

Maybe you could try using TCPDF (never used it with 16bit PNGs but it should be easy to test it).

罗罗贝儿 2024-08-30 14:10:23

在 python 中修复了这个问题:

def fix_16_bit_depth_not_supported(raw_image_path):
    """
    fix
    RuntimeError: FPDF error: 16-bit depth not supported: test.png
    """
    new_file, filename = tempfile.mkstemp(suffix='.png')
    os.close(new_file)
    i = cv2.imread(raw_image_path, cv2.IMREAD_UNCHANGED)
    img = np.array(i, dtype=np.float32)
    convert = img / 255.
    cv2.imwrite(filename, convert)
    return filename

Fixed with this in python:

def fix_16_bit_depth_not_supported(raw_image_path):
    """
    fix
    RuntimeError: FPDF error: 16-bit depth not supported: test.png
    """
    new_file, filename = tempfile.mkstemp(suffix='.png')
    os.close(new_file)
    i = cv2.imread(raw_image_path, cv2.IMREAD_UNCHANGED)
    img = np.array(i, dtype=np.float32)
    convert = img / 255.
    cv2.imwrite(filename, convert)
    return filename
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文