Replace text not working

Hi,

I try to replace some tokens in an existing pdf, but the first token I would like to replace is unchanged, and only the first occurrence of the other tokens is replaced.
I use the following code to do the stuff, and the source file is in attachment:
InputStream in = getClass().getResourceAsStream("/SISMAG1G603_20141230184450_DEPLPA.pdf");
License license = new License();
license.setLicense(getClass().getResourceAsStream("/Aspose.Pdf.lic"));
Properties tokens = new Properties();
tokens.put("A1B1C1D1E1F1G1H1I1J1K1L1M1N1O1P1Q1R1S1T1U1V1W1X1Y1Z1INTITULE014490", "My document title");
tokens.put("ABCDEFGHIJKLMNADR01B0000001058135AA", "Dummy_1");
tokens.put("ABCDEFGHIJKLMNADR02B0000001058135AA", "Dummy_2");
tokens.put("ABCDEFGHIJKLMNADR03B0000001058135AA", "Dummy_3");
tokens.put("ABCDEFGHIJKLMNADR04B0000001058135AA", "Dummy_4");
tokens.put("ABCDEFGHIJKLMNADR05B0000001058135AA", "Dummy_5");
PdfContentEditor editor = new PdfContentEditor();
editor.bindPdf(in);
editor.getReplaceTextStrategy().setReplaceScope(ReplaceTextStrategy.Scope.REPLACE_ALL);
editor.getTextReplaceOptions().setReplaceScope(TextReplaceOptions.Scope.REPLACE_ALL);
for (Object key : tokens.keySet()) {
String keyStr = (String) key;
String val = tokens.getProperty(keyStr);
editor.replaceText(keyStr, val);
}
editor.save("result.pdf");

Thanks for your help,
Wilfried

Hi Wilfried,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for Java 9.7.0 in Eclipse Juno project running over Windows 7 (x64) and I am unable to notice any issue. The text is properly being replaced in PDF document. For your reference, I have also attached the resultant file generated over my end.

Thanks for your help. An update to Aspose 9.7.0 solves my issues.

Hi Wilfried,


Thanks for your feedback. It is good to know that you have manged to resolved the issue.

Please keep using our API and feel free to ask any question or concerns, we will be more than happy to extend our support.

Best Regards,

Hi,


The migration to version 9.7.0 solve the replacement issue, but I noticed something odd: after replacement, text is no more aligned on left.
In attachment, source.pdf is the pdf before replacement, and result_facade.pdf is the result after replacement.
Test are done on Windows XP, with Eclipse Luna and JDK 1.6.

Best Regards,
Wilfried

wvandenberghe: Hi,

The migration to version 9.7.0 solved the replacement issue, but I noticed something odd: after replacement, the text is no longer aligned to the left.

In attachment, source.pdf is the pdf before replacement, and result_facade.pdf is the result after replacement.

Tests are done on Windows XP, with Eclipse Luna and JDK 1.6.

Hi Wilfried,

Thanks for sharing the details.

I have tested the scenario and I am able to reproduce the same problem. For the sake of correction, I have logged it in our issue tracking system as PDFNEWJAVA-34660. We will investigate this issue in detail and will keep you updated on the status of a correction.

We apologize for your inconvenience.

The issues you have found earlier (filed as PDFNEWJAVA-34660) have been fixed in Aspose.Pdf for Java 16.12.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.