Please replace the 'Haroon' at the end of each page by 'Zakria Marwat'
cd /tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/ && python3 -c " import pdfplumber with pdfplumber.open('Block_N_Surgery_260721_185719.pdf') as pdf: print(f'Total pages: {len(pdf.pages)}') for i, page in enumerate(pdf.pages[:5]): words = page.extract_words() # look for Haroon haroon_words = [w for w in words if 'Haroon' in w['text'] or 'haroon' in w['text'].lower()] print(f'Page {i+1}: Haroon words = {haroon_words}') if haroon_words: print(f' Last word on page: {words[-3:] if len(words)>=3 else words}') "
python3 -c " import pdfplumber pdf_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_260721_185719.pdf' with pdfplumber.open(pdf_path) as pdf: # Check page 1 (index 0) separately since it had no Haroon page0 = pdf.pages[0] words0 = page0.extract_words() print('Page 1 last 5 words:', words0[-5:] if len(words0)>=5 else words0) print('Page 1 size:', page0.width, page0.height) # Get exact info for Haroon text on page 2 page1 = pdf.pages[1] words1 = page1.extract_words() haroon = [w for w in words1 if 'Haroon' in w['text']] made_by = [w for w in words1 if w['text'] in ('Made', 'by')] print() print('Page 2 Haroon:', haroon) print('Page 2 Made/by:', made_by) print('Page 2 size:', page1.width, page1.height) # Check how many pages have Haroon count = 0 for i, page in enumerate(pdf.pages): words = page.extract_words() if any('Haroon' in w['text'] for w in words): count += 1 print(f'Pages with Haroon: {count} out of {len(pdf.pages)}') "
python3 << 'EOF' import io from pypdf import PdfReader, PdfWriter from reportlab.pdfgen import canvas from reportlab.lib.colors import white pdf_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_260721_185719.pdf' output_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_ZakriaMarwat.pdf' reader = PdfReader(pdf_path) writer = PdfWriter() # Coordinates from pdfplumber (top-down from top of page): # Haroon: x0=300.81, x1=322.95, top=816.68, bottom=823.43 # Page height = 842.88 # PDF uses bottom-up coords, so: # pdf_y_bottom = page_height - pdfplumber_bottom # pdf_y_top = page_height - pdfplumber_top page_height = 842.88 # pdfplumber coords pl_x0 = 300.8115 pl_x1 = 322.9501 pl_top = 816.6804 pl_bottom = 823.4304 text_height = pl_bottom - pl_top # ~6.75 # Convert to PDF (bottom-up) coords pdf_y_bottom_text = page_height - pl_bottom # bottom of text box in PDF coords pdf_y_top_text = page_height - pl_top # top of text box in PDF coords # We'll cover from x0 to end of page + some margin, and a bit above/below cover_x0 = pl_x0 - 1 cover_x1 = 420 # wide enough for "Zakria Marwat" cover_y0 = pdf_y_bottom_text - 1 # PDF bottom-up cover_y1 = pdf_y_top_text + 1 font_size = text_height # ~6.75pt print(f"Text height: {text_height}") print(f"PDF y_bottom: {pdf_y_bottom_text}, y_top: {pdf_y_top_text}") print(f"Cover box: x({cover_x0},{cover_x1}) y({cover_y0},{cover_y1})") print(f"Font size: {font_size}") for page_num, page in enumerate(reader.pages): # Get the actual page dimensions media_box = page.mediabox actual_width = float(media_box.width) actual_height = float(media_box.height) # Create overlay packet = io.BytesIO() c = canvas.Canvas(packet, pagesize=(actual_width, actual_height)) # Only apply overlay if this page has Haroon (pages 2-50, index 1-49) # Page 1 (index 0) has no Haroon text if page_num > 0: # White rectangle to cover "Haroon" c.setFillColor(white) c.setStrokeColor(white) c.rect(cover_x0, cover_y0, cover_x1 - cover_x0, cover_y1 - cover_y0, fill=1, stroke=0) # Draw "Zakria Marwat" in black at same position c.setFillColorRGB(0, 0, 0) c.setFont("Helvetica", font_size) c.drawString(cover_x0 + 1, pdf_y_bottom_text, "Zakria Marwat") c.save() packet.seek(0) # Merge overlay onto page from pypdf import PdfReader as PR overlay_reader = PR(packet) overlay_page = overlay_reader.pages[0] page.merge_page(overlay_page) writer.add_page(page) with open(output_path, 'wb') as f: writer.write(f) print(f"\nDone! Saved to: {output_path}") EOF
python3 << 'EOF' import io from pypdf import PdfReader, PdfWriter from reportlab.pdfgen import canvas from reportlab.lib.colors import white pdf_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_260721_185719.pdf' output_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_ZakriaMarwat.pdf' reader = PdfReader(pdf_path) writer = PdfWriter() page_height = 842.88 # pdfplumber coordinates (top-down) pl_x0 = 300.8115 pl_bottom = 823.4304 pl_top = 816.6804 text_height = pl_bottom - pl_top # ~6.75 # Convert to reportlab PDF coords (bottom-up) pdf_y_bottom_text = page_height - pl_bottom # ~19.45 pdf_y_top_text = page_height - pl_top # ~26.20 cover_x0 = pl_x0 - 1 cover_x1 = 430 # wide enough for "Zakria Marwat" cover_y0 = pdf_y_bottom_text - 1 cover_y1 = pdf_y_top_text + 1 font_size = text_height # ~6.75 for page_num, page in enumerate(reader.pages): actual_width = float(page.mediabox.width) actual_height = float(page.mediabox.height) if page_num > 0: # Build overlay PDF in memory packet = io.BytesIO() c = canvas.Canvas(packet, pagesize=(actual_width, actual_height)) # White rectangle over "Haroon" c.setFillColor(white) c.setStrokeColor(white) c.rect(cover_x0, cover_y0, cover_x1 - cover_x0, cover_y1 - cover_y0, fill=1, stroke=0) # Draw replacement text c.setFillColorRGB(0, 0, 0) c.setFont("Helvetica", font_size) c.drawString(cover_x0 + 1, pdf_y_bottom_text, "Zakria Marwat") c.save() packet.seek(0) # Read overlay and merge overlay_reader = PdfReader(packet) overlay_page = overlay_reader.pages[0] page.merge_page(overlay_page) writer.add_page(page) with open(output_path, 'wb') as f: writer.write(f) print(f"Done! Saved to: {output_path}") print(f"Total pages processed: {len(reader.pages)}") EOF
python3 -c " import pdfplumber output_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_ZakriaMarwat.pdf' with pdfplumber.open(output_path) as pdf: print(f'Total pages: {len(pdf.pages)}') for i in [1, 2, 10, 25, 49]: # check pages 2,3,11,26,50 page = pdf.pages[i] words = page.extract_words() bottom_words = [w for w in words if w['top'] > 810] print(f'Page {i+1} bottom text: {[w[\"text\"] for w in bottom_words]}') haroon = [w for w in words if 'Haroon' in w['text']] zakria = [w for w in words if 'Zakria' in w['text'] or 'Marwat' in w['text']] print(f' Haroon found: {len(haroon)}, Zakria Marwat found: {len(zakria)}') "
python3 << 'EOF' import io from pypdf import PdfReader, PdfWriter from reportlab.pdfgen import canvas from reportlab.lib.colors import white pdf_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_260721_185719.pdf' output_path = '/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_ZakriaMarwat.pdf' reader = PdfReader(pdf_path) writer = PdfWriter() page_height = 842.88 # pdfplumber coordinates (top-down from page top) pl_x0_haroon = 300.8115 # start of "Haroon" pl_x1_haroon = 322.9501 # end of "Haroon" pl_top = 816.6804 pl_bottom = 823.4304 text_height = pl_bottom - pl_top # ~6.75 # Convert to reportlab PDF coords (bottom-up) pdf_y_bottom = page_height - pl_bottom # ~19.45 pdf_y_top = page_height - pl_top # ~26.20 # Cover box: generously cover from start of "Haroon" to far right cover_pad = 2 cover_x0 = pl_x0_haroon - cover_pad cover_y0 = pdf_y_bottom - cover_pad cover_w = 120 # wide enough to cover Haroon + room for Zakria Marwat cover_h = (pdf_y_top - pdf_y_bottom) + cover_pad * 2 font_size = text_height # ~6.75 for page_num, page in enumerate(reader.pages): actual_width = float(page.mediabox.width) actual_height = float(page.mediabox.height) if page_num > 0: packet = io.BytesIO() c = canvas.Canvas(packet, pagesize=(actual_width, actual_height)) # Solid white rectangle to cover "Haroon" c.setFillColor(white) c.setStrokeColor(white) c.rect(cover_x0, cover_y0, cover_w, cover_h, fill=1, stroke=0) # Draw "Zakria Marwat" starting at same x as "Haroon" was c.setFillColorRGB(0, 0, 0) c.setFont("Helvetica", font_size) c.drawString(pl_x0_haroon, pdf_y_bottom, "Zakria Marwat") c.save() packet.seek(0) overlay_reader = PdfReader(packet) page.merge_page(overlay_reader.pages[0]) writer.add_page(page) with open(output_path, 'wb') as f: writer.write(f) print(f"Done! Output: {output_path}") # Verify import pdfplumber with pdfplumber.open(output_path) as pdf: for i in [1, 10, 49]: page = pdf.pages[i] words = page.extract_words() bottom = [w['text'] for w in words if w['top'] > 810] haroon = [w for w in words if 'Haroon' in w['text']] print(f"Page {i+1}: bottom={bottom}, Haroon={len(haroon)}") EOF
python3 -c " # Check if pdf2image or fitz (PyMuPDF) is available for rendering try: import fitz print('PyMuPDF (fitz) available:', fitz.__version__) except ImportError: print('PyMuPDF not available') try: from pdf2image import convert_from_path print('pdf2image available') except ImportError: print('pdf2image not available') "
python3 -c " from pdf2image import convert_from_path # Render page 2 (index 1) bottom area pages = convert_from_path('/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/Block_N_Surgery_ZakriaMarwat.pdf', dpi=150, first_page=2, last_page=2) page = pages[0] # Crop bottom strip w, h = page.size bottom_strip = page.crop((0, h-80, w, h)) bottom_strip.save('/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/bottom_check.png') print(f'Saved bottom strip: {w}x80 pixels') "
python3 -c " # Check the pixel values around the 'Haroon' area to verify it's white-covered from PIL import Image img = Image.open('/tmp/workspace/attachments/aa237a04-95ef-47db-b8c2-022e9146f278/bottom_check.png') import numpy as np arr = np.array(img) # The strip is 80px tall; at 150dpi, page is 1242x1754 pixels # Bottom 80px. The text should be ~5-10px from bottom # Let's check pixel colors in the middle-right area where Haroon was # At 150dpi: x=300.81pts * (150/72) = ~626px x_haroon = int(300.81 * 150/72) x_zakria = int(300.81 * 150/72) print(f'x_haroon pixel position: ~{x_haroon}') # Sample some pixels around that area in the strip sample = arr[20:60, x_haroon-10:x_haroon+100] # Check if it's mostly white white_pixels = np.sum(sample > 200) total_pixels = sample.size print(f'Pixels >200 (white): {white_pixels}/{total_pixels} = {white_pixels/total_pixels:.1%}') # Also check for dark pixels (text) dark_pixels = np.sum(np.mean(sample, axis=2) < 100) print(f'Dark pixels (text): {dark_pixels}') # save a larger portion for visual inspection print(f'Strip size: {img.size}') "
Block N Surgery ZakriaMarwat
PDF Document · PDF