Conversion (PDF to PNG/JPEG) exceptions

Hello,
During tests of new lib 10.6.1 we see:
Handling ConversionServiceException: ----> Exception occured while saving pages as set of images.
This is a Debug Exception. Please do not CR this Exception.
This exception is printed if the debug logs are turned on for log family DCS.
class com.aspose.pdf.internal.p391.z72: java.lang.NullPointerException —> java.lang.NullPointerException
— End of inner exception stack trace —
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
com.aspose.pdf.devices.PngDevice.process(Unknown Source)
com.x.PDFToPNGConverter.convert(PDFToPNGConverter.java:88)
com.x.ConversionTask.call(ConversionTask.java:49)
com.x.ConversionTask.call(ConversionTask.java:16)
java.util.concurrent.FutureTask.run(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
at com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
at com.aspose.pdf.devices.PngDevice.process(Unknown Source)
at com.x.PDFToPNGConverter.convert(PDFToPNGConverter.java:88)
at com.nortelnetworks.ims.app.dcs.servlet.fw.ConversionTask.call(ConversionTask.java:49)
at com.nortelnetworks.ims.app.dcs.servlet.fw.ConversionTask.call(ConversionTask.java:16)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.aspose.pdf.internal.p636.z1.m13(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m14(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m21(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m17(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
class com.aspose.pdf.internal.p391.z72: java.lang.NullPointerException —> java.lang.NullPointerException
— End of inner exception stack trace —
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
com.aspose.pdf.devices.PngDevice.process(Unknown Source)
com.x.PDFToPNGConverter.convert(PDFToPNGConverter.java:88)
com.x.ConversionTask.call(ConversionTask.java:49)
com.x.ConversionTask.call(ConversionTask.java:16)
java.util.concurrent.FutureTask.run(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
at com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
at com.aspose.pdf.devices.PngDevice.process(Unknown Source)
at com.x.PDFToPNGConverter.convert(PDFToPNGConverter.java:88)
at com.x.ConversionTask.call(ConversionTask.java:49)
at com.x.ConversionTask.call(ConversionTask.java:16)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException
at com.aspose.pdf.internal.p636.z1.m13(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m14(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m21(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m17(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
… 12 more
Caused by: class com.aspose.pdf.internal.p391.z72: java.lang.NullPointerException —> java.lang.NullPointerException
— End of inner exception stack trace —
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.z1.m1(Unknown Source)
com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
com.aspose.pdf.devices.PngDevice.process(Unknown Source)
java.util.concurrent.FutureTask.run(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.z1.m1(Unknown Source)
at com.aspose.pdf.devices.ImageDevice.m1(Unknown Source)
at com.aspose.pdf.devices.PngDevice.processInternal(Unknown Source)
at com.aspose.pdf.devices.PngDevice.process(Unknown Source)
at com.x.PDFToPNGConverter.convert(PDFToPNGConverter.java:88) ( pngDevice.process(pages.get_Item(page), baos):wink:
… 6 more
Caused by: java.lang.NullPointerException
at com.aspose.pdf.internal.p636.z1.m13(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m14(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m21(Unknown Source)
at com.aspose.pdf.internal.p636.z1.m17(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
at com.aspose.pdf.internal.p633.z7.m1(Unknown Source)
… 12 more
Used code:

public boolean convert() throws ConversionServiceException {
prepare();//license.setLicense(getLicense()); 
Document.setLocalFontPaths(paths);resolution = new Resolution(dpi_Resolution);
String uploadedFile = formatUploadedFile(inputFileName);
PdfFileInfo fileInfo = new PdfFileInfo(uploadedFile);
Document pdfDocument = null;
try {
pdfDocument = new Document(uploadedFile);
}
catch (Exception e) {
handleException(e, “PDf file binding failed”);
}
PageCollection pages = pdfDocument.getPages();
int pageCount = (pages == null) ? 0 : pdfDocument.getPages().size();
if (pageCount > getPageLimit() || pageCount == 0) {
handleException(null, “Document size exceeds the set page limit or document is empty.”);
}
PngDevice pngDevice = new PngDevice(resolution);
JpegDevice jpegDevice = new JpegDevice(resolution, MIN_JPG_QUALITY);
try {
// convert pages to images
for (int page = 1; page <= pageCount; page++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String processFileName;
// Convert a particular page and save the image to stream
try {
pngDevice.process(pages.get_Item(page), baos); 
//HERE!!!It’s line #88
}
catch (Exception e) {
handleException(e, “Exception occured while saving pages as set of images.”);
}
finally {
// Close the stream
baos.close();
}
byte[] pngImageInBytes = baos.toByteArray();
int pngFileSize = pngImageInBytes.length;
processFileName = formatProcessFile(page, PNG_EXTENSION);
if (pngFileSize == 0) {
if (DcsDebug.isEnabled()) {
DcsDebug.print("---------> PNG file size was zero so skipping write to file… " + processFileName,
DebugLevel.VERBOSE);
}
continue;
}
if (pngFileSize <= png_size_limit) {
writeToFile(processFileName, pngImageInBytes);
}
else {
ByteArrayOutputStream jbaos = new ByteArrayOutputStream();
try {
// Convert a particular page and save the image to stream
jpegDevice.process(pages.get_Item(page), jbaos);
}
catch (Exception e) {
// Nothing to do. We already have png stream
}
finally {
// Close the stream
jbaos.close();
}
byte[] jpgImageInBytes = jbaos.toByteArray();
int jpgFileSize = jpgImageInBytes.length;
if (jpgFileSize == 0 || pngFileSize <= (jpgFileSize + MAX_PNG_JPG_SIZE_OFFSET)) {
writeToFile(processFileName, pngImageInBytes);
}
else {
writeToFile(formatProcessFile(page, JPG_EXTENSION), jpgImageInBytes);
}
}
}
}
catch (Exception e) {
handleException(e, “Exception occured during PDf conversion.”);
}
finally {
com.aspose.pdf.MemoryCleaner.clear();
}
<span style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-bidi-font-family:“Times New Roman”;color:#1F497D;mso-ansi-language:
EN-US;mso-fareast-language:RU;mso-bidi-language:AR-SA” lang=“EN-US”>The issue is
intermittent (90%).<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>RU</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>
/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; 
mso-tstyle-rowband-size:0;
 mso-tstyle-colband-size:0;
 mso-style-noshow:yes;
 mso-style-priority:99;
 mso-style-parent:"";
 mso-padding-alt:0cm 5.4pt 0cm 5.4pt; 
mso-para-margin:0cm;
 mso-para-margin-bottom:.0001pt;
 mso-pagination:widow-orphan;
 font-size:10.0pt; font-family:"Times New Roman","serif";
}
<![endif]–>

I’ve seen similar reports about NullPointer exceptions but not sure that it is the same.
So could you please be so kind to verify is it bug or some incorrect usage of aspose lib?
Thank you in advance.
Best Regards

Hi Akane,


Thanks for your inquiry. I am afraid I am unable to test your shared code due to missing references. However I have tested PDF to PNG/JPEG conversion scenario using your shared source PDF document with Aspose.Pdf for Java 10.6.1, JDK 7 and eclipse over Win 7 64 bit in 25 iterations. But I am unable to replicate the issue. Please share an executable code and your environment details, so we will try to replicate the issue at our end and will provide you more information accordingly.

We are sorry for the inconvenience caused.

Best Regards,

hello,
Some details are below

prepare();
`//license.setLicense(getLicense());Document.setLocalFontPaths(paths);resolution = new
Resolution(dpi_Resolution);

PdfFileInfo fileInfo = new PdfFileInfo(uploadedFile);

Document pdfDocument = null;
try {
pdfDocument = new Document(uploadedFile);
}
catch (Exception e) {
}

PageCollection pages = pdfDocument.getPages();
int pageCount = (pages == null) ? 0 : pdfDocument.getPages().size();

PngDevice pngDevice = new PngDevice(resolution);
JpegDevice jpegDevice = new JpegDevice(resolution, MIN_JPG_QUALITY);

try {
// convert pages to images
for (int page = 1; page <= pageCount; page++) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
String processFileName;
// Convert a particular page and save the image to stream
try {
pngDevice.process(pages.get_Item(page), baos); //HERE!!!It’s line #88
}
catch (Exception e) {
}
finally {
// Close the stream
baos.close();
}
byte[] pngImageInBytes = baos.toByteArray();
int pngFileSize = pngImageInBytes.length;

processFileName = page+".png";
writeToFile(processFileName, pngImageInBytes);
}
}
catch (Exception e) {
}
finally {
com.aspose.pdf.MemoryCleaner.clear();
}
<span style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-bidi-font-family:“Times New Roman”;color:#1F497D;mso-ansi-language:
EN-US;mso-fareast-language:RU;mso-bidi-language:AR-SA” lang=“EN-US”>
java version “1.7.0_85”
Java™ SE Runtime Environment (build 1.7.0_85-b31)
Java HotSpot™ 64-Bit Server VM (build 24.85-b06, mixed mode)
Linux 2.6.32-573.el6.x86_64 x86_64 GNU/Linux

The main problem is that <span style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-bidi-font-family:“Times New Roman”;color:#1F497D;mso-ansi-language:
EN-US;mso-fareast-language:RU;mso-bidi-language:AR-SA” lang=“EN-US”>the issue is
intermittent
I didn’t observe it a couple of days even when other users reported about it.
<span style=“font-size:11.0pt;font-family:
“Calibri”,“sans-serif”;mso-fareast-font-family:Calibri;mso-fareast-theme-font:
minor-latin;mso-bidi-font-family:“Times New Roman”;color:#1F497D;mso-ansi-language:
EN-US;mso-fareast-language:RU;mso-bidi-language:AR-SA” lang=“EN-US”>Now the issue is
intermittent (90%) for files with more than 30 pages
The issue was not observed at all with previous libs and with

Best Regards

Hi Akane,


Thanks for your sharing additional information. We will test the scenario over Linux server and provide you information accordingly.

Best Regards,

Hi Akane,


Thanks for your patience. I have tested the scenario over Ubuntu 13.10 with Aspose.Pdf for Java 10.6.1 and still unable to replicate the issue.

Moreover, are you converting PDF to Image in a multi-threaded environment? as the issue can be happened in multithreading. Aspose is multi-thread safe as long as only one thread works on a document at a time. It is a typical scenario to have one thread working on one document. Different threads can safely work on different documents at the same time.

I am sorry we can not suggest any solution without replicating the issue. If you find some other information to replicate the issue then please share so we will try to replicate the issue.

We are truly sorry for the inconvenience.

Best Regards,