Я работаю над проектом Java, в котором мне нужно уменьшить размер файла PDF. Я использую PDFBox /itextPdf для обработки PDF-файлов, но не знаю, как оптимизировать или сжать PDF-файл, чтобы уменьшить его размер.
PdfReader reader = new PdfReader(inputPdf);
// Use a ByteArrayOutputStream for the compressed PDF output
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
// Use the PdfStamper for incremental saving
PdfStamper stamper = new PdfStamper(reader, outputStream);
// Set full compression
stamper.setFullCompression();
// Close the stamper to finalize the PDF
stamper.close();
} finally {
// Always close the reader in a finally block to avoid resource leaks
reader.close();
}
// Return the compressed PDF as a byte array
return outputStream.toByteArray();
Подробнее здесь: https://stackoverflow.com/questions/790 ... -libraries