@suruthyb
Thanks for sharing sample files.
As per our understandings, you need to convert an image into PDF where PDF Page should have similar dimensions as of source image. In order to achieve that, please use following code snippet:
BufferedImage readImage = null;
try {
readImage = ImageIO.read(new File(dataDir + "Fig_1.jpeg"));
int h = readImage.getHeight();
int w = readImage.getWidth();
Document doc = new Document();
Page page = doc.getPages().add();
com.aspose.pdf.Image image = new Image();
image.setFile(dataDir + "Fig_1.jpeg");
page.getPageInfo().setHeight(h);
page.getPageInfo().setWidth(w);
page.getPageInfo().getMargin().setBottom(0);
page.getPageInfo().getMargin().setTop(0);
page.getPageInfo().getMargin().setRight(0);
page.getPageInfo().getMargin().setLeft(0);
page.getParagraphs().add(image);
doc.save(dataDir + "ImagetoPDF.pdf");
} catch (Exception e) {
readImage = null;
}
ImagetoPDF.pdf (25.5 KB)
In case you want to remove/trim white space around a PDF Page from existing PDF document, please refer to “Trim White Space Around Page” article in API documentation. In case of further assistance, please feel free to let us know.