Hi,
We are currently evaluating Aspose PDF (v4.0) for our project. The designed code works fine on the local machine (Windows XP), but throws various exceptions in a Linux environment (our servers are Linux-based). We are using the latest (at the time of writing) jars downloaded from the aspose website, and we are on JDK 1.6 in all environments.
Here is snippet of the code that tries to remove pages from an existing PDF file and save the new document to a byte array:
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(inData));
Document inputPDF = new Document(dis);
inputPDF.getPages().delete(pages); //pages is an int[] array;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
inputPDF.save(baos);
Like I said earlier, this works fine on win XP, but on Linux, we get the following error:
java.lang.NullPointerException
at com.aspose.a.bS.a(Unknown Source)
at com.aspose.pdf.Document.preSave(Unknown Source)
at com.aspose.pdf.Document.saveInternal(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.wellsfargo.wts.wsts.ims.ccg.handlers.PDFManipulationHandler.removePages(PDFManipulationHandler.java:58)
Another function tries to replace some text (with blank strings, for redaction):
DataInputStream dis = new DataInputStream(new ByteArrayInputStream(inData));
Document inputPDF = new Document(dis);
char[] tmp = new char[redactContent.length()];
Arrays.fill(tmp, ' ');
String replacementBlankString = new String(tmp);
TextFragmentAbsorber tfa = new TextFragmentAbsorber ("\\b"+redactContent+"\\b");
TextSearchOptions tso = new TextSearchOptions (true);
tfa.setTextSearchOptions(tso);
inputPDF.getPages().accept(tfa);
TextFragmentCollection tfc = tfa.getTextFragments();
for(com.aspose.pdf.TextFragment tf : (Iterable<com.aspose.pdf.TextFragment>)tfc)
{
TextSegment ts = tf.getSegments().get_Item(1);
Font font = ts.getTextState().getFont();
float size = ts.getTextState().getFontSize();
tf.setText(replacementBlankString);
tf.getTextState().setFont(font);
tf.getTextState().setFontSize(size);
tf.getTextState().setForegroundColor(java.awt.Color.BLACK);
tf.getTextState().setBackgroundColor(java.awt.Color.BLACK);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
inputPDF.save(baos);
This function throws the following error:
class com.aspose.ms.System.d: null key
Parameter name: key
com.aspose.ms.System.a.f.get_Item(Unknown Source)
com.aspose.pdf.engine.commondata.text.encoding.ConsolidatedCache.getFromCache(Unknown Source)
com.aspose.pdf.engine.c.a.a(Unknown Source)
aspose.pdf.HttpResponse.getStandardFontForCodeRange$3a00fffa(Unknown Source)
com.aspose.pdf.engine.commondata.text.b.a.f.a(Unknown Source)
aspose.pdf.HttpResponse.setFont(Unknown Source)
com.aspose.pdf.engine.commondata.text.c.a.a(Unknown Source)
com.aspose.pdf.TextSegment.setText(Unknown Source)
com.aspose.pdf.TextFragment.setText(Unknown Source)
com.wellsfargo.wts.wsts.ims.ccg.handlers.PDFManipulationHandler.redactContent(PDFManipulationHandler.java:127)
Please let me know if any additional info is needed.
Thanks,
Abhijit