We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Replace text in PDF

Hello,

I’ve seen a recent post about replacing all the appearences of a string in a PDF with another string using PdfContentEditor.replaceText(). I have the same problem: text doesn’t get replaced and the quotes are replaced by question marks. Has this problem been solved?

My code is this:

PdfContentEditor pdfContent = new PdfContentEditor();
try{
pdfContent.bindPdf(“c:\Curves.pdf”);
pdfContent.replaceText(“curve”, “ZZZZZZZZ”);
pdfContent.save(“c:\ReplacedCurves.pdf”);
}catch(Exception ex){
ex.printStackTrace();
}

I would like to add that this feature is very important, I just haven’t found any APIs on the web that do PDF text replacing properly.

Thank you,

Peergynt

Can you please also provide the Pdf and let us check it?

I have attached a very simple pdf file for which text replacing just doesn’t work.

I’m trying to replace the string ‘curve’ with another string.

Peergynt

Hi,

I have checked the document you send and found some other problem. I will discuss this with the developers and let you know as soon as solution is found.

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

This bug has been fixed in hotfix 2.5.2.

I am running Pdf.Kit in evaluation mode and the text isn’t being replaced. Was this fix applied for those running in eval mode? My company is considering purchasing this and text replacement is one of our core needs so I need to see this work before purchasing. Thanks.

Hi,

Thank you for considering Aspose.

Can you please send us your Pdf file and let us test this issue.

Thanks.

I have attached my sample file, created in LiveCycle Designer 8.0. I have also tried using replacement in the Aspose.Pdf.Kit.pdf file located in my "C:\Program Files\Aspose\Aspose.Pdf.Kit\Demos\Resources" directory.

The attached sample file also includes some form fields. I can populate the logo image and the textbox, but inline fields don't show up in the fields collection recognized by the pdf kit library. I also need to find a way to handle this.

Thanks.

Hi,

I have checked and able to reproduce the error. I will discuss this with the developers and we will let you know as soon as solution is found.

Thanks.

Thanks for looking into this. The project I am working on has a very tight deadline, what kind of turn around can be expected on this solution? With this functionality in place, we would definately buy an enterprise license. Thanks.

Hi,

I will ask the developer to give you an ETA soon.

Thank you for your patience.

Hi,

We will fix the null reference bug in next hotfix, which will be available in early next month.

Best Regards.

My company is also considering purchasing your product PDF KIT only if text replacement is working. Does it work perfectly ? Can i see a demo ?

Thanks

Hi,

Thank you for considering Aspose.

As you can see there are still some bugs in this feature but we are working to make it perfect. You can evaluate it first.

Hello,
I also was unable to get the Text Replace function working. Simply, nothing happend after calling the function and saving the file. The output file is actually created but when I open it, the replacement is not applied at all.
Additionaly, another problem start occuring unexpectivly. The problem is that after calling this function and saving the output file, the Adobe (Professional, v 7) is showing an error dialog box when I try to open the outputed file. An error is saying just: “Too few operands”. And there is a blank page in the Adobe.

Could you please do something in order to fix this issues. It is realy important and I’m running out of time for finishing the project I’m working on. And this was really unexpected problem. The company is currently preparing to buy the product mostly because of this functionality, because it is very urgent and its realy unexpected the fact that this function does not work.

Thank You in advance

Can you please attach your pdf document and code and let us check it?

Hello.

Yes sure.

I will attach the file, and the code is as follows:

PdfContentEditor ced = new PdfContentEditor();

ced.BindPdf(@"\the\file\path\test1.pdf");

ced.ReplaceText("<>", "ABC12345");

ced.Save(@"\the\file\path\test1_out.pdf");

Thats all. And also i have tryed to optimised the input pdf for lower versions of pdf formats ,but the problem is still there.

But I noticed that the output pdf get broken only when a replacement is about to be done. I mean, when I enter some matching string that I know it exists in the input PDF and it has to be related , the output file gets broken. otherwise, it gets OK, as a copy of the input file.

Thank You

Hi,

Can you please provide us with the input file as well so that we can more accurately determine the cause of the problem.

Thanks.

Hi,
Yes sure. I somehow missed to provide it.
Here it is.
Thank You

Hi,

I have been able to reproduce this error. I have logged this issue as PDFKITNET-3790 into our issue tracking system. Our developers will try their best to rectify this problem as soon as possible.

Thanks.