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

Free Support Forum - aspose.com

Replace does'nt work

Hi support,

for a proof of concept we need the text replacement function.
unfortenately my testcase does’nt work. i using the pdf.kit trial version

This is the sourcecode of my test case:

private void checkSubstFiles(String pdfFileSource, String pdfFileTarget)
throws FileNotFoundException {
if (!new File(pdfFileSource).exists())
throw new FileNotFoundException();

File f = new File(pdfFileTarget);
if (f.exists())
f = null;

public void subst(final String pdfFileSource, final String pdfFileTarget)
throws Exception {

log.info("Check Input PDF: " + pdfFileSource);
checkSubstFiles(pdfFileSource, pdfFileTarget);

int pageNo = numberOfPages(pdfFileSource);

PdfContentEditor editor = new PdfContentEditor();

Runtime rt = Runtime.getRuntime();

long maxMem = rt.maxMemory();

editor.replaceText(“Achtung!”, “Attention!”);

for (int i = 1; i <= pageNo; i++) {
String strPageNo = String.valueOf(i);
log.debug("Mem " + rt.freeMemory() + “/” + maxMem);
log.debug("Substitude Page: " + i);
editor.replaceText(“PAGENO”, i, strPageNo);

log.debug("Create " + pdfFileTarget);


private int numberOfPages(final String pdfFile) throws IOException {
return new PdfFileInfo(pdfFile).getNumberofPages();

My test pdf is attachted.

Best Regards,

Manfred Nentwig

Hi Manfred,

Thank you very much for considering Aspose.

I have reproduced this issue at my end and logged it as PDFKITJAVA-11070 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.

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

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