Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

New Here ,
Apr 06, 2024 Apr 06, 2024

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

1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Employee , Apr 10, 2024 Apr 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 a

...
Translate
Adobe Employee ,
Apr 06, 2024 Apr 06, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2024 Apr 07, 2024

Raymond
Thanks for the reply however I forgot to mention one extra detail.  I'm using the Adobe "Dynamic HTML to PDF" connector action in Microsoft Power Automate not via direct access tot eh API.  There is no mention anywhere of using an embedded json.js file and apart from indicating that the HTML file must be inside a ZIP file (which I have done) .. even the Adobe limited documentation fails to refer to Javascript in any shape or form

https://learn.microsoft.com/en-us/connectors/adobepdftools/#convert-dynamic-html-to-pdf

I've used the WORD version generating a PDF from a template and all the placeholder tags work perfectly so had made a fairly simple assumption that the HTML to PDF connector had similar functiobality
https://learn.microsoft.com/en-us/connectors/adobepdftools/#generate-document-from-word-template

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 10, 2024 Apr 10, 2024

Yeah, I agree our docs need to be improved for this use case. So outside of that though, are you ok now?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 07, 2024 Apr 07, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Employee ,
Apr 10, 2024 Apr 10, 2024
LATEST

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

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources