简体   繁体   English

在 PDF 中搜索/更新图形

[英]Search/Update Graphics in a PDF

Is there any way to search for a graphic in a PDF page?有什么办法可以在PDF页面中搜索到图片吗?

For example, I have used the PyFPDF library to generate a PDF with few rectangles and circles (code below).例如,我使用PyFPDF 库生成了一个 PDF ,其中包含几个矩形和圆形(代码如下)。 Now I would like to现在我想

  • get a list of ellipses that are printed in each page and their location.获取每页中打印的省略号及其位置的列表。
  • and update the color of all the circles to blue并将所有圆圈的颜色更新为蓝色

Is there any library which allows this?有没有允许这样做的图书馆?


PDF generation with few rectangles and circles: PDF 生成几个矩形和圆形:

Sample PDF generated using code below: Download the PDF使用以下代码生成的示例 PDF:下载 PDF

from fpdf import FPDF

# Prepare PDF generator
pdf = FPDF(orientation = 'L', unit = 'in', format = 'A4')
pdf.add_page()
pdf.set_fill_color(0, 0, 0)

# Draw the rectangle
pdf.rect(x = 1, y = 1, w = 2, h = 2, style = 'S')
pdf.rect(x = 1.5, y = 1.5, w = 5, h = 1, style = 'S')
pdf.ellipse(x = 1, y = 4, w = 1, h = 1, style = 'S')
pdf.ellipse(x = 4, y = 5, w = 1, h = 1, style = 'S')
pdf.ellipse(x = 9, y = 2, w = 1, h = 1, style = 'F')
pdf.rect(x = 6, y = 5, w = 2, h = 1, style = 'F')

# Write to file
pdf.output("test.pdf")

NOT YOUR ANSWER just a visual comment NOT YOUR ANSWER 只是一个视觉评论

Its not been easy to dissect and rebuild by hand so used some shortcuts.手工解剖和重建并不容易,所以使用了一些快捷方式。 but the pdf supplied has all vectors as only one black encoded stream object that looks something like this但是 pdf 提供的所有向量只有一个黑色编码 stream object 看起来像这样

4 0 obj
<</Filter /FlateDecode /Length 251>>
stream
xœU’»q!„sª 3舜ºÆ¿#'Nܾ-.‚ïЮVßCN¥Åß¹äœãWh<7±°$¶Hª‹Þ°þ|Æ@ÙÖ^­­
©yW¸Ì¼˜­‚ïcÂÕHÜ’M]Þr˜F0KÄÝ:€›ÄäBIstK¹,A# á9E>£ŽóPïÌÔWQ¹¼„õÑI²^9ØìR‚à;ÂáÖW(©Êåš¾Þõœ"!”¼k‚Æû‹Rñ   ÏTëóöÒ²'®¶;F¨uç8§j—òaZ°ô²r@)­_¾ ù·¼+‰ |æñTøº×óÿ_Ø+ü)„Ÿ
endstream
endobj

Thus at a simple level everything at once could possibly be prefixed as blue.因此,在一个简单的层面上,所有的东西都可以同时作为蓝色的前缀。 but if we decode the stream, it is easier to inject colours per part of stroked stream here I marked the stack targets in green and have injected 0 0 1 rg for blue (end of square re ct & 1 group of the c hords and 0 g for stop Graphics change between times但是,如果我们解码 stream,则更容易为描边 stream 的每个部分注入颜色,我将堆栈目标标记为绿色,并为蓝色注入 0 0 1 rg(方块末端和 c hords的 1 组和 0 g 停止图形在时间之间变化

在此处输入图像描述

Thus as with many a PDF question:-因此,与许多 PDF 问题一样:-

Can I reverse engineer PDF to "other the and that,this Do" the answer is do it at source我可以将 PDF 逆向工程为“其他的那个,这个做”答案是在源头上做

$pdf->SetDrawColor(0,0,0);
$pdf->Circle(100,50,30,'D');
$pdf->SetFillColor(0,0,255);
$pdf->Circle(110,47,7,'F');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM