在 Python 中,有什么方法可以自动检测 PDF 特定区域的颜色,然后将它们转换为 RGB 或将它们与图例进行比较,然后获取颜色?
最佳答案
Felipe的方法对我不起作用,但我想到了这个:
#!/usr/bin/env python
# -*- Encoding: UTF-8 -*-
import minecart
colors = set()
with open("file.pdf", "rb") as file:
document = minecart.Document(file)
page = document.get_page(0)
for shape in page.shapes:
if shape.fill:
colors.add(shape.fill.color.as_rgb())
for color in colors: print color
这将在您的文档的第一页中打印所有唯一 RGB 值的整洁列表(当然,您可以将其扩展到所有页面)。
关于python - 如何从 PDF Python 中检测颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29971228/