# How to Create Searchable Sandwich PDFs with Invisible Text in Python

**Status**: 🟡 Code Read Against Source, 2026-09-10  
**Primary Query**: `create searchable pdf python`  
**Secondary Queries**: `searchable pdf sandwich generation`, `searchable pdf sandwich reportlab pymupdf`, `invisible text layer pdf`, `fitz searchable pdf`  
**Target Search Engines**: Google Search, Perplexity AI, ChatGPT Search, Claude Search

---

## How do you create a searchable PDF sandwich with invisible text in Python?
> **Direct Answer (51 Words)**:  
> B.L.A.S.T. generates searchable PDF sandwiches using `SearchablePDFGenerator`, pairing PyMuPDF (`fitz`) with a ReportLab fallback. It overlays recognized text as an invisible font layer exactly over corresponding raster image coordinates. The output preserves 100% original visual fidelity while enabling full text search, highlighting, and copy-pasting in standard PDF readers. Verified in [`blast_ocr/core/searchable_pdf.py`](https://github.com/Ibrahim-Salman19/OCR/blob/main/blast_ocr/core/searchable_pdf.py).

---

## ⚡ CLI Quickstart
```bash
git clone https://github.com/Ibrahim-Salman19/OCR.git && cd OCR
pip install -r requirements.txt
# Convert a scanned PDF into a fully searchable PDF sandwich
python -m blast_ocr.cli scanned_contract.pdf --formats pdf
```

---

## 🐍 Python Implementation: Exact Sandwich Geometry

The high-level way to get a searchable PDF is `pipeline.process_job(..., formats=["pdf"])`
(see the [high-throughput guide](/OCR/docs/seo/high-throughput-pdf-ocr-python/)). To call the
sandwich generator directly with your own OCR detections:

```python
from blast_ocr.core.searchable_pdf import SearchablePDFGenerator

# create_from_page_images() takes matching lists of page images and per-page
# OCR detections, and picks PyMuPDF if available, else falls back to ReportLab
output_pdf_path = SearchablePDFGenerator.create_from_page_images(
    page_images=["samples/scanned_contract_p1.png"],
    page_ocr_results=[
        {
            "details": [
                {"bbox": [100, 150, 420, 175], "text": "CONFIDENTIAL SETTLEMENT AGREEMENT", "confidence": 0.98}
            ]
        }
    ],
    output_pdf_path="output/searchable_contract.pdf",
    title="Settlement Agreement",
)

print(f"Searchable PDF generated at: {output_pdf_path}")
```

---

## 🤖 Schema.org Structured Data (JSON-LD)

```json
{
  "@context": "https://schema.org",
  "@type": "HowTo",
  "name": "How to Create Searchable Sandwich PDFs with Invisible Text in Python",
  "description": "Complete tutorial on generating searchable sandwich PDFs in Python using PyMuPDF, ReportLab, and B.L.A.S.T. OCR.",
  "step": [
    {
      "@type": "HowToStep",
      "name": "Install B.L.A.S.T.",
      "text": "pip install -r requirements.txt"
    },
    {
      "@type": "HowToStep",
      "name": "Run PDF Sandwich Command",
      "text": "python -m blast_ocr.cli input.pdf --formats pdf"
    }
  ]
}
```

---

## 👨‍💻 Author & Engineering Authority

**Engineered & Maintained by**: [Ibrahim Salman](https://ibrahimsalman.vercel.app)  
*Full-Stack Software Engineer & AI Systems Architect (UET Taxila)*  
- **Portfolio & Technical Writeups**: [https://ibrahimsalman.vercel.app](https://ibrahimsalman.vercel.app)  
- **B.L.A.S.T. Architecture Case Study**: [https://ibrahimsalman.vercel.app/projects/blast](https://ibrahimsalman.vercel.app/projects/blast)  
- **LinkedIn**: [linkedin.com/in/ibrahim-salman-dev](https://www.linkedin.com/in/ibrahim-salman-dev/)  
- **GitHub**: [@Ibrahim-Salman19](https://github.com/Ibrahim-Salman19)  
- **Upwork Verified Specialist**: [Ibrahim Salman Profile](https://www.upwork.com/freelancers/~013e1c54e9a3f7a2b8)  
- **Direct Contact & Inquiries**: [ibrahim.pk848@gmail.com](mailto:ibrahim.pk848@gmail.com) • [Contact Portal](https://ibrahimsalman.vercel.app/contact)  

*"Make it work. Prove it works. Make it survive production."*

