Find below sample Java code to convert Word document to PDF and compress images to reduce the DPI resolution to 150 DPI suing Qoppa’s PDF library jOfficeConvert. Images from the original Word document that have a resolution higher than 150 will be resized down to 150 DPI in the resulting PDF document. Other images will be left untouched.
By default, MaxDPI option is set to zero which signifies that images will retain their original resolution from the original Word document.
This feature is coming in jOfficeConvert v2021R1 planned for release in June 2021.
import com.qoppa.office.WordConvertOptions; import com.qoppa.office.WordDocument; public class WordDPISample { public static void main(String[] args) { try { // Create a new WordConvertOption // and set the max dpi to 150 WordConvertOptions opts = new WordConvertOptions(); opts.setMaxDPI(150); // Open and convert the Word document to PDF using the options above WordDocument wordDoc = new WordDocument("C:/test.docx", opts); // Save the PDF file wordDoc.saveAsPDF("C:/test.pdf"); } catch (Exception ex) { ex.printStackTrace(); } } } |