We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Need to find/replace text in PDF without altering layout

Thread ID:





131405 Jul 7,2017 02:31 PM UTC Jul 10,2017 09:55 AM UTC ASP.NET MVC 1
Tags: PDF
Philip Tenn
Asked On July 7, 2017 02:31 PM UTC


I am trying to find and replace text in a PDF.  However, when I do so, my PDF format changes completely.  Here is my code:

                   PdfLoadedDocument loadedDocument = new PdfLoadedDocument(GetStreamFromUrl(inputFile));
            logger.Info($"Successfully got PDF Loaded Document from {inputFile}.");

            PdfLoadedPageCollection loadedPages = loadedDocument.Pages;
            PdfDocument newPdfDocument = new PdfDocument();
            foreach (PdfPageBase page in loadedPages)
                string extractedText = page.ExtractText();
                foreach (var item in bindVarDictionary)
                    extractedText = extractedText.Replace(item.Key, item.Value);
                PdfPage newPage = newPdfDocument.Pages.Add();

                //Create PDF graphics for the page
                PdfGraphics graphics = newPage.Graphics;

                //Set the standard font.
                PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20);

                //Draw the text.
                graphics.DrawString(extractedText, font, PdfBrushes.Black, new PointF(0, 0));

Does anyone know how I can do a simple find/replace of text in a PDF without totally changing my formatting?



Surya Kumar [Syncfusion]
Replied On July 10, 2017 09:55 AM UTC

Hi Philip, 
Thank you for using Syncfusion products. 
At present, we do not have support for performing find and replace text in a PDF document and we have logged feature request for “Need to add support for performing find and replace text in existing PDF document ” in our feature management system. We will let you know once this feature is implemented. 
Surya Kumar 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon