Aspose.Pdf.Kit.PdfContentEditor � ReplaceText

Hello,

I’m trying to replace text on a PDF but Aspose.Pdf.Kit.PdfContentEditor.ReplaceText is not working. Following is my code snippet,

Aspose.Pdf.Kit.PdfContentEditor pdfContentEditor = new Aspose.Pdf.Kit.PdfContentEditor();

pdfContentEditor.BindPdf(path);

pdfContentEditor.ReplaceText("", "value");

pdfContentEditor.Save(Path.Combine(Path.GetDirectoryName(path), Path.GetFileNameWithoutExtension(path) + "_merged" + Path.GetExtension(path)));

Attached are the source PDF (Aspose.Pdf.Kit.PdfContentEditor - ReplaceText.PDF) and the PDF resulting from the ReplaceText operation (Aspose.Pdf.Kit.PdfContentEditor - ReplaceText_merged.PDF).

Any idea why this won’t work?

Thanks,

Juno

Dear

Thank you for considering Aspose.

We have tested the pdf file you attached and found the reason why it can not be replaced . For the text in the pdf file is not text format but image format. So, it can not be replaced.

Any more question is welcome.

I made another test converting a Word document to PDF using Aspose.Words and Aspose.Pdf. I tried to replace text on the resulting PDF and it didn’t work. It is Aspose.Pdf saving the text from the Word document to image format?

Following is my code snippet and attached are the original Word document, the converted PDF and the PDF after the ReplaceText operation.

Aspose.Words.Document wordDocument = new Aspose.Words.Document(wordDocumentPath);

string tempFile = Path.GetTempFileName();

wordDocument.Save(tempFile, Aspose.Words.SaveFormat.FormatAsposePdf);

Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();

pdf.BindXML(tempFile, null);

string pdfPath = wordDocumentPath + ".pdf";

pdf.Save(pdfPath);

Aspose.Pdf.Kit.PdfContentEditor pdfContentEditor = new Aspose.Pdf.Kit.PdfContentEditor();

pdfContentEditor.BindPdf(pdfPath);

pdfContentEditor.ReplaceText("", "value");

string replacedPdfPath = Path.Combine(Path.GetDirectoryName(wordDocumentPath), Path.GetFileNameWithoutExtension(wordDocumentPath) + "_merged.pdf");

pdfContentEditor.Save(replacedPdfPath);

By the way, the first line of the PDF was missing after Aspose.Pdf.Kit.PdfContentEditor.Save.

Thanks,

Juno

We will test the files and reply you ASAP.