The Image file getting cropped while converting to pdf

Hi,

I have an image file which I have to convert to a PDF. I am using Aspose Java 2.9.0

In this conversion half of the image file is getting ignored while converting to PDF. How can this be fixed ?

Here is the code sample :

public static void convertImageFiles(String fileName, String pdfFileName)throws Exception{

Pdf pdfImage = null;

try {

pdfImage = new Pdf();

Section sec = pdfImage.getSections().add();

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

sec.getParagraphs().add(img);

img.getImageInfo().setFile(fileName);

pdfImage.save(pdfFileName);

} finally {

if (pdfImage != null) {

try {

pdfImage.close();

} catch (Exception ignore) {

}

}

}

}

But in this conversion the full image is not coming in the PDF.(Actual image and the generated PDF attached)

Hi Sriman,

Thanks for using our products. The width of the image that you are trying to place inside PDF document is greater than the page width. In order to properly accommodate the image inside PDF file, either please update the page width information or set the page orientation to landscape. Please take a look over the attached PDF document where I have specified the page orientation as Landscape. In case you have any further query, please feel free to contact. We apologize for your inconvenience.

// set the page orientation as Landscape
sec.setIsLandscape(true);

Thanks, but how can we decide when to go for Landscape ?

Hi,

In order to accomplish this requirement, Get the Width information of source image and if the width is larger than the width of PDF document, set the page orientation to landscape. Else leave the dimensions to Portrait. Please take a look over following code snippet to accomplish this requirement.

[Jav]
// load the source image file.
Image image = new ImageIcon(“d:/pdftest/JPEGimage6.3.0.jpg”).getImage();
// check if the width of the image file is greater than Page width or not
if (image.getWidth(null) > sec.getPageInfo().getPageWidth())
// if the Image width is greater than page width, then set the page orientation to Landscape
sec.setIsLandscape(true);
else
// if the Image width is less than page width, then set the page orientation to Portrait
sec.setIsLandscape(false);

// add the image to paragraphs collection of the PDF document
sec.getParagraphs().add(img);

I think we dont have any class " ImageIcon" in Aspose Jar. Could you please let me know which Jar contains this class ?

Hi,

I have the following requirements.

1. I need to convert these two files to PDF.

2. I am not able to get the image width to check whether it exceeds the PDF with, how can I get that ?

3. I tried the below code to set the image width in the pdf but the PDF is coming same as before(half cropped).

img.getImageInfo().setFixWidth(sec.getPageInfo().getPageWidth());

sulthu:
I think we dont have any class " ImageIcon" in Aspose Jar. Could you please let me know which Jar contains this class ?


Hi,

ImageIcon class is present in javax.swing.ImageIcon.ImageIcon package and also please import java.awt.Image in your project.

Hi,

I have managed to reproduce that current version of Aspose.Pdf for Java is having some issue when specifying the Height and Width information for image being placed inside the PDF. For the
sake of correction, I have logged it in our issue tracking system as <span style=“font-family:“Arial”,“sans-serif””>PDFJAVA-31580
. We
will investigate this issue in details and will keep you updated on the status
of a correction.<span style=“font-size:10.0pt;font-family:“Arial”,“sans-serif””>

We
apologize for your inconvenience.