Tiff inverts black and white after saving or transforming


I am adding several TIFF images into a single PDF document.

Looking at the final PDF document, some (not all) images are appearing as white text on black background when the original image is black text on white background.

I also noticed that by only loading and saving the tiff image, you get the inverted black/white result.

I also tried all TiffExpectedFormat values and Photometric combinations, some make invalid files and others are also inverted.

This is the code:

final String sampleTiffImagePath = "/path/to/Document/sampletiff.tiff";

public void testTiffToPdf() {
    final int IMG_MARGIN_LEFT = 70;
    final int IMG_MARGIN_RIGHT = 70;
    final int IMG_MARGIN_TOP = 72;
    final int IMG_MARGIN_BOTTOM = 72;
    final int MAX_IMG_WIDTH = 595;
    final int MAX_IMG_HEIGHT = 792;

    com.aspose.pdf.Document pdf = new com.aspose.pdf.Document();

    TiffImage tiff = (TiffImage) Image.load(sampleTiffImagePath);
    TiffFrame[] frames = tiff.getFrames();
    int count = 1;
    for (TiffFrame frame : tiff.getFrames()) {
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        TiffOptions opt = new TiffOptions(TiffExpectedFormat.TiffNoCompressionRgb);
        frame.save(os, opt);
        ByteArrayInputStream tiffStream = new ByteArrayInputStream(os.toByteArray());

        Page page = pdf.getPages().add();
        double proportionalMaxHeight = frame.getHeight() * (MAX_IMG_WIDTH + IMG_MARGIN_LEFT) / frame.getWidth();
        page.setCropBox(new Rectangle(0, 0, MAX_IMG_WIDTH, proportionalMaxHeight));
        com.aspose.pdf.Image image = new com.aspose.pdf.Image();



public void testTiffSaveFrame() {
    TiffImage tiff = (TiffImage) Image.load(sampleTiffImagePath);
    TiffFrame[] frames = tiff.getFrames();
    int count = 1;
    for (TiffFrame frame : tiff.getFrames()) {
        TiffOptions opt = new TiffOptions(TiffExpectedFormat.TiffNoCompressionRgb);
        frame.save("/path/to/Document/test/testSaveFrame-" + count + ".tiff", opt);

public void testTiffSave() {
    TiffImage tiff = (TiffImage) Image.load(sampleTiffImagePath);
    TiffOptions opt = new TiffOptions(TiffExpectedFormat.TiffNoCompressionRgb);
    tiff.save("/path/to/Document/test/testSaveTiff.tiff", opt);


Here is the sample image

sampletiff.tiff.zip (26.3 KB)



I have worked with the sample file shared by you and have been able to observe the issue specified. An issue with ID IMAGINGJAVA-1341 has been created in our issue tracking system to further investigate and resolve the issue. This thread has been linked with the issue so that you may be notified once the issue will be fixed.


Hi. Any updates or estimates on this issue?



I have verified from our issue tracking system and issue is tentatively going to get resolved in Aspose.Imaging for Java 19.8. We will share the good news with you as soon as the issue will be fixed and request for your patience.


The issues you have found earlier (filed as IMAGINGJAVA-1341) have been fixed in this update.