I am trying to add information dynamically in the ...
# ask-stanley-ai
v
I am trying to add information dynamically in the header of an Advanced PDF template using a loop. However, I am unable to display data specific to each page correctly. How can I ensure that only the relevant data for the current page is added to the header? Any guidance or examples would be greatly appreciated. Thanks!
Copy code
<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>

 <#assign salesOrders = salesOrders?eval />
<#list salesOrders.salesOrders as order>

                <tr>        
                    <td colspan="1"></td>
                    <td colspan="2" align="left">Date: ${order.trandate}</td>
                </tr>

                 <tr>
                  <td colspan="1"></td> 
                  <td colspan="2" align="left">Order: ${order.tranid}</td>
                </tr>

				<tr>
                    <td colspan="1"></td>                          
                    <td colspan="2" align="left"><pagenumber/> of <totalpages/></td>
                </tr>

                 </#list>

</head>
<body>
 <#assign salesOrders = salesOrders?eval />
    <#list salesOrders.salesOrders as order>
</#list>
</body>
</pdf>
c
AI generated answer (using internal Slack threads):
Based on the conversations, it seems that you are trying to add dynamic information to the header of an Advanced PDF template using a loop. However, you are facing issues with displaying data specific to each page correctly. The issue you are facing might be due to the placement of your loop. In your current code, you are looping through the sales orders in the header section. This means that for each sales order, a new header is created, which might not be what you want. Instead, you should consider moving the loop to the body section of the PDF. This way, each sales order will be processed and displayed on its own page, with the header information remaining constant. Here is a simplified example:
Copy code
xml
<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
    <macrolist>
        <macro id="nlheader">
            <table>
                <tr>
                    <td colspan="1"></td>
                    <td colspan="2" align="left">Date: ${.vars["currentDate"]}</td>
                </tr>
                <tr>
                    <td colspan="1"></td>
                    <td colspan="2" align="left">Order: ${.vars["currentOrder"]}</td>
                </tr>
                <tr>
                    <td colspan="1"></td>
                    <td colspan="2" align="left"><pagenumber/> of <totalpages/></td>
                </tr>
            </table>
        </macro>
    </macrolist>
</head>
<body header="nlheader" header-height="10%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter">
    <#assign salesOrders = salesOrders?eval />
    <#list salesOrders.salesOrders as order>
        <#assign currentDate = order.trandate />
        <#assign currentOrder = order.tranid />
        <!-- Your body content here -->
    </#list>
</body>
</pdf>
In this example, the loop is moved to the body section. For each sales order, the
currentDate
and
currentOrder
variables are updated. These variables are then used in the header macro to display the current date and order number. Please note that this is a simplified example and you might need to adjust it according to your specific requirements. ****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.826057374
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.814309597
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.806189299
Please provide your feedback on this answer.