Highlight word in PDF is not working with our sample file

I am using below code but instead of saving it to Disk , i want to keep the data in memory, and using that data in memory i want to display the pdf in browser. Below code is working fine but i want to keep data in memory rather than saving to disk. What changes can be made to this ?

[Aspose.Pdf.Document document = new Aspose.Pdf.Document(@“C:\TestArea\Destination\SUP000011\ATM-1B4L2KQ0ZE0-0001\OpenAML.pdf”);

        //create TextAbsorber object to find all instances of the input search phrase
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("(?i)" + searchText, new TextSearchOptions(true));


        ////accept the absorber for all the pages

        document.Pages.Accept(textFragmentAbsorber);

        ////get the extracted text fragments
       

        for(int i = 1; i < textFragmentAbsorber.TextFragments.Count + 1; i++)
        {
            textFragmentAbsorber.TextFragments[i].TextState.Font = FontRepository.FindFont("Verdana");
            textFragmentAbsorber.TextFragments[i].TextState.FontSize = 9;
            textFragmentAbsorber.TextFragments[i].TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Blue);
            textFragmentAbsorber.TextFragments[i].TextState.BackgroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Yellow);
        }



        // Save resulting PDF document.
        document.Save(@"C:\TestArea\Destination\SUP000011\ATM-1B4L2KQ0ZE0-0001\Highlightdoc.pdf");
     

        WebClient User = new WebClient();

        byte[] buf = User.DownloadData(@"C:\TestArea\Destination\SUP000011\ATM-1B4L2KQ0ZE0-0001\Highlightdoc.pdf");

        if (buf != null)

        {

            Response.ContentType = "application/pdf";

            Response.AddHeader("content-length", buf.Length.ToString());

            Response.BinaryWrite(buf);

        }](http://)

@swapnilmax2000

You can save document into MemoryStream to keep it into memory and later use same MemoryStream object to load document. The change in the code would be like following:

///// Document generation code is above ////
MemoryStream ms = new MemoryStream();
document.Save(ms);
WebClient User = new WebClient();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", ms.Length.ToString());

In case of any further assistance, please feel free to let us know.

Thanks after doing little modification it works.
Can you please let me know how to find all instances of search text in excel and highlighting it. Currently it searches only first instance and highlight it. Here is my code -

[Workbook workbook = new Workbook(@“C:\TestArea\Destination\SUP000011\ATM-1B4L2KQ0ZE0-0001\TestExcel.xlsx”);
Worksheet worksheet = workbook.Worksheets[0];

        Aspose.Cells.Cells cells = worksheet.Cells;
        //Suppose you need to add a text into the cells.
        //You need to find out if this text is already there in some cells.
        //You may use Find and Search options provided by Aspose.Cells APIs for this purpose.

        string searchText = Session["SearchText"].ToString();

        FindOptions findOptions = new FindOptions();
        findOptions.CaseSensitive = false;
        findOptions.LookInType = LookInType.Values;

        Aspose.Cells.Cell foundCell = cells.Find(searchText, null, findOptions);          
    
       
        if (foundCell != null)
        {

            int row = foundCell.Row;
            string name = foundCell.Name;

            Aspose.Cells.Style style = worksheet.Cells[name].GetStyle();
            style.ForegroundColor = System.Drawing.Color.Yellow;
            style.Pattern = BackgroundType.Solid;
            worksheet.Cells[name].SetStyle(style);
            workbook.Save(@"C:\TestArea\Destination\SUP000011\ATM-1B4L2KQ0ZE0-0001\TestExcel_Final.xlsx");

        }
        else
        {
            
        }

@swapnilmax2000,

Please give a try to the following sample code and provide your feedback.

Workbook wb = new Workbook(path + "book1.xlsx");
string searchText = "Text 1";
Worksheet worksheet = wb.Worksheets[0];
FindOptions options = new FindOptions();
options.CaseSensitive = false;
options.LookInType = LookInType.Values;

Aspose.Cells.Cell nextCell = null;

do
{
    nextCell = worksheet.Cells.Find(searchText, nextCell, options);
    if (nextCell == null)
        break;
    if (nextCell != null)
    {

        int row = nextCell.Row;
        string name = nextCell.Name;

        Aspose.Cells.Style style = worksheet.Cells[name].GetStyle();
        style.ForegroundColor = System.Drawing.Color.Yellow;
        style.Pattern = BackgroundType.Solid;
        worksheet.Cells[name].SetStyle(style);

    }
    else
    {

    }
} while (true);

wb.Save(path + "outputFindCellsWithSpecificText.xlsx");

The issues you have found earlier (filed as SLIDESNET-40600) have been fixed in this update.