Skip to main content
Known Participant
July 14, 2021
Question

conditional-section does not work in header

  • July 14, 2021
  • 2 replies
  • 1846 views

I am currently trying out the Document Generator service as part of a POC for a current project and ran into what I believe is a bug.  The conditional-section syntax is not being parsed if it is part of a Word header section.  If I place it in the body of the document it works, but if I move it up into the header it just outputs the syntax rather than evaluating it.  Other tags are evaluated, just not the conditional-section tag.

    This topic has been closed for replies.

    2 replies

    Known Participant
    July 15, 2021

    Thank you for confirming.  Please let me know when you have an ETA on the fix.

    Community Manager
    July 15, 2021

    Update:  I just heard back from the internal team.  It looks like it's technically not a bug.  We currently don't support conditionals in headers or footers, but are working to get the feature added to our backlog.  We will definitely keep you informed. 

    Known Participant
    July 15, 2021

    Ok - it's definitely a deal breaker for us, so if there is anyway to get an ETA on a fix anytime soon, I would appreciate it.  Otherwise we will likely have to choose a different technology.  I would think it would be an issue for lots of customers given the use case I mentioned on the phone.  Usually mail merges have a customer address in a header section, and some of that information (e.g. multiple address lines) is nullable.  We will actually have the same issue with many of our footers, which often display addresses from different companies that can have a varying numbers of address lines.

    Known Participant
    July 14, 2021
    /*
     * Copyright 2021 Adobe
     * All Rights Reserved.
     *
     * NOTICE: Adobe permits you to use, modify, and distribute this file in
     * accordance with the terms of the Adobe license agreement accompanying
     * it. If you have received this file from a source other than Adobe,
     * then your use, modification, or distribution of it requires the prior
     * written permission of Adobe.
     */
    
    const PDFServicesSdk = require('@adobe/pdfservices-node-sdk'),
        fs = require('fs');
    
    /**
     * This sample illustrates how to merge the Word based document template with the input JSON data to generate
     * the output document in the PDF format.
     * <p>
     * To know more about document generation and document templates, please see the <a href="http://www.adobe.com/go/dcdocgen_overview_doc">documentation</a>
     * <p>
     * Refer to README.md for instructions on how to run the samples.
     */
    try {
        // Initial setup, create credentials instance.
        const credentials =  PDFServicesSdk.Credentials
            .serviceAccountCredentialsBuilder()
            .fromFile("pdfservices-api-credentials.json")
            .build();
    
        // Setup input data for the document merge process
        const jsonString = fs.readFileSync('resources/salesOrder.json'),
            jsonDataForMerge = JSON.parse(jsonString);
    
        // Create an ExecutionContext using credentials
        const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
    
        // Create a new DocumentMerge options instance
        const documentMerge = PDFServicesSdk.DocumentMerge,
            documentMergeOptions = documentMerge.options,
            options = new documentMergeOptions.DocumentMergeOptions(jsonDataForMerge, documentMergeOptions.OutputFormat.PDF);
    
        // Create a new operation instance using the options instance
        const documentMergeOperation = documentMerge.Operation.createNew(options)
    
        // Set operation input document template from a source file.
        const input = PDFServicesSdk.FileRef.createFromLocalFile('resources/conditionalBugDemoTemplate.docx');
        documentMergeOperation.setInput(input);
    
        // Execute the operation and Save the result to the specified location.
        documentMergeOperation.execute(executionContext)
            .then(result => result.saveAsFile('output/conditionalBugDemoOutput.pdf'))
            .catch(err => {
                if(err instanceof PDFServicesSdk.Error.ServiceApiError
                    || err instanceof PDFServicesSdk.Error.ServiceUsageError) {
                    console.log('Exception encountered while executing operation', err);
                } else {
                    console.log('Exception encountered while executing operation', err);
                }
            });
    } catch (err) {
        console.log('Exception encountered while executing operation', err);
    }