Cómo guardar resultados como un PDF buscable en C#

How to Save Results as a Searchable PDF

This article was translated from English: Does it need improvement?
Translated
View the article in English

A searchable PDF, often referred to as an OCR (Optical Character Recognition) PDF, is a type of PDF document that contains both scanned images and machine-readable text. These PDFs are created by performing OCR on scanned paper documents or images, recognizing the text in the images, and converting it into selectable and searchable text.

IronOCR provides a solution for performing optical character recognition on documents and exporting the results as searchable PDFs. It supports exporting searchable PDFs as files, bytes, and streams.

Quickstart: Export Searchable PDF in One Line

Set RenderSearchablePdf = true, run Read(...) on your input, and invoke SaveAsSearchablePdf(...) — that’s all it takes to generate a fully searchable PDF with IronOCR.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronOCR with NuGet Package Manager

    PM > Install-Package IronOcr

  2. Copy and run this code snippet.

    new IronOcr.IronTesseract { Configuration = { RenderSearchablePdf = true } } .Read(new IronOcr.OcrImageInput("file.jpg")).SaveAsSearchablePdf("searchable.pdf");
  3. Deploy to test on your live environment

    Start using IronOCR in your project today with a free trial
    arrow pointer


Export as Searchable PDF Example

Here's how you can export the result as a searchable PDF using IronOCR. You must first set the Configuration.RenderSearchablePdf property to true. After obtaining the OCR result object from the Read method, use the SaveAsSearchablePdf method by specifying the output file path. The code below demonstrates using a sample TIFF file.

:path=/static-assets/ocr/content-code-examples/how-to/searchable-pdf-searchable-pdf.cs
using IronOcr;

// Instantiate IronTesseract
IronTesseract ocrTesseract = new IronTesseract();

// Enable render as searchable PDF
ocrTesseract.Configuration.RenderSearchablePdf = true;

// Add image
using var imageInput = new OcrImageInput("Potter.tiff");
// Perform OCR
OcrResult ocrResult = ocrTesseract.Read(imageInput);

// Export as searchable PDF
ocrResult.SaveAsSearchablePdf("searchablePdf.pdf");
Imports IronOcr

' Instantiate IronTesseract
Private ocrTesseract As New IronTesseract()

' Enable render as searchable PDF
ocrTesseract.Configuration.RenderSearchablePdf = True

' Add image
Dim imageInput = New OcrImageInput("Potter.tiff")
' Perform OCR
Dim ocrResult As OcrResult = ocrTesseract.Read(imageInput)

' Export as searchable PDF
ocrResult.SaveAsSearchablePdf("searchablePdf.pdf")
$vbLabelText   $csharpLabel

Below is a screenshot of the sample TIFF and an embedded searchable PDF. Attempt to select the text in the PDF to confirm its searchability. The ability to select also means the text can be searched in a PDF viewer.

Por favor notaIronOCR uses a particular font to overlay text on the image file, which might result in some discrepancies in text size.

TIFF file

Export as Searchable PDF with filters applied

The SaveAsSearchablePdf also accepts a boolean flag as a second parameter that allows you to apply filters to a searchable PDF or not, giving developers the flexibility to choose.

Below is an example of applying the grayscale and then saving the PDF with a filter by putting true in the second parameter of SaveAsSearchablePdf.

:path=/static-assets/ocr/content-code-examples/how-to/image-quality-correction-searchable-pdf.cs
using IronOcr;

var ocr = new IronTesseract();
var ocrInput = new OcrInput();

// Load a PDF file
ocrInput.LoadPdf("invoice.pdf");

// Apply gray scale filter
ocrInput.ToGrayScale();
OcrResult result = ocr.Read(ocrInput);

// Save the result as a searchable PDF with filters applied
result.SaveAsSearchablePdf("outputGrayscale.pdf", true);
IRON VB CONVERTER ERROR developers@ironsoftware.com
$vbLabelText   $csharpLabel

Searchable PDF as Byte and Stream

