I am evaluating Aspose.PDF for Java to convert pdfs to tiff images in our organization.
I have received sample pdf and correct Tiff files from business which is required to be generated. Here is the metadata for the tiff file which is readable in our workflow system.
Correct_File_Metadata.png (30.7 KB)
I tried converting sample PDF to Tiff using aspose java sdk 19.8 using sample source code from aspose git repo and generated tiff has different metadata as follows.
Incorrect_File_Metadata.png (18.8 KB)
Our existing system is unable to read tiff files generated by aspose.pdf for Java sdk and based on metadata it seems I need to set StripOffset, RowsPerStrip properties.
In documentation of aspose.pdf for java, I don’t see any where how do I set StripOffset, RowsPerStrip and ImageSize settings so that I can generate correct Tiff.
Can you help me how do I set those properties and have same metadata as required ?
Here is Java source code.
public static void convertAllPDFPagesToTIFFImages(String pdfSourceFile, String tiffDestinationFolder, int dpi, String licensePath, int Bpp) throws IOException {
// Open document
Document pdfDocument = new Document(pdfSourceFile);
// License
com.aspose.pdf.License license = new com.aspose.pdf.License();
try {
license.setLicense(licensePath);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("Continuing as trial...");
}
int numberOfPages = pdfDocument.getPages().size();
if(com.aspose.pdf.Document.isLicensed()) {
System.out.println("License is set");
System.out.println("If license expires, only 4 pdf pages will be converted. Full version of pdf to tiff conversion will not work.");
}
else
{
numberOfPages = 4;
System.out.println("No license found, only 4 pdf pages will be converted. Full version of pdf to tiff conversion will not work.");
}
// Create Resolution object
Resolution resolution = new Resolution(dpi);
System.out.println(String.format("Resolution: %s", Integer.toString(dpi)));
// instantiate TiffSettings object
TiffSettings tiffSettings = new TiffSettings();
// set the compression of resultant TIFF image
tiffSettings.setCompression(CompressionType.CCITT4);
System.out.println(String.format("Compression: %s", "CCITT4"));
// set the color depth for resultant image
int colorDepth = ColorDepth.Format1bpp; // default 1 bit per pixel
if(Bpp == 4) {colorDepth = ColorDepth.Format4bpp;}
if(Bpp == 8) {colorDepth = ColorDepth.Format8bpp;}
tiffSettings.setDepth(colorDepth);
System.out.println(String.format("ColorDepth: %s (1 : 8bpp, 2 : 4bpp, 3 : 1bpp)", Integer.toString(colorDepth)));
// skip blank pages while rendering PDF to TIFF
tiffSettings.setSkipBlankPages(false);
System.out.println("Skip blank pages : False");
// Create TiffDevice object with particular resolution
TiffDevice tiffDevice = new TiffDevice(resolution, tiffSettings);
// Loop through number of pages of PDF file
Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
System.out.println("Conversion started:");
System.out.println(formatter.format(date));
for(int i=1; i<=numberOfPages; i++) {
// Create stream object to save the output image
java.io.OutputStream imageStream = new java.io.FileOutputStream(tiffDestinationFolder + "\\"+ String.format("Image_%sbpp_%sdpi_page%s.tiff", Integer.toString(Bpp), Integer.toString(dpi), Integer.toString(i)));
// Convert a all pages of PDF file to TIFF format
tiffDevice.process(pdfDocument, i, i, imageStream);
// Close the stream
imageStream.close();
System.out.print(".");
}
date = new Date();
System.out.println("Conversion completed:");
System.out.println(formatter.format(date));
System.out.println("Done.");
}