Skip to main content
Participant
April 6, 2024
해결됨

Dynamic HTML to PDF how to declare JSON variables in the HTML - no documentation

  • April 6, 2024
  • 1 답변
  • 1608 조회

I cannot find ANY indication of how to insert placeholders for JSON values in the HTML code so that they populate with the JSON data when generating the PDF.
There is documentation on the Adobe Website for PDF creation from JSON template data on the WORD version {{variable}} but nothing on Dynamic HTML.
I am able to generate the PDF from the HTML but the JSON array I am passing does not change the text in the document.  
Can someone clarify the syntax/format of how to declare the JSON variables in HTML please?

JSON : {"PageContent": "Test"}
HTML : <!DOCTYPE html><html><body>{{PageContent}}</body></html>
PDF generated attached

    이 주제는 답변이 닫혔습니다.
    최고의 답변: Raymond Camden

    So, this is the API demo, https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/src/htmltopdf/dynamic-html-to-pdf.js, which references this zip: https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/resources/createPDFFromDynamicHtmlInput.zip,

    which if you download, shows how to include the JSON (script tag) and sample JS to use it. To be clear, we don't have requirements in that area, you can use it as you will, but you are responsible for using code to get the values and update the DOM.

     

    1 답변

    Raymond Camden
    Community Manager
    Community Manager
    April 6, 2024

    You don't, thats not the way this feature works. The idea is that you include a script tag, <script src='./json.js' type='text/javascript'></script>, in your HTML, and then you write JavaScript that access that via a window object. I believe the name is window.json. So everything you provided would be in that variable. Your code can then use DOM methods to update the code as you see fit. If you want to use tokens, like **name**, then you can use code to fnd and replace that with window.json.name. The point is, it's not automatic, you have to do the updates to the HTML with JavaScript.

     

    Personally, with the multiple JS template languages out there, I wouldn't use this feature. I'd do the HTML updating *before* you package up the HTML and send it to us to convert it to PDF.

    Participant
    April 7, 2024

    Raymond,
    If the PowerAutomate version works the same as the direct API version can you indicate where I can get a working code example of a ZIP archive that I can test with PowerAutomate? Or point me at some more detailed documentation that explains the process.

    Raymond Camden
    Community Manager
    Community Manager
    April 10, 2024

    So, this is the API demo, https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/src/htmltopdf/dynamic-html-to-pdf.js, which references this zip: https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/resources/createPDFFromDynamicHtmlInput.zip,

    which if you download, shows how to include the JSON (script tag) and sample JS to use it. To be clear, we don't have requirements in that area, you can use it as you will, but you are responsible for using code to get the values and update the DOM.