Replace text in PDF

Hi,

you can go to the page (<A href="</A> )</P> <P>to download the new dll to test. this problem has been solved in the new fix version.</P> <P>but until now, the function of replacing text is not perfect, for some special document, it may exist some problems. we will try best to improve this function.</P>

Hello,

I am sorry to say but the replaceText method of this API is a complete failure. I wrote the same syntax as you in version 2.0 as well as 2.1 which is the latest release with all hot fixes. i.e.

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

But now i am getting the execption below :

java.lang.NullPointerException

at com.aspose.pdf.kit.f4.a(Unknown Source)

at com.aspose.pdf.kit.PdfContentEditor.replaceText(Unknown Source)

at Test.main(Test.java:56)

Thanks & Regards

Anand

Hi Anand,

Can you please provide your PDF file and let us check it?

Hello I have attached x.pdf. please try to replace

Gramm-Leach-Bliley in this document with any word. Try to change Edward L. Stull with any other word. observe that it will not work. also see that the justification of the document gets distorted in the output pdf file.

Thanks & Regards

Anand

Hi,

I am able to reproduce the error, and it has been logged as PdfKitJava-6004 in our issue tracking system. We will try to resolve it ASAP.

Thanks,

I did find with PDF files that wouldn't replace the text I could open it save it and then open it again at which point the replace function would work. Not sure what pdfkit does when it writes out the file but it seems to like it when it reads it in again.

pdfContent.BindPdf("c:\\temp\\junk.pdf");

pdfContent.Save("c:\\temp\\junk2.pdf");

pdfContent.BindPdf("c:\\temp\\junk2.pdf");

pdfContent.ReplaceText("Sept", "Oct");

pdfContent.Save("c:\\temp\\Replaceddate.pdf");

Hope they find a solution to this.

Hello mark,

Thanks for considering Aspose.

Please share the Pdf file that you are using, so that we can test the issue at our end.

Hi Mark,

You are using a .NET edition of Aspose.Pdf.Kit, so the workaround may not work for Anand’s project which uses a JAVA Kit. But your solution is very special and may be useful to us. Could you pease share the source Pdf file here to help us to resolve the issue?

Thank you,

I have a three for one special. The first file junk.pdf is the starting pdf. Junk2 is the file after aspose saves it out and the third file is after I have replaced some text in junk2. I will say that it might have something to do with color in the pdf. I will be getting my license soon so I will try it with the full version shortly.

Hi Anand,

The issue of PdfKitJava-6004 has resolved, and we also added a new method of PdfContentEditor.replaceText(String, int, String) for replacing words in one appointed page. Please download the attached Beta version(2.1.0.4) of aspose.pdf.kit.jar and try it.

Note that replacing words like Gramm and Edward with any words could be supported, but words such as “Gramm-Leach-Bliley” and “Edward L. Stull” may not be successfully replaced with other words by this Beta version. We will try to enhance the feature to support the latter form of words in our next version.

Thanks,

This post is over 2 years old and I still cannot get the code to work. It is creating the new document but the text is not replaced. If I can get the evaluation to work I will buy the product, but not unless it does. Please advise…

using Aspose.Pdf.Kit;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
PdfContentEditor pdfContent = new PdfContentEditor();
try
{
pdfContent.BindPdf(Server.MapPath(“template.pdf”));
pdfContent.ReplaceText(“the”, “zzzzzzzzzzzzzzzzz”);
pdfContent.Save(Server.MapPath(“new.pdf”));
}
catch (Exception ex)
{
Response.Write(ex);
}
}
}

Hi,

Thank you very much for considering Aspose.

Can you please share the PDF file with us? We'll test the issue at our end and will update you accordingly.

We're sorry for the inconvenience.

Regards,

I got the replace text working, but it’s putting a tab in the middle of the words. attached is the pdf file I am using

For example, I replace {DATE} with the date, but the PDF displayed it like this 7-1-2 009

PdfContentEditor pdfContent = new PdfContentEditor();
try
{
pdfContent.bindPdf(“old.pdf”);
pdfContent.replaceText("{DATE}", “7-1-2009”);

pdfContent.save(“new.pdf”);
}
catch (Exception ex)
{
ex.printStackTrace();
}

Hi George,

I have reproduced the issue and logged it as PDFKITJAVA-9536 in our issue tracking system. Our team will be looking into the matter and you'll be updated via this forum as the issue is resolved.

We're sorry for the inconvenience.

Regards,

The issues you have found earlier (filed as 9536) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

I'm evaluating Aspose.PDF and trying to replace some text. But I get an Exception: "At most 4 elements (for any collection) can be viewed in evaluation mode."

How am I supposed to evaluate your component if I can't use basic methods? Isn't timebomb and watermark enough?

Hi Hinek,

Please get a temporary license for 30 days to evaluate the component without any limitations.

I hope this helps. If you find any further questions, please do let us know.
Regards,

thanks, got it now :slight_smile: