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

Free Support Forum - aspose.com

Aspose PDF (v4.0) for Java on Linux

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

Hi Abhijit,


Thanks for you inquiry. After initial investigation, we’ve logged an issue as PDFNEWJAVA-33476 in our issue tracking system for further investigation and resolution. We will keep you updated regarding issue status via this forum thread.

Sorry for the inconvenience faced.

Best Regards,

We are almost about to buy this product Aspose Toal for Java for our bank.


We need this ticket closed ASAP, if we have to proceed further in buying this product.

Please let us know if this issue can be solved. This is a SHOW STOPPER for us.

I still cannot get this working on Linux!

Hi Abhijit,


Thanks for your inquiry. I’m afraid your reported issue is still not resolved due to other priority tasks. However, I’ve share your concern with development team and requested them to share an ETA at their earliest. I’ll update you via this forum thread as soon as I get a feedback.

Thanks for your patience and cooperation.

Best Regards,

Do you have any updates on this?

Hi Amruth,


Thanks for your inquiry. I’m afraid the reported issue is still not resolved. Our development team is looking into the issue and as soon as it is resolved we will update you via this forum thread.

Sorry for the inconvenience faced.

Best Regards,

Hi Abhijit,


Thanks for your patience.

We have further investigated the problem reported earlier and I am pleased to share that NullPointerException is resolved in latest release of Aspose.Pdf for Java 4.5.0. Now concerning to other issue related to Text replace, the problem occurs over the code line tf.getTextState().setFont(font);

The development team is working hard on fixing this problem and as a workaround, you need to manually set the required font:

textFragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont(“Font Name”));

For further details, please visit Replace text in page of PDF doucment.

Having same issue. The following code works great under Windows, but gives an NullPointerException on TextFragment creation on Solaris:

private static com.aspose.pdf.Document txtPages2pdf2(String path, Charset encoding) {
FileInputStream fin = null;
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

try {
fin = new FileInputStream(path);
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] bytes = new byte[1024];
int len;

while ((len = fin.read(bytes)) != -1) {
bout.write(bytes, 0, len);
}

byte[] encoded = bout.toByteArray();
String text = encoding.decode(ByteBuffer.wrap(encoded)).toString();

System.out.println("All text: " + text);
com.aspose.pdf.TextFragment textfragment = new com.aspose.pdf.TextFragment(text);
// never gets here
System.out.println(“textFragment created.”);
textfragment.getTextState().setFont(com.aspose.pdf.FontRepository.findFont(“Times New Roman”));

doc.getPages().add().getParagraphs().add(textfragment);
} catch (Exception ex) {
ex.printStackTrace();
}
return doc;
}

I’ve tried it with Strings of all shapes and sizes and even reading in as ASCII. File is a .txt uploaded from Windows, but it looks fine in vi. I’m on PDF 9.3.1.

Hi Ronald,


Thanks for contacting support.

I have tested the scenario and have observed that when trying to convert attached TXT file to DPF format even on Linux, a NullReferenceException is being generated. It’s been observed that input TXT file has UTF-8 encoding and when trying to convert the same file over Windows, an error message is being displayed. However if encoding of TXT file is changed to ANSI, the conversion of windows works fine but it still fails over Linux. For the sake of correction, I have logged this problem as PDFNEWJAVA-34446 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction.

Please be patient and spare us little time. We are sorry for this inconvenience.

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


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