Java aspose PDF stamp removal gives java.lang.OutOfMemoryError: Java heap space

Hi Team,

I’m trying to remove all the stamps from the PDF file and able to get the stamps inside each page and trying to remove it is working fine without any issue. But at some point, it is giving me

last.mql.log:Error: #1900068: execute program failed last.mql.log:System Error: #5000001: java.lang.OutOfMemoryError: Java heap space

Is there any way we can resolve this issue. Below is the code i have used:

public void removeHeaderFooterWatermark1(Context context, String sFileNameWithPath) throws Exception
{
List iStampIds = new ArrayList();
com.aspose.pdf.facades.StampInfo[] stamps = null;
com.aspose.pdf.facades.StampInfo stampInfoDetail = null;
StampType stStampType = null;
try {
PdfContentEditor contentEditor = new PdfContentEditor();
System.out.println(“Before>>>>>>>>>>>>>>>>>>”);
//InputStream inputStream = new FileInputStream(sFileNameWithPath);
contentEditor.bindPdf(sFileNameWithPath);//path+file
for(Page page1 : contentEditor.getDocument().getPages()) {
System.out.println(“page1.getNumber()>>>>>>>>>>>>>>>>>>:”+page1.getNumber());
stamps = contentEditor.getStamps(page1.getNumber());
System.out.println(“stamps>>>>>>>>>>>>>>>>>>:”+stamps);
iStampIds = new ArrayList();
System.out.println(“stamps.length>>>>>>>>>>>>>>>>>>:”+stamps.length);
for(int i=0; i<stamps.length; i++){
stampInfoDetail = stamps[i];
stStampType = stampInfoDetail.getStampType();
if((StampType.Form).equals(stStampType)){
int iStampDetail = stampInfoDetail.getIndexOnPage();
iStampIds.add(iStampDetail);
}
}
int[] intArrDetailStamp = iStampIds.stream().filter(iDetail → iDetail != null).mapToInt(iDetail → iDetail).toArray();
//System.out.println(“Before delete Stamp>>>>>>>>>>>>>>>>>>:”+intArrDetailStamp.length);
//contentEditor.deleteStamp(page1.getNumber(), intArrDetailStamp);
System.out.println(“page1.getNumber()…1…>>>>>>>>>>>>>>>>>>:”+page1.getNumber());
}
System.out.println(“After>>>>>>>>>>>>>>>>>>”);
contentEditor.save(sFileNameWithPath);//new file

	} catch (Exception ex) {
		System.out.println(" ** Exception in the prigram removeHeaderFooterWatermark---->" + ex.getMessage());
		ex.printStackTrace();
	}
}

Please help me to resolve this

@Prashanthabmkdzz
We are looking into it and will be sharing our feedback with you shortly.

@Prashanthabmkdzz

Would you please share your sample PDF document with us so that we can try to replicate the issue in our environment and address it accordingly?

Hi @asad.ali - Due to confidentiality reasons, we are not supposed to share the client pdf in any forums. I do want to resolve this issue and really appreciate your help on resolving them. Could you please suggest an other way like i can show the pdf and issue what I’m getting in any meeting or some other way. Please let me know what we can do here?

@Prashanthabmkdzz

In case your file is confidential and you do not want to share it publicly, you can please share it via private message. This way it will stay between you and Aspose Staff only. We also do not keep files and we discard them from our System after issue is fixed. Please click on username and press Blue Message button to send a private message.