问题描述
我有要从中提取图像的 PDF 文件,其中一些图像还具有与之关联的网址。
我可以用
提取网址@keyframes
autoplay {
0%,15% {
left: 0px;
}
25%,40% {
left: -1920px;
}
50%,65% {
left: -3840px;
}
100% {
left: -5760px;
}
并且我知道每个 url 都有一个关联的矩形(例如,import pikepdf
file = "testPDF.pdf"
pdf_file = pikepdf.Pdf.open(file)
urls = []
# iterate over PDF pages
for page in pdf_file.pages:
if page.get("/Annots") is not None:
for annots in page.get("/Annots"):
uri = annots.get("/A").get("/URI")
if uri is not None:
if re.search("facebook|twitter",str(uri)):
print("[+] URL Found:",uri)
urls.append(uri)
返回一个带有 pdf_file.pages[2].get("/Annots")[0].get("/Rect")
的数组,我认为它是链接的坐标(作为一个不可见的矩形)。
我可以用 [ Decimal('64.554153'),Decimal('697.37781'),Decimal('346.79092'),Decimal('760.43066') ]
单独提取图像:
fitz
然而,当我检查图像时,例如 import fitz
file = "testPDF.pdf"
doc = fitz.open(file)
for i in range(len(doc)):
for img in doc.getPageImageList(i):
xref = img[0]
pix = fitz.pixmap(doc,xref)
if pix.n < 5: # this is GRAY or RGB
pix.writePNG("p%s-%s.png" % (i,xref))
else: # CMYK: convert to RGB first
pix1 = fitz.pixmap(fitz.csRGB,pix)
pix1.writePNG("pp%s-%s.png" % (i,xref))
pix1 = None
pix = None
,x 和 y 位置始终为 0。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)