OUT of memory error on find and replace string for attached pdf document

Dear Team,


We have faced out of memory error for the attached pdf document while find and replace text operation. text I tried to find “kpn54527@gmail.com” and replace with empty string(“”)

Code examples are:

for(com.aspose.pdf.TextFragment textFragment : (Iterable)textFragmentCollection){

// Iterate through text segments

for(com.aspose.pdf.TextSegment textSegment : (Iterable)textFragment.getSegments()){

LOGGER.info("Text going to be replaced "+textSegment.getText());

textSegment.setText("");

}

}


Exception Trace are also attached .

Caused by: java.lang.OutOfMemoryError: Java heap space
	at java.util.Arrays.copyOf(Arrays.java:2219)
	at com.aspose.pdf.internal.p515.z17.m4(Unknown Source)
	at com.aspose.pdf.internal.p515.z17.m1(Unknown Source)
	at com.aspose.pdf.internal.p515.z17.addItem(Unknown Source)
	at com.aspose.pdf.internal.p162.z26.m1(Unknown Source)
	at com.aspose.pdf.internal.p162.z26.m1(Unknown Source)
	at com.aspose.pdf.internal.p162.z26.m1(Unknown Source)
	at com.aspose.pdf.internal.p163.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p163.z1.m2(Unknown Source)
	at com.aspose.pdf.internal.p163.z1.m1(Unknown Source)
	at com.aspose.pdf.internal.p162.z3.m1(Unknown Source)
	at com.aspose.pdf.internal.p160.z2.m1(Unknown Source)
	at com.aspose.pdf.z23.m1(Unknown Source)
	at com.aspose.pdf.z23.m1(Unknown Source)
	at com.aspose.pdf.ADocument.m1(Unknown Source)
	at com.aspose.pdf.Document.m1(Unknown Source)
	at com.aspose.pdf.ADocument.save(Unknown Source)
	at com.aspose.pdf.Document.save(Unknown Source)
	at com.adventnet.crm.integration.aspose.MaskResumePDFUtil.createMaskedDocument(MaskResumePDFUtil.java:304)
Some more traces are:

at java.lang.OutOfMemoryError.()V (OutOfMemoryError.java:48)

at java.util.Arrays.copyOf([Ljava/lang/Object;I)[Ljava/lang/Object; (Arrays.java:2219)

at com.aspose.pdf.internal.p515.z17.m4(I)V (Unknown Source)

at com.aspose.pdf.internal.p515.z17.m1(I)V (Unknown Source)

at com.aspose.pdf.internal.p515.z17.addItem(Ljava/lang/Object;)V (Unknown Source)

at com.aspose.pdf.internal.p162.z26.m1(ILcom/aspose/pdf/internal/p515/z17;Lcom/aspose/pdf/internal/p521/z176;Lcom/aspose/pdf/internal/p521/z176;)V (Unknown Source)

at com.aspose.pdf.internal.p162.z26.m1(Lcom/aspose/pdf/internal/p515/z17;Lcom/aspose/pdf/internal/p515/z17;[[I[[IIIII)V (Unknown Source)

at com.aspose.pdf.internal.p162.z26.m1([[B)V (Unknown Source)

at com.aspose.pdf.internal.p163.z1.m1(Lcom/aspose/pdf/internal/p162/z13;FFIZ)Lcom/aspose/pdf/internal/p168/z4; (Unknown Source)

at com.aspose.pdf.internal.p163.z1.m2(Lcom/aspose/pdf/internal/p162/z13;FF)Lcom/aspose/pdf/internal/p168/z4; (Unknown Source)

at com.aspose.pdf.internal.p163.z1.m1(Lcom/aspose/pdf/internal/p162/z13;Lcom/aspose/pdf/internal/p521/z183;)V (Unknown Source)

at com.aspose.pdf.internal.p162.z3.m1(Lcom/aspose/pdf/internal/p515/z17;Lcom/aspose/pdf/internal/p165/z2;Lcom/aspose/pdf/internal/p162/z20;)V (Unknown Source)

at com.aspose.pdf.internal.p160.z2.m1(Lcom/aspose/pdf/internal/p515/z17;)V (Unknown Source)

at com.aspose.pdf.z23.m1(Lcom/aspose/pdf/internal/p160/z2;Lcom/aspose/pdf/internal/p515/z19;)V (Unknown Source)

at com.aspose.pdf.z23.m1(Lcom/aspose/pdf/IDocument;Lcom/aspose/pdf/internal/p528/z41;Lcom/aspose/pdf/DocSaveOptions;)V (Unknown Source)

at com.aspose.pdf.ADocument.m1(Lcom/aspose/pdf/internal/p528/z41;Lcom/aspose/pdf/SaveOptions;)V (Unknown Source)

at com.aspose.pdf.Document.m1(Lcom/aspose/pdf/internal/p528/z41;Lcom/aspose/pdf/SaveOptions;)V (Unknown Source)

at com.aspose.pdf.ADocument.save(Ljava/io/OutputStream;Lcom/aspose/pdf/SaveOptions;)V (Unknown Source)

at com.aspose.pdf.Document.save(Ljava/io/OutputStream;Lcom/aspose/pdf/SaveOptions;)V (Unknown Source)

at com.adventnet.crm.integration.aspose.MaskResumePDFUtil.createMaskedDocument([B[Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/HashMap;Z)Ljava/io/ByteArrayOutputStream; (MaskResumePDFUtil.java:304)

at


This causes out app server to restart. Issue is reproducing every time I try for attatched document. Please, check this ASAP.
I am using aspose.pdf 10.6.2 version with JAVA jdk 1.7 on Cent OS 6 stable version

Hi Ganesh,


We are sorry for the inconvenience. I am testing the scenario over Cent OS and will update you soon.

Best Regards,

Hi Ganesh,


Thanks for your inquiry. I have tested the scenario over Cent OS 6,5 using Eclispse, JRE 1.7 and Aspose.Pdf for Java 10.9.0 but I am unable to notice the reported exception. Please download and try latest version of Aspose.Pdf for Java, hopefully it will resolve the issue. However if the issue persist then please share some more details to replicate the issue.

//Open
document
<o:p></o:p>

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("Kimberly+Nichols.pdf");

//Create TextAbsorber object to find all instances of the input search phrase

com.aspose.pdf.TextFragmentAbsorber textFragmentAbsorber = new com.aspose.pdf.TextFragmentAbsorber("kpn54527@gmail.com");

//Accept the absorber for first page of document

pdfDocument.getPages().accept(textFragmentAbsorber);

//Get the extracted text fragments into collection

com.aspose.pdf.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.getTextFragments();

//Loop through the fragments

for(com.aspose.pdf.TextFragment textFragment : (Iterable)textFragmentCollection)

{

// Iterate through text segments

for(com.aspose.pdf.TextSegment textSegment : (Iterable)textFragment.getSegments())

{

// Update text and other properties

textSegment.setText("");

}

}

//Save the updated PDF file

pdfDocument.save("Updated_Text.pdf");


Please feel free to contact us for any further assistance.

Best Regards,