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);
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 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””>