Some jpgs result in blank page once converted to PDF

Hi,
I am using below code to convert jpg to pdf. But I see that the resultant PDF file is empty with only water mark appended.

I have attached a sample file for which PDF is empty.

//Code snippet
Document pdfDocument = new Document();
Page page = pdfDocument.getPages().add();
pdfPage.getPageInfo().setHeight(imHeight);
pdfPage.getPageInfo().setWidth(imWidth);
pdfDocument.getPageSetup().setOrientation(PageFormat.LANDSCAPE);
Image image = new Image();
image.setImageStream(is);
pdfDocument.getPages().get_Item(1).getParagraphs().add(image);
page.getParagraphs().add(image);
pdfDocument.save(“C:/temp/ImagetoPDF.pdf”);
saveFile(workerServlet, pdfDocument, os);

Image-116.jpg (74.7 KB)

@sushma1509
what version of the library are you using?

Hi,
I am using aspose-pdf-22.9-jdk16 for JAVA. I have tried the same with words jar as well. It is still empty. aspose words is aspose-words-22.9-jdk16 for JAVA

     Document doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
  setPrintSettings(ps, dataProvider, printThread, book, img, builder); (I set img width , pageWidth , resolution, orientation and other attributes in this method)
   Shape img = builder.insertImage(is);
   doc.save("C:/temp/ImagetoPDF.pdf");

@sushma1509
I’m not strong in Java - I wrote how it would look like in C#

var pdfDocument = new Aspose.Pdf.Document();
var pdfPage = pdfDocument.Pages.Add();

pdfPage.PageInfo.IsLandscape = true;

var image = new Aspose.Pdf.Image();
image.File = myDir + "Image-116.jpg";

pdfPage.Paragraphs.Add(image);

pdfDocument.Save(myDir + "image-out.pdf");

image-out.pdf (179.5 KB)

Hi,
This is a direct load from a file. But what I am trying is from an inputstream.
Shape img = builder.insertImage(is);
“is” is InputStream.

Document pdfDocument = new Document();
Page page = pdfDocument.getPages().add();
pdfPage.getPageInfo().setHeight(imHeight);
pdfPage.getPageInfo().setWidth(imWidth);
pdfDocument.getPageSetup().setOrientation(PageFormat.LANDSCAPE);
Image image = new Image();
image.setImageStream(is);
pdfDocument.getPages().get_Item(1).getParagraphs().add(image);
page.getParagraphs().add(image);

@sushma1509
Check out this code snippet

var pdfDocument = new Aspose.Pdf.Document();
var pdfPage = pdfDocument.Pages.Add();

pdfPage.PageInfo.IsLandscape = true;

var image = new Aspose.Pdf.Image();

byte[] array = System.IO.File.ReadAllBytes(myDir + "Image-116.jpg");
var mstream = new System.IO.MemoryStream(array);
image.ImageStream = mstream;
pdfPage.Paragraphs.Add(image);

pdfDocument.Save(myDir + "image-out.pdf"); 

Hi @sergei.shibanov
I tried the above. Though I see the output now, I still see few errors in the log.
Please see below
version used : aspose pdf 23.1 jdk16
File used : Uploaded here
Code used:
Document pdfDocument = new Document();
Page page = pdfDocument.getPages().add();
//setPrintSettings(ps, dataProvider, printThread, book, pdfDocument);
Image image = new Image();
image.setImageStream(is);
pdfDocument.getPages().get_Item(1).getParagraphs().add(image);
page.getParagraphs().add(image);
pdfDocument.save(“C:/temp/ImagetoPDF.pdf”);
Image-124.jpg (74.5 KB)

Errors in log:

java.lang.NullPointerException
at com.aspose.pdf.ADocument.lf(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)
at com.aspose.pdf.ADocument$4.lI(Unknown Source)
at com.aspose.pdf.internal.l89u.lf.lI(Unknown Source)
at com.aspose.pdf.internal.l89u.lj.lI(Unknown Source)
at com.aspose.pdf.ADocument.save(Unknown Source)
at com.aspose.pdf.Document.save(Unknown Source)

I see these errors with more than one jpg file. Please let me know if you need more files as reference.

@sushma1509
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-42488

You can obtain Paid Support services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@sushma1509
image-124-out.pdf (178.4 KB)

Hi @sergei.shibanov

As mentioned I too see the output. But I was concerned with the errors, if some features might get missed because of them
Thanks for the ticket.

@sushma1509
As soon as I have information I will let you know.

@sushma1509
Development team looked at the task and wrote the following:

We tried to reproduce the issue, but the exceptions are absent.
JDK version: 1.6.0_45
Version of Aspose.Pdf for Java: 23.1 (for JDK 1.6)
Also, we attached our test project, please offer the customer to check our test project.

Commands for running test project:
mvn clean install
java -jar target/aspose-hello-world-1.0-SNAPSHOT.jar
To build the project we use apache-maven-3.2.5.

We need more details to reproduce this issue:
OS
JDK version
test project

aspose-hello-world.zip (615.4 KB)
Image-116_23.1_jdk1.6.0_45.pdf (234.1 KB)
Image-124_23.1_jdk1.6.0_45.pdf (233.6 KB)