Converting an image to a searchable PDF in memory
Images often contain text that users can’t search or copy. Converting those images to searchable PDFs adds an OCR text layer while preserving the original visual content.
This guide shows how to run the full workflow in memory:
- Load an image
- Convert it to PDF in a
MemoryStream - Run OCR on the in-memory PDF
- Save a searchable PDF
Project setup
Install:
- The core Nutrient Native SDK package
GdPicture.Resourcesfor OCR language and recognition resources
Prepare the project
Register the SDK license before running conversion or OCR operations. For setup details, refer to the getting started with .NET SDK guide.
using GdPicture14;
LicenseManager licence = new LicenseManager();licence.RegisterKEY("");Set up document processors
Use these two SDK components:
GdPictureDocumentConverterfor image-to-PDF conversionGdPicturePDFfor OCR and PDF output
using GdPicturePDF pdf = new GdPicturePDF();using GdPictureDocumentConverter converter = new GdPictureDocumentConverter();Process the image in memory
Load the image and write the intermediate PDF to a memory stream:
converter.LoadFromFile(@"input.png");using MemoryStream stream = new MemoryStream();converter.SaveAsPDF(stream);Apply OCR and save output
Load the in-memory PDF, run OCR, and save the searchable result:
pdf.LoadFromStream(stream);pdf.OcrPages("*", 0, "eng", "", "", 200);pdf.SaveToFile(@"output_with_ocr.pdf");OcrPages parameters:
"*"— Process all pages0— Default OCR mode"eng"— English OCR language"",""— No allowlist or denylist200— Processing DPI
Handle errors
LoadFromFile, SaveAsPDF, LoadFromStream, and OcrPages return GdPictureStatus values. Use these values in your error handling flow. For details, refer to the handling errors with .NET SDK guide.
Conclusion
This workflow converts an image to a searchable PDF using in-memory processing and OCR.