Hi!
I’m having an issue while converting a TIFF document to PDF using the Aspose.PDF library. The problem is that the output PDF size is much larger than the input TIFF size. Specifically, it increases from 756 KB to 5,925 KB, which is a significant difference.
I have tried to find a solution on this forum, but none of the methods have worked for me. Below, I’m sending a portion of the code responsible for optimizing the conversion process:
private String exportFormat = "v_1_7";
private int quality = 70;
private int resolution = 96;
//...
private void setDocumentFormat(Document pdfDocument, String exportFormat) {
if (!exportFormat.isBlank()) {
try {
int formatInt = (int) PdfFormat.getValue(PdfFormat.class, exportFormat);
pdfDocument.convert(new PdfFormatConversionOptions(formatInt));
LOGGER.info("Document format was set to {}", exportFormat);
} catch (IllegalArgumentException e) {
LOGGER.error("Invalid PDF format specified: {}", exportFormat);
throw new NnpMigrationDocToolsException("Invalid PDF format specified: " + exportFormat, e);
}
}
}
private void setDocumentQuality(Document pdfDocument, int quality, int resolution) {
if (0 < quality && quality <= 100) {
OptimizationOptions optOptions = new OptimizationOptions();
optOptions.getImageCompressionOptions().setCompressImages(true);
optOptions.getImageCompressionOptions().setImageQuality(quality);
optOptions.getImageCompressionOptions().setMaxResolution(resolution);
optOptions.setRemoveUnusedObjects(true);
optOptions.setUnembedFonts(true);
pdfDocument.optimizeResources(optOptions);
LOGGER.info("Document '{}': PDF quality was set to {}", this.documentLogName, quality);
} else {
LOGGER.error("Document '{}': Invalid quality value! It can only be in the range from 1 to 100, inclusively.", this.documentLogName);
throw new NnpMigrationDocToolsException("Invalid quality value! It can only be in the range from 1 to 100, inclusively.");
}
}
I have attached the relevant TIFF and PDF files for your review. Could you assist me in resolving this issue? If there is a known bug or if I’m missing a step in the process, any guidance or workaround would be greatly appreciated.
tiff_to_pdf.zip (5.7 MB)
Environment Details:
- Aspose.PDF for Java version: 20.12
- Java version: 11
- Operating System: Windows
Thank you!