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. Image for the cookie policy date

Need to find/replace text in PDF without altering layout


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?



1 Reply

SK Surya Kumar Syncfusion Team 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 

Live Chat Icon For mobile
Up arrow icon