Aspose.OCR return searchable pdf

Hello,

All of the examples you provided showing how to read files from local file storage and save them to local file storage.

How can I achieve that if the user attaches the scanned pdf file, OCR that file (make searchable pdf) and return the result (searchable pdf) back to the user?

This is kind of the idea

[HttpPost]
public IActionResult SearchablePdf(IFormFile file)
{
var fileStream = file.OpenReadStream();
var memoryStream = new MemoryStream();
fileStream.CopyTo(memoryStream);
var ocr = new AsposeOcr();
var pdfResult = ocr.RecognizePdf() // is this method doesnt get any kind of stream?
var imageResult = ocr.RecognizeImage(memoryStream, new RecognitionSettings() { Language = Language.None});

imageResult.Save(“test.pdf”, SaveFormat.Pdf); //in here how can i return searchable pdf back to user instead of saving to local

}

@emrebiber

The following code snippet recognizes a scanned PDF document and saves the result in PDF format:

Aspose.OCR.DocumentRecognitionSettings rs = new Aspose.OCR.DocumentRecognitionSettings();
rs.PagesNumber = 0;
rs.Language = Aspose.OCR.Language.Deu;
rs.LinesFiltration = true;

Aspose.OCR.AsposeOcr api = new Aspose.OCR.AsposeOcr();
List<Aspose.OCR.RecognitionResult> res1 = api.RecognizePdf(sourceFilePath, rs);
Aspose.OCR.AsposeOcr.SaveMultipageDocument(ocredPdfFilePath, Aspose.OCR.SaveFormat.Pdf, res1);

Do you mean you want to save the result in memory stream instead of file path so that it can be downloaded by the user?

Hello Ali,

Thanks for your quick response.
What I mean is, our customer wants to upload a pdf or image to one of our API endpoints (which takes an IFormFile as an input parameter) and as result, we would like to return a searchable pdf.

Correct me if I’m wrong but the snippet you sent is saving the result to a local pc. We would like to have everything in the memory stream (without reading or saving any kind of local storage).

I appreciate your help :slight_smile:

@emrebiber

You are right. A feature request as OCRNET-487 has been logged in our issue management system to implement memory stream support while loading and saving OCR results. The ticket has been associated with this thread and you will receive a notification as soon as the ticket is resolved. Please spare us some time.