Searchable PDF (output=pdf, prebuilt-read): how to avoid duplicate text layer on PDFs that already contain native text?

TRẦN NGỌC UYỂN NHI 20 Reputation points
2026-06-25T09:09:02.31+00:00

We're using Azure Document Intelligence prebuilt-read with output=pdf (API 2024-11-30, 4.0 GA) to generate searchable PDFs from scanned/image-only documents. This works well for pure image PDFs.

Context: Our current plan is to gate generation per page (only OCR pages with no native text) to avoid the duplicate layer. We'd prefer a service-side option if one exists, especially for the mixed-page case.

Problem: When the input PDF (or some of its pages) already contains a native text layer, the returned searchable PDF ends up with two overlapping text layers — the original native text plus Azure's invisible OCR overlay covering the same region. In a viewer this produces duplicate search hits and unreliable/offset text selection, which is a blocker for our use case (we build redaction masks from text selection, so duplicated/misaligned text is not acceptable).

Questions:

  1. Is there any request parameter or option to make output=pdf skip pages (or regions) that already contain a native text layer, so no overlay is added there?
  2. For mixed PDFs (a single page containing both native text and a scanned image that contains text), what is the recommended approach to get one coherent searchable layer without duplicating the native text?
Azure Document Intelligence in Foundry Tools
0 comments No comments

Answer accepted by question author

Jerald Felix 16,420 Reputation points Volunteer Moderator
2026-06-25T15:33:36.31+00:00

Hello TRẦN NGỌC UYỂN NHI,

Greetings! Thanks for raising this question in the Q&A forum.

There is currently no request parameter or service side option for output=pdf that detects existing native text and skips adding an overlay on those pages or regions. The Read model's searchable PDF feature works by running OCR across every page image you submit and embedding an invisible text layer at the detected word locations, it does not inspect the input PDF for an existing text layer first, so any page sent through analyze?output=pdf will always get an overlay regardless of whether it already had selectable text. Your plan to gate generation per page on the client side is the correct approach, since there is no equivalent server side flag to do this for you.

  1. Confirm there is no native text skip option

Since the Analyze operation for output=pdf only accepts the document and output format, there is no parameter such as a region mask, page filter, or a "skip if text exists" flag in the 2024-11-30 GA API surface. This answers your first question, the per-page gating you already planned is the recommended path, not a workaround for a missing feature, it is the actual intended approach for this scenario.

  1. Detect native text per page before deciding routing

Use a PDF library on the client to check whether each page already has an extractable text layer before deciding whether to send that page through Document Intelligence.

import fitz  # PyMuPDF

doc = fitz.open("input.pdf")
pages_needing_ocr = []
for i, page in enumerate(doc):
    text = page.get_text().strip()
    if not text:
        pages_needing_ocr.append(i)

Only the pages in pages_needing_ocr should be sent for OCR processing, exactly as your current plan describes.

  1. For mixed pages, flatten rather than try to merge two layers

For a single page that has both native text and a scanned image region containing text, do not try to combine the original native layer with a new OCR overlay on the same page, since the service has no concept of partial page processing and you would end up reconciling two independent coordinate systems by hand, which is fragile and exactly the kind of misalignment that breaks your redaction workflow. Instead, rasterize that specific page to a flat image, which strips its existing text layer entirely, then submit only that flattened image through analyze?output=pdf.

pix = page.get_pixmap(dpi=300)
pix.save(f"page_{i}_flattened.png")

Send page_{i}_flattened.png through the Read model with output=pdf, then in your final assembled document replace that original mixed page with the new OCR generated page rather than layering anything on top of the original. This gives you one single coherent text layer for that page with no duplication, at the cost of losing the original native text's exact font metadata, which is an acceptable tradeoff since your downstream use case only needs reliable, non overlapping text selection for building redaction masks.

  1. Reassemble the final document

Keep pages that were already fully native and untouched as is, replace pages that were fully image only with the direct output=pdf result for that page, and replace mixed pages with the flattened and reprocessed version from step 3, then merge all pages back into a single PDF using a library such as PyMuPDF or PDFBox.

If this answer helps you kindly accept the answer which will help others who have similar questions.

Best Regards,

Jerald Felix.

Was this answer helpful?

2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.