Determine image color type before converting to PDF using Aspose.PDF for .NET

Hello Aspose team,

I know how to use Aspose.pdf to convert a TIFF image to pdf. But is there a way to check if the TIFF is black&white or not before converting? If the TIFF is black&white, I can call setBlackWhite(true), it saves more time and space for converting. I’m using aspose.pdf 11 java library by the way.

Thank you so much for helping.

@taoj

Thanks for contacting support.

You may surely determine the Color Type of a PDF Page. Please follow the instructions given in the linked article and in case you face any issue, please let us know. Furthermore, we also request and recommend you use the latest version of the API.

Hello,

Thank you for the reply.
I followed that sample and test it by a colored pdf, but it returns 2, blackandwhite, which is wrong.
I run JRuby call java method, and following is the code.
color_tiff.tiff.zip (562.2 KB)

    pdf       = com.aspose.pdf.Document.new
    page      = pdf.getPages.add
    pdf_image = com.aspose.pdf.Image.new
    
    //document_data is the colored TIFF I attached.
    pdf_image.setImageStream(ByteArrayInputStream.new(document_data.to_java_bytes))
    page.getParagraphs.add pdf_image
    pp '-----------------------------------------------------'
    pp pdf.get_pages.size
    pageColorType = pdf.get_pages().get_Item(1).get_color_type()
    pp pageColorType   // pageColorTye return 2 here

Could you check if anything looks problematic above?
I attached the TIFF I used in this case.

Thank you again!

@taoj

Would you please try to determine the Color Type after Document is saved. In case you still face any issue, please share the output PDF document that is obtained at your side. We will test the scenario in our environment and address it accordingly.

Hi,
It returns expected color type after being saved. Thank you for pointing that out.
As you see, it determines the Color Type after converted to Pdf, can the color type be determined before converting? Specifically, can com.aspose.pdf.Image tell what color type it is?

Thank you.

@taoj

Thanks for your feedback.

Regretfully, Aspose.PDF does not provide functionality to read/process images. However, you can determine whether image inside PDF is Colored or Black and White. Furthermore, you can use Aspose.Imaging for Java to work with images and their conversion into different formats.