LINQ Expressions Not Working When Saving as PDF in Aspose.Words

Description

I am using Aspose.Words for Java to generate documents with LINQ Reporting Engine. The LINQ expressions are processed correctly when saving the document as DOCX, but when saving as PDF, the expressions are not evaluated, and the raw placeholders appear in the output.

Code Snippet

ReportingEngine reportingEngine = new ReportingEngine();
reportingEngine.buildReport(doc, ds.values().toArray(), ds.keySet().toArray(new String[0]));

SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.fromName("PDF"));
doc.save(out, saveOptions);

Observed Behavior

  • DOCX Output → Works correctly (LINQ expressions are evaluated).
  • PDF Output → LINQ expressions remain as placeholders instead of being replaced with actual values.

Additional Notes

  • I also tried explicitly calling:
    doc.updateFields();
    doc.updatePageLayout();
    doc.cleanup()
    
  • I attempted using PdfSaveOptions with different settings.

But it didn’t solve the issue - the LINQ expressions still remain unprocessed in the PDF.

@MindControl Such problem might occur if document layout is cached before the document is filled with data. For example if you call Document.updateFields or Document.updatePageLayout before building the report. Please try calling Document.updatePageLayout just before saving the document as PDF. This must help.
If not, please attach your sample input, data, output and code that will allow us to reproduce the problem. We will check the issue on our side and provide you more information.

1 Like

Hi Alexey.
Yes, as I mentioned I have already tried:

doc.updateFields();
doc.updatePageLayout();
doc.cleanup()

What other code is needed? It’s just a simple LINQ expression. The thing is, everything works perfectly when saving to DOCX, but nothing works at all with PDF. The source template is, of course, in DOCX.

@MindControl Could you please provide you input document, sample data, code that you use and the problematic output documents? We will test your scenario on our side and provide you more information.

1 Like

@alexey.noskov sure, please check:
How I pass the values to engine:

public void generateLinq(ReportRequest request, Document doc, OutputStream out) throws Exception {
    Map<String, Object> ds = new HashMap<>();
    ds.putAll(chartHandler.handleLinq(request.getCharts()));
    reportingEngine.buildReport(doc, ds.values().toArray(), ds.keySet().toArray(new String[0]));
    SaveOptions saveOptions = SaveOptions.createSaveOptions(SaveFormat.fromName(request.getFileType().name()));
    doc.save(out, saveOptions);
}

The engine initialization config:

@Bean
public ReportingEngine reportingEngine() {
    ReportingEngine engine = new ReportingEngine();
    engine.setOptions(ReportBuildOptions.ALLOW_MISSING_MEMBERS);
    engine.setMissingMemberMessage(StringUtils.EMPTY);
    engine.getKnownTypes().add(Integer.class);
    engine.getKnownTypes().add(Float.class);
    engine.getKnownTypes().add(Double.class);
    engine.getKnownTypes().add(ArrayList.class);
    engine.getKnownTypes().add(HashMap.class);
    engine.getKnownTypes().add(ArrayValue.class);
    engine.getKnownTypes().add(ReportRequest.class);

    return engine;
}

The sample data:|

[
    {
        "entity": "United States",
        "value": 100
    },
    {
        "entity": "Germany",
        "value": 20
    },
    {
        "entity": "London",
        "value": 50
    },
    {
        "entity": "London",
        "value": -40
    },
    {
        "entity": "London",
        "value": 130
    },
    {
        "entity": "London",
        "value": -60
    },
    {
        "entity": "London",
        "value": 70
    }
]

Please find below the LINQ template, the succeeded DOCX file and failed PDF file:
Waterfall chart LINQ template.docx (78.5 KB)
DOCX result (success).docx (48.8 KB)
PDF result (failed).pdf (37.6 KB)

@MindControl
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): WORDSNET-28168

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like