We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Converting tif to pdf

Hi There,

I am using the following code snippet to convert a tif file to pdf. The original tif file size is around 40 KB whereas the pdf file size is close to 2 MB. This happens for other tif files too. Another sample I tried, the tif file is 3 MB and pdf is 51 MB. Please let me know why the pdf file size is so huge and how to reduce it. I am using Aspose PDF 19.2 for Java version for this conversion.

Document doc = new Document();
// Add a page to pages collection of document
Page page = doc.getPages().add();
// Load the source image file to Stream object
FileInputStream fs = new FileInputStream(“35860007_0001.0002.TIF”);

java.awt.image.BufferedImage bImage = null;
bImage = javax.imageio.ImageIO.read(new File(“12-1735-0616-8-003.TIF”));

	page.getPageInfo().setHeight(bImage.getHeight());
	page.getPageInfo().setWidth(bImage.getWidth());
	// Set margins so image will fit, etc.
	page.getPageInfo().getMargin().setBottom(0);
	page.getPageInfo().getMargin().setTop(0);
	page.getPageInfo().getMargin().setLeft(0);
	page.getPageInfo().getMargin().setRight(0);

Image image1 = new Image();
// Add the image into paragraphs collection of the section
page.getParagraphs().add(image1);
// Set the image file stream
image1.setImageStream(fs);

doc.save(“35860007_0001.0002.TIF.pdf”);

Find attached the tif file and the output pdf file for your reference.

Thanks,
Mani
35860007_0001.0002.zip (5.1 MB)

@Mani_Alagappan

Thank you for contacting support.

We have logged a ticket with ID PDFJAVA-38501 in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

Hi There,

Thanks for the update. So, I assume this is a bug and you guys are able to reproduce it from your side too and this will be addressed in a future release. Is that right?

Thanks,
Mani

@Mani_Alagappan

Your understanding is correct. We have been able to notice the difference in file sizes thus a ticket has been logged for further investigations. It will be scheduled on its due turn. We will notify you as soon as any updates are available or once the ticket is resolved.

@Mani_Alagappan

We are glad to inform you that you can minimize the size of grayscale images by using below option:

image1.setBlackWhite(true);

Please share your kind feedback with us after trying it in your environment.

Hi There,

I tried this and now the pdf file size is almost same as tif file. Thanks for the quick response.

Thanks,
Mani

@Mani_Alagappan

Thank you for your kind feedback.

We are glad to know that your issue has been resolved by suggested approach. Please keep using our API and in event of any further query, feel free to ask.