Extracted Image in pdf has white space

Hi Team,
Extracting Image from doc and save image as a pdf has white space around the image.
Suggest a method to extract image alone and save as a pdf without space.

Meanwhile for JPEG it is extracting perfectly with the help of shape render.
Hereby I have attached the sample for your reference.

Fig.zip (185.0 KB)

Many Thanks in advance
Suruthy

@suruthyb

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Please find the attached application for trim space in pdf.

Trim_Space.zip (656 Bytes)

@suruthyb

Thanks for sharing the detail. Your query is related to Aspose.PDF API. We have moved this thread to Aspose.PDF forum where you will be guided appropriately.

@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.

@asad.ali
Thankyou for your response, here I tried with this but " doc.getPages() " throws error - “The method getPages() is undefined for the type Document” . Let me know what is the issue and in which version it works.

Thanks
Suruthy.

@suruthyb

Please use suggested code snippet with Aspose.PDF for Java 18.8 which is latest version of the API. In case you still face any issue, please feel free to let us know.

@asad.ali
Yes I have tried with the latest version, still the same error exist. Suggest a solution, Thankyou.

@suruthyb

Document Class in your program must be referring to a different assembly, so please try using complete qualified name like com.aspose.pdf.Document in your code and in case issue still occurs, please share a sample console application with us which is able to replicate the issue in any environment. We will test the scenario in our environment and address it accordingly.