Does aspose.words support OptimizeForWeb when convert word to pdf?

does aspose.words support OptimizeForWeb when convert word to pdf? after search we found OptimizeForWeb for c++. Does the setOptimizeOutput(true) equals OptimizeForWeb for c++?

@softboy

Cause

Aspose.Words does not have a direct property named “OptimizeForWeb” for PDF conversion. However, it provides various options to optimize the output when saving documents as PDFs.

Solution

To achieve web optimization when converting a Word document to PDF, you can use the PdfSaveOptions class. This class allows you to set various properties that can help reduce the file size and improve loading times, such as image compression, font embedding options, and downsampling images.

Code

Here’s a sample code snippet demonstrating how to configure PdfSaveOptions for optimizing a Word document for web use:

import com.aspose.words.*;

public class OptimizeForWebExample {
    public static void main(String[] args) throws Exception {
        // Load the document
        Document doc = new Document("input.docx");

        // Create PdfSaveOptions
        PdfSaveOptions options = new PdfSaveOptions();
        
        // Set image compression to reduce file size
        options.setImageCompression(PdfImageCompression.Jpeg);
        options.setJpegQuality(75); // Adjust quality as needed

        // Enable downsampling of images
        DownsampleOptions downsampleOptions = new DownsampleOptions();
        downsampleOptions.setDownsampleImages(true);
        downsampleOptions.setResolution(150); // Set desired resolution
        options.setDownsampleOptions(downsampleOptions);

        // Save the document as PDF
        doc.save("output.pdf", options);
    }
}

Next Steps

  1. Adjust the jpegQuality and resolution values in the code to find the right balance between quality and file size.
  2. Test the output PDF in different web environments to ensure it meets your needs.
  3. Review the Aspose documentation for more details on PdfSaveOptions and other related properties to further refine your PDF output.

If you have any further questions or need additional assistance, feel free to ask!

after search we found OptimizeForWeb for c++. Does the setOptimizeOutput(true) equals OptimizeForWeb for c++? do you mean there is no way to open the mode currently?

@softboy I suppose under OptimizeForWeb you mean PDF linearization or “Fast Web View” option. After careful evaluation, we have decided not to implement PDF linearization (“Fast Web View”) at this time due to:

  1. Low Demand – Minimal customer requests over 11 years there were only few request of this feature.
  2. High Implementation Cost – Would require:
    • Rewriting our single-pass PDF renderer to multi-pass
    • Significant memory management changes Risk of performance degradation in core workflows
  3. Existing Workarounds – Customers can easily linearize output using:
    • Standard tools (qpdf, Adobe Acrobat)
    • Simple post-processing scripts