Converting .jpg files to PDF

Hi Good day,

How are you?
We are having some production issue while converting certain .jpg files to PDF.
Following is the error that we are getting in our Service logs.

Error message: Image top or bottom margin is too large 0,0 image file:/var/spool/pdfconvert/aspose/1427704633078_1_3.JPG. Error cause: null


try { Pdf pdf1 = new Pdf();
// Create a section in the Pdf object
Section sec1 = pdf1.getSections().add();
// Create an image object in the section
aspose.pdf.Image img1 = new aspose.pdf.Image(sec1);
// Add image object into the Paragraphs collection of the section
sec1.isLandscape(true);//added to resolve some formatting issue
sec1.getParagraphs().add(img1);
// Set the path of image file
img1.getImageInfo().setFile(inFilepath);
// Save the Pdf
pdf1.save(pdfFilepath);
LOG.info(" Converted Image To Pdf by ASPOSE Successfully " );
}catch (Exception e) {
LOG.error("Failed to convert Image to PDF… Error message: “+e.getMessage()+”. Error cause: "+e.getCause());
throw new XPdfConvert(String.format(
“message=“Failed to convert Image file To PDF ‘%s’””, inFilepath),e);
}
}

Pls find the samples attached which are failed.

Currently we are using
'aspose.pdf-9.1.0.jar’

as we are having some formatting issues with old version “aspose.pdf-3.0.1.jdk16.jar” few months
so we have deployed new version of ‘aspose.pdf-9.1.0.jar’ with some extra logic added to code.

sec1.isLandscape(true);//added to resolve some formatting issue.
which means,while converting bigger images the result pdf is coming in two or more pages for one image and which is not really looking good.
After deploying new version and above logic highlighted solved the issue,
but we are getting new issue, with certain jpg files as per attached samples with the following
Error:
Error message: Image top or bottom margin is too large 0,0 image

Your response,will be appreciated,

Regards,
Prasad




Hi Prasad,


Thanks for your inquiry. We have tested your scenario with new DOM approach. It is recommend to use new approach as it is more improved and efficient. It is working fine with Duane.JPG. However we have noticed an exception with IMG.JPG conversion, so logged a ticket PDFNEWJAVA-34775 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

// instantiate Document object<o:p></o:p>

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

// add page to PDF file

doc.getPages().add();

// create Image object

com.aspose.pdf.Image img = new com.aspose.pdf.Image();

// load TIFF image

img.setFile(myDir+"Duane.jpg");

// add image to paragraphs collection of first page

doc.getPages().get_Item(1).getParagraphs().add(img);

// save resultant PDF

doc.save(myDir+"IMGDOM.PDF");


We are sorry for the inconvenience caused.

Best Regards,

Hi Good evening,

Could you pls provide some feedback for the issue we have raised earliler with regarding .jpg conversion to PDF.
Below is the ticket number : PDFNEWJAVA-34775
<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:EN-ZA;mso-fareast-language:
EN-ZA;mso-bidi-language:AR-SA”> and thread link : <span style=“font-size:12.0pt;font-family:“Times New Roman”,“serif”;
mso-fareast-font-family:“Times New Roman”;mso-ansi-language:EN-ZA;mso-fareast-language:
EN-ZA;mso-bidi-language:AR-SA”><a href="
we are still having issues with certain jpg files.
Pls find the attached files that has .jpg files with in the email attachment.


we are also having .TIF file conversion issues,pls find one sample one that failed in PRODUCTION

Your response,will be appreciated…

Regards,
Prasad
Hi Prasad,

Thanks for your inquiry.


metropolitanhealth:
Hi Good evening,
Could you pls provide some feedback for the issue we have raised earliler with regarding .jpg conversion to PDF.
Below is the ticket number : PDFNEWJAVA-34775
and thread link : metropolitanhealth:

Moreover, we are looking into your shared images and will update our findings soon.


Best Regards,
Hi Prasad,

metropolitanhealth:
we are still having issues with certain jpg files.
Pls find the attached files that has .jpg files with in the email attachment.


we are also having .TIF file conversion issues,pls find one sample one that failed in PRODUCTION


I am afraid I am unable to find image files in email attachments, emails contain .eml attachments. We will appreciate it if you please share the image files instead email messages. So we will look into it and guide you accordingly.


Best Regards,

Hi good day,

The image file is there in the .eml attachment,
As a part of our service functionality we expect .eml file (embedded files(JPG/Tiff/doc etc., attached ) as an email attachment.
we have to convert whole email body and attachment into pdf after extracting.
Anyway pls find the TIF file as an attachment.

Below is the error logged while TIf file conversion process:
-------------------------------------------------------------
Failed to convert TIF File of File Type : Tiff to PDF. Error message: Cannot decode strip 0. Details: Cannot perform 2d decoding. Missing changes from previous row…

Your response,will be appreciated,

Regards,
Prasad

Hi Prasad,


Thanks for sharing source TIFF image. I have tested the scenario and managed to notice the reported exception. So logged a ticket PDFNEWJAVA-34838 in our issue tracking system for further investigation and resolution. We will notify you as soon as it is resolved.

We are sorry for the inconvenience caused.

Best Regards,

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


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

Hi Good day,

As per your suggestion,i currently using latest.‘aspose-pdf-10.4.0.jar’ for resolving some tiff conversion.
we still having issue.

.TIFF error:
Error message: -1. Error cause: null

Also,having issue with jpg file.Pls find attached.
JPG Error:
Failed to convert Image to PDF… Error message: Image top or bottom margin is too large 0,0. Error cause: null


Pls assist us ASAP,as we have renewed license and upgraded with latest Aspose Jars to resolve these issues.These are impacting our PROD environment.

Pls find the attached fiels that failed while converting into PDF using ASPOSE JAVA…

KindRegards,
Prasad Dasari…

Hi Prasad,


Thanks for your inquiry. As suggested in above post, please use new DOM approach JPG to PDF conversion is fixed in it. I have tested your shared JPG images with following code and unable to notice above reported exception.

Moreover, we will notify you as soon as we resolve above reported issue (PDFNEWJAVA-34838), related to TIF image conversion.

// instantiate Document object<o:p></o:p>

com.aspose.pdf.Document doc = new com.aspose.pdf.Document();

// add page to PDF file

doc.getPages().add();

// create Image object

com.aspose.pdf.Image img = new com.aspose.pdf.Image();

// load TIFF image

img.setFile(myDir+"prod4.JPGF");

// add image to paragraphs collection of first page

doc.getPages().get_Item(1).getParagraphs().add(img);

// save resultant PDF

doc.save(myDir+"prod4_IMGDOM.PDF");


Best Regards,

Hi good day,
I have tried your DOM Approach,

pls check below code as i am currently tested:

//New version using DOM approach
private static void convertImageToPdf(String inFilepath, String pdfFilepath,FileType fileType)
throws XPdfConvert {
LOG.info(" Converting Image To Pdf using DOM Approach … " );
ByteArrayInputStream srcStream = null;
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
byte[] inbytesArray = null;
try {
inbytesArray = FileUtils.readFileToByteArray(new File(inFilepath));
srcStream = new ByteArrayInputStream(inbytesArray);
Pdf pdf1 = new Pdf();
// instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// add page to PDF file
doc.getPages().add();
com.aspose.pdf.Image img1 = new com.aspose.pdf.Image();
img1.setImageStream(srcStream);
//add image to paragraphs collection of first page
doc.getPages().get_Item(1).getParagraphs().add(img1);
pdf1.save(dstStream);
LOG.info(" Converted Image To Pdf by ASPOSE Successfully " );
} catch (Exception e) {
LOG.error("Failed to convert Image to PDF… Error message: “+e.getMessage()+”. Error cause: "+e.getCause());
throw new XPdfConvert(String.format(
“message=“Failed to convert Image file To PDF ‘%s’””, inFilepath),e);
}
}
Pls assist with this ASAP as this is a PROD issue.
Pls send me the converted pdf’s that you have mentioned that it was working with my JPEG files attached earlier.
The code snippet that you have given earlier is the one i shared some time before which was not working.so bit confused.
Your code:
// instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// add page to PDF file
doc.getPages().add();
// create Image object
com.aspose.pdf.Image img = new com.aspose.pdf.Image();
// load TIFF image
img.setFile(myDir+“prod4.JPGF”);
// add image to paragraphs collection of first page
doc.getPages().get_Item(1).getParagraphs().add(img);
// save resultant PDF
doc.save(myDir+“prod4_IMGDOM.PDF”);

We are still waiting tiff issue related to TIF image
conversion.
(PDFNEWJAVA-34838), related to TIF image
conversion.

<o:p></o:p>

Your response will be appreciated,

Kind Regards,Prasad


Hi Prasad,

metropolitanhealth:

I have tried your DOM Approach,
pls check below code as i am currently tested:

//New version using DOM approach
private static void convertImageToPdf(String inFilepath, String pdfFilepath,FileType fileType)
throws XPdfConvert {
LOG.info(" Converting Image To Pdf using DOM Approach .... " );
ByteArrayInputStream srcStream = null;
ByteArrayOutputStream dstStream = new ByteArrayOutputStream();
byte[] inbytesArray = null;
try {
inbytesArray = FileUtils.readFileToByteArray(new File(inFilepath));
srcStream = new ByteArrayInputStream(inbytesArray);
Pdf pdf1 = new Pdf();
// instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// add page to PDF file
doc.getPages().add();
com.aspose.pdf.Image img1 = new com.aspose.pdf.Image();
img1.setImageStream(srcStream);
//add image to paragraphs collection of first page
doc.getPages().get_Item(1).getParagraphs().add(img1);
pdf1.save(dstStream);
LOG.info(" Converted Image To Pdf by ASPOSE Successfully " );
} catch (Exception e) {
LOG.error("Failed to convert Image to PDF... Error message: "+e.getMessage()+". Error cause: "+e.getCause());
throw new XPdfConvert(String.format(
"message=\"Failed to convert Image file To PDF '%s'\"", inFilepath),e);
}
}
Pls assist with this ASAP as this is a PROD issue.



Thanks for your inquiry. Please note you are mixing old generator and new generator in above code. You have added image to PDF using new DOM but at the end saving old generator object. That results in a blank PDF. Please remove above highlighted code lines and save PDF to stream using doc.save() method. It will resolve the issue.

metropolitanhealth:
Pls send me the converted pdf's that you have mentioned that it was working with my JPEG files attached earlier.



We have already shared the subjected PDFs in above post.

metropolitanhealth:
The code snippet that you have given earlier is the one i shared some time before which was not working.so bit confused.
Your code:
// instantiate Document object
com.aspose.pdf.Document doc = new com.aspose.pdf.Document();
// add page to PDF file
doc.getPages().add();
// create Image object
com.aspose.pdf.Image img = new com.aspose.pdf.Image();
// load TIFF image
img.setFile(myDir+"prod4.JPGF");
// add image to paragraphs collection of first page
doc.getPages().get_Item(1).getParagraphs().add(img);
// save resultant PDF
doc.save(myDir+"prod4_IMGDOM.PDF");

We are still waiting tiff issue related to TIF image conversion. (PDFNEWJAVA-34838), related to TIF image conversion.

Your response will be appreciated,

Kind Regards,Prasad



Please pay attention, actually you shared old generator(aspose.pdf) code in you initial post and we are suggesting you new DOM code(com.aspose.pdf), both are different.

Moreover regarding PDFNEWJAVA-34838, we will notify as soon as we made some significant progress towards issue resolution.

Best Regards,

Hi Good day,

Thank your the assistance by pointing to right piece of code for JPEG conversion with latest apose.pdf jar and i have tested JPEG files which are failed earlier?

with regarding PDFNEWJAVA-34838,did you guys made any progress on this.<o:p></o:p>

Pls let me know once u have solution that fix converting certain tiff files that failed as per my email earlier.

Your response will be appreciated.


Thank you once again for the suppport.


kind regards,

Prasad


Hi Prasad,

metropolitanhealth:
Thank your the assistance by pointing to right piece of code for JPEG conversion with latest apose.pdf jar and i have tested JPEG files which are failed earlier?


I am afraid I am not clear by your statement. Does it mean JPEG conversion issue is resolved?

metropolitanhealth:

with regarding PDFNEWJAVA-34838,did you guys made any progress on this.

Pls let me know once u have solution that fix converting certain tiff files that failed as per my email earlier.

In reference to PDFNEWJAVA-34838, the issue is still not resolved. Our product team has completed initial investigation and planning for the resolution. We will notify you as soon as we made some significant progress towards issue resolution.


Thanks for your patience and cooperation.


Best Regards,

Hi Good day,

Sorry for the confusion,
I mean to say issue with JPEG files was resolved with new DOM Approach.
Just waiting for the solution for TIFF image conversion.

Kind Regards,
Prasad Dasari…
metropolitanhealth:
Hi Good day,
Sorry for the confusion,
I mean to say issue with JPEG files was resolved with new DOM Approach.
Just waiting for the solution for TIFF image conversion.
Hi Prasad,

Please note that the issue reported earlier as PDFNEWJAVA-34838 is regarding TIFF to PDF conversion, whereas the previously reported issue was related to JEPG to PDF conversion.

As shared by Tilal, as soon as we have we have made some definite progress towards the resolution of TIFF image to PDF conversion, we will let you know.

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


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