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.
Unfortunately, activation email could not send to your email. Please try again.

Need to find/replace text in PDF without altering layout

Thread ID:

Created:

Updated:

Platform:

Replies:

131405 Jul 7,2017 10:31 AM Jul 10,2017 05:55 AM ASP.NET MVC 1
loading
Tags: PDF
Philip Tenn
Asked On July 7, 2017 10:31 AM

All,

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?

Thanks,

Philip

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

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. 
 
Regards,
Surya Kumar 


CONFIRMATION

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.

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.

;