• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

PdfBox - how to Replace String with double value in pdf

 
Krishna Rajendran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My requirement:

Your loan amount @loanamount is approved.

I wanted to replace @loanamount to 5,00,000. If i try with pdfbox api,i am not able to replace. i am getting empty space in pdf.
If i use same api and if try to replace @loanamount to abcd. now its replacing

replaceFirst("@loanamount","5,00,00"); - not able to replace. getting empty content in pdf
replaceFirst("@loanamount","abcd"); - able to replace.
Could anyone help me out?

Can anyone of you suggest me anyother open source api to replace string in pdf?

Thanks in Advance...:)
 
Paul Clapham
Sheriff
Posts: 21116
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're using a string in both cases, so it's quite likely that your problem diagnosis is incorrect.

And you haven't given us enough information to help out. In fact you've given us nothing but two bare lines of code. A full example of code which does and doesn't work would be much more useful.
 
Krishna Rajendran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your quick response Paul.

Please see the below code.


sample content in pdf:
Dear ABC,

Your loan amount @loanamount is approved.

Regards,
DEF

Output:Your loan amount is approved.
I m getting empty spaces instead of @loanamount
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what op.getOperation() = "TJ" and op.getOperation() = "Tj" mean, but since they're apparently different things I'm not too surprised that the result would be different.
 
Krishna Rajendran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your response. Ulf

//Tj and TJ are the two operators that display strings in a PDF

if (op.getOperation().equals("Tj"))
{
// Tj takes one operator and that is the string
// to display so lets update that operator
COSString previous = (COSString) tokens.get(j - 1);

System.out.println("COSString::"+previous);

String string = previous.getString();

string = string.replace("@loanamount", "5,00,000");

//Word you want to change. Currently this code changes word "Solr" to "Solr123"
previous.reset();



previous.append(string.getBytes());

}

When i run this code, only Tj loop (if loop) is getting called.

TJ loop is not getting called. so we no need to worry about TJ right now.
 
Krishna Rajendran
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone help me out ?

Please suggest me java open source api to replace caption or content in existing pdf.

Thanks in advance.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It would be very useful to have an SSCCE and a PDF to go with it. As it is, the problem is a bit abstract.

Fundamentally, PDFs are not meant for this kind of editing; I think it's quite possible that you won't find a free solution for this; I'm surprised you even got this to work (sort of).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic