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

Free Support Forum - aspose.com

Problems with Multipage Tiff. Wrong Colors displayed

Hello Team,

i’m trying to convert several images to pdf. Everything sounds ok, but the Multipage-Tiff want be converted. The image has a Pink-background and the picture is green. I think the problem is in the Documentbuilder.insertImage but i don’t see where the problem is.output.pdf (654.3 KB)
Desktop.zip (1.2 MB)

My Code, Inputfile and Resultfile have i attached.

Best regards
Michel

@zssservices

We have tested the scenario using the latest version of Aspose.Words for Java 19.5 and have not found the shared issue. Please use Aspose.Words for Java 19.5. We have attached the output PDF with this post for your kind reference. 19.5.pdf (1.0 MB)

Please use the following code example to get the desired output.

Document doc = new Document();

InputStream inputStream = new FileInputStream(MyDir + "multipage_tiff_example.tif");//new ByteArrayInputStream(baos.toByteArray());
DocumentBuilder builder = new DocumentBuilder(doc);

// Load images from the disk using the approriate reader.
// The file formats that can be loaded depends on the image readers available on the machine.
ImageInputStream iis = ImageIO.createImageInputStream(inputStream);

ImageReader reader = ImageIO.getImageReaders(iis).next();
reader.setInput(iis, false);

try
{
    // Get the number of frames in the image.
    int framesCount = reader.getNumImages(true);

    // Loop through all frames.
    for (int frameIdx = 0; frameIdx < framesCount; frameIdx++)
    {
        // Insert a section break before each new page, in case of a multi-frame image.
        if (frameIdx != 0)
            builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE);

        // Select active frame.
        BufferedImage image = reader.read(frameIdx);

        // We want the size of the page to be the same as the size of the image.
        // Convert pixels to points to size the page to the actual image size.
        PageSetup ps = builder.getPageSetup();

        ps.setPageWidth(ConvertUtil.pixelToPoint(image.getWidth()));
        ps.setPageHeight(ConvertUtil.pixelToPoint(image.getHeight()));

        // Insert the image into the document and position it at the top left corner of the page.
        builder.insertImage(
                image,
                RelativeHorizontalPosition.PAGE,
                0,
                RelativeVerticalPosition.PAGE,
                0,
                ps.getPageWidth(),
                ps.getPageHeight(),
                WrapType.NONE);
    }
}

finally {
    if (iis != null) {
        iis.close();
        reader.dispose();
    }
}

doc.save(MyDir + "19.5.pdf");

Hello Team,
thank you for your Response. Unfortunately on my environment, it does not work. I work with Aspose-Words 19.5, Java 1.8 and Windows 10. I have the same error as bevor, pink background and green foreground.
You have any ideas for my problem? The problem is only by multi-page tiff’s. On a single tiff it works.
Thank you and best regards
Michel

@zssservices

We have tested the scenario using the latest version of Aspose.Words for Java 19.5 at Windows 10 with Java 8. We have not found the shared issue. Could you please try the code example shared in my previous post? Please make sure that you are using the same TIFF file that you shared in this thread.

Hello Team,
now it works. The Problem was the ‘twelvemonkeys.imageio’ I replaced with ‘jai-imageio-core’ and everything is ok.
Thank you for your support.
Best regards
Michel Waelty

@zssservices

Thanks for your feedback. It is nice to hear from you that your problem has been resolved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.