How to convert TIFF images to PDF with specific requirements?

Hi.
We are considering to use Aspose.Imaging for java to convert TIFF images to PDF. This works fine with basic code and settings. We have some specific requirements for the generated PDF that we are trying to add:
Format (compression) must be CCITT G4 fax
300 dpi resolution
Monochrome
Full size

The TIFF files should already have these settings so this is a direct conversion but we need to ensure it is set for the resulting PDF. They contain large drawings with a lot of details that must also be readable in the pdf.

What parameters and values should we use in the code to achieve the four requirements?

Any help is appreciated.

Hi, @dawittwe
Thank you for your interest in Aspose.Imaging. You can specify all your requirements using the following code.

Image image = Image.load("picture.tif");
try
{
	image.save("output.pdf", new PdfOptions(){{
		setPdfCoreOptions(new PdfCoreOptions() {{
			setCompression(PdfImageCompressionOptions.Ccitt4);
		}});
		setUseOriginalImageResolution(true);
	}});
} finally {
	image.dispose();
}

Hi Evgeniy,
Thanks for your quick reply. It is appreciated.

Please note that the latest version we can run is Asose.Images 21.12 from 2021.

We have been experimenting a bit with the code to set the requirements.

We managed to set the original page width and breadth like this:
pdfOpt.setUseOriginalImageSize(true);

The PDF is unfortunately completely unreadable if we add this line for compression (same with Ccitt3 but jpeg works):
setCompression(PdfImageCompressionOptions.Ccitt4);

Do you know if there is a parameter or something we can use to fix this? Or if there is another way?

We tried to change to black & white but it didn’t work.The output tiff still shows colour mode in the settings in Paint.

How should we set the colour to black & white?

And how should we set the resolution to 300 dpi?

Here is the current code we are testing with.

package com.tietoevry.fls;

import com.aspose.imaging.Image;
import com.aspose.imaging.License;
import com.aspose.imaging.fileformats.pdf.PdfCoreOptions;
import com.aspose.imaging.fileformats.pdf.PdfDocumentInfo;
import com.aspose.imaging.imageoptions.PdfOptions;
import com.aspose.imaging.imageoptions.TiffOptions;

;
public class AsposeImage2 {
public static void main(String[] args) {
try {
License imgLicense = new License();
imgLicense.setLicense(“C:\Development\CTS jar files\21.4\Aspose.Total.Java.lic”);

              Image image = Image.load("C:\\Development\\FLS\\09009e5e8c08682b.dwg.tif");
              
              TiffOptions cp = (TiffOptions)image.getOriginalOptions();
              
        System.out.println(cp.getCompression());
              cp.setBitsPerSample(new int[]{1});
          image.save("C:\\\\Development\\\\FLS\\\\09009e5e8c08682b-copy.dwg.tif", cp);
              
              
              
              PdfOptions pdfOpt = new PdfOptions();
              PdfCoreOptions coreOpt = new PdfCoreOptions();
              PdfDocumentInfo pdfInfo = new PdfDocumentInfo();
           pdfInfo.setAuthor("TietoEvry Norway");
        pdfOpt.setUseOriginalImageSize(true);

// pdfOpt.setPalette(null);
// coreOpt.setPdfCompliance(0);
// coreOpt.setCompression(PdfImageCompressionOptions.Ccitt4);
// pdfOpt.setResolutionSettings(null);
// ResolutionSetting rs = new ResolutionSetting();
// rs.
pdfOpt.setPdfCoreOptions(coreOpt);
pdfOpt.setPdfDocumentInfo(pdfInfo);
image.save(“C:\\Development\\FLS\\09009e5e8c08682b.dwg.pdf”, pdfOpt);

        } catch (Throwable e) {
              e.printStackTrace();
        }

  }

}

@dawittwe, we will investigate your issue and reply.

Hello, @dawittwe
Yes, In the old versions of Aspose.Imaging the error with Ccitt4 compression had existed. It was fixed.
As far as I know, PDF always stores images with a resolution 72x72 dpi, so we added an option setUseOriginalImageResolution(true); which recalculated the size accordingly to the original resolution.
If you need to use Ccitt4, please take the latest version of Aspose.Imaging.

Thanks a lot for the reply. I see, then that explains why that is not working.