Is there any way to search for a graphic in a PDF page?
For example, I have used the PyFPDF library to generate a PDF with few rectangles and circles (code below). Now I would like to
Is there any library which allows this?
PDF generation with few rectangles and circles:
Sample PDF generated using code below: Download the 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
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
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
Thus as with many a PDF question:-
Can I reverse engineer PDF to "other the and that,this Do" the answer is do it at source
$pdf->SetDrawColor(0,0,0);
$pdf->Circle(100,50,30,'D');
$pdf->SetFillColor(0,0,255);
$pdf->Circle(110,47,7,'F');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.