The output of the searchable PDF can also be handled as bytes or streams using SaveAsSearchablePdfBytes and SaveAsSearchablePdfStream methods, respectively. The code example below shows how to utilize these methods.

:path=/static-assets/ocr/content-code-examples/how-to/searchable-pdf-searchable-pdf-byte-stream.cs
// Export searchable PDF byte
byte[] pdfByte = ocrResult.SaveAsSearchablePdfBytes();

// Export searchable PDF stream
Stream pdfStream = ocrResult.SaveAsSearchablePdfStream();
' Export searchable PDF byte
Dim pdfByte() As Byte = ocrResult.SaveAsSearchablePdfBytes()

' Export searchable PDF stream
Dim pdfStream As Stream = ocrResult.SaveAsSearchablePdfStream()
$vbLabelText   $csharpLabel

Preguntas Frecuentes

¿Qué es un PDF buscable?

Un PDF buscable es un documento que combina imágenes escaneadas con texto legible por máquina, creado al realizar OCR en documentos o imágenes escaneadas, permitiendo a los usuarios seleccionar y buscar texto dentro del documento.

¿Cómo puedo convertir documentos escaneados en PDFs buscables en C#?

Para convertir documentos escaneados en PDFs buscables en C#, use IronOCR configurando la propiedad Configuration.RenderSearchablePdf en verdadero, ejecutando OCR con el método Read y luego guardando el resultado usando SaveAsSearchablePdf.

¿Puedo exportar PDFs buscables como bytes o flujos?

Sí, IronOCR permite exportar PDFs buscables como bytes usando SaveAsSearchablePdfBytes y como flujos usando SaveAsSearchablePdfStream.

¿Cómo manejo diferentes formatos de archivo para el procesamiento OCR?

IronOCR admite varios formatos de archivo como TIFF para el procesamiento OCR, lo que permite la creación de PDFs buscables a partir de estos formatos.

¿Es posible seleccionar y buscar texto en un PDF buscable creado con tecnología OCR?

Sí, los PDFs buscables creados con la tecnología IronOCR permiten la selección de texto y la capacidad de búsqueda dentro de un visor de PDF.

¿Qué pasos están involucrados en la creación de un PDF buscable usando OCR?

Los pasos incluyen descargar la biblioteca IronOCR C#, preparar documentos para OCR, establecer la propiedad RenderSearchablePdf en verdadero y usar el método SaveAsSearchablePdf para guardar el archivo.

¿Cómo puedo asegurarme de que el texto en mi PDF sea buscable?

Asegure que el texto sea buscable usando IronOCR para realizar OCR en sus imágenes y configure la propiedad RenderSearchablePdf en verdadero antes de guardar el documento.

¿IronOCR utiliza una fuente específica para el texto superpuesto en los PDFs buscables?

Sí, IronOCR utiliza una fuente específica para el texto superpuesto en los archivos de imagen, lo que puede resultar en algunas discrepancias en el tamaño del texto.

Chaknith Bin
Ingeniero de Software
Chaknith trabaja en IronXL e IronBarcode. Tiene un profundo conocimiento en C# y .NET, ayudando a mejorar el software y apoyar a los clientes. Sus conocimientos derivados de las interacciones con los usuarios contribuyen a mejores productos, documentación y experiencia en general.
Revisado por
Jeff Fritz
Jeffrey T. Fritz
Gerente Principal de Programas - Equipo de la Comunidad .NET
Jeff también es Gerente Principal de Programas para los equipos de .NET y Visual Studio. Es el productor ejecutivo de la serie de conferencias virtuales .NET Conf y anfitrión de 'Fritz and Friends', una transmisión en vivo para desarrolladores que se emite dos veces a la semana donde habla sobre tecnología y escribe código junto con la audiencia. Jeff escribe talleres, presentaciones, y planifica contenido para los eventos de desarrolladores más importantes de Microsoft, incluyendo Microsoft Build, Microsoft Ignite, .NET Conf y la Cumbre de Microsoft MVP.
¿Listo para empezar?
Nuget Descargas 5,044,537 | Versión: 2025.11 recién lanzado