Consistent PdfSaveOptions across Aspose libraries

Dear Support,

I’m reaching out for assistance in understanding how the PdfSaveOptions/PdfOptions objects work across different Aspose libraries.

I’m currently implementing a Rendition Engine that converts various document formats to PDF. I am using the following Aspose libraries:

  • Aspose.Words for RTF/TXT/DOC/DOCX documents
  • Aspose.Slides for PPT/PPTX documents
  • Aspose.Cells for XLS/XLSX documents

Our client has specific requirements for the output PDF documents, such as a custom ‘PDF producer’ value, document resolution, format, compression, etc. So far, I have found settings for most of these elements only in Aspose.Cells, for example:

private void convertTable(Path inputPath, Path outputPath) throws Exception {
    com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(inputPath.toString());

    com.aspose.cells.PdfSaveOptions pso = new com.aspose.cells.PdfSaveOptions();
    pso.setImageResample(600, 100);
    pso.setProducer("Test company");
    pso.setPdfCompression(3);

    workbook.save(outputPath.toString(), pso);
}

After thoroughly reviewing the documentation and internal Aspose code, I have noticed that different Aspose libraries offer different customization options for PdfSaveOptions/PdfOptions. I can find these object, but they don’t have much settings I need, for example:

private void convertText(Path inputPath, Path outputPath) throws Exception {
    com.aspose.words.Document document = new com.aspose.words.Document(inputPath.toString());

    com.aspose.words.PdfSaveOptions pso = new com.aspose.words.PdfSaveOptions();

    document.save(outputPath.toString(), pso);
}

private void convertPres(Path inputPath, Path outputPath) {
    com.aspose.slides.Presentation presentation = new com.aspose.slides.Presentation(inputPath.toString());

    com.aspose.slides.PdfOptions po = new com.aspose.slides.PdfOptions();

    try {
        presentation.save(outputPath.toString(), SaveFormat.Pdf, po);
    } finally {
        presentation.dispose();
    }
}

Could you please advise if there is a universal approach that allows me to apply the same required settings across all document types?

I’m using an Aspose.Total license, so I have access to all your libraries.

Thank you in advance for your support!

@grigonaz

Could you please specify which specific settings you are looking to apply universally across all Aspose libraries for PDF conversion?

The most important settings are:

  • Custom PDF producer name
  • Output PDF format (1.4)
  • Resolution
  • Compression

@grigonaz,

You are correct that the PdfSaveOptions and PdfOptions classes differ among Aspose libraries, as each document format has its own rendering considerations. This is because each Aspose API is designed for different file formats, which have distinct architectures and structures. Unfortunately, there is no single universal PDF saving options or settings (PdfSaveOptions/PdfOptions) that can be applied across all Aspose libraries. However, you can create a common abstraction implementation in your Rendition Engine to standardize settings where feasible. Additionally, since Aspose does not provide a universal PdfSaveOptions, the most effective strategy is to abstract the differences into a helper class and apply equivalent settings to each library whenever possible. You might also want to consider post-processing the final PDF using the Aspose.PDF API to modify metadata such as the producer, PDF version, and other elements.

My colleagues from the Aspose.Words and Aspose.Slides teams will evaluate this and provide further assistance shortly.

1 Like

@grigonaz,
As for Aspose.Slides,

Please note that you cannot set values for the Application and Producer fields, because Aspose Ltd. and Aspose.Slides for Java x.x.x will be displayed for these fields.

API Limitations|Aspose.Slides Documentation
Presentation Properties|Aspose.Slides Documentation

You can use the PdfOptions to apply these settings. The following code example shows you how to do this.

Presentation presentation = new Presentation("sample.pptx");

PdfOptions pdfOptions = new PdfOptions();
pdfOptions.setCompliance(PdfCompliance.PdfA1b); // or PdfA1a
pdfOptions.setSufficientResolution(300);
pdfOptions.setTextCompression(PdfTextCompression.Flate);
pdfOptions.setJpegQuality((byte)90);

presentation.save("output.pdf", SaveFormat.Pdf, pdfOptions);
presentation.dispose();

Convert PowerPoint to PDF in Java|Aspose.Slides Documentation

1 Like

@grigonaz In Aspose.Words PdfSaveOptions you cannot specify PDF document generator name, though you can disable exporting generator name using ExportGeneratorName.

You can set PDF compliance using PdfSaveOptions.Compliance property. You can use PdfSaveOptions.DownsampleOptions property to change the resolution of images in the PDF document.
PdfSaveOptions.TextCompression property can be used to specify PDF text compression.

1 Like