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

Convert Dynamic HTML Resources to a PDF File using REST API

Community Beginner ,
Oct 30, 2023 Oct 30, 2023

Copy link to clipboard

Copied

I am trying to convert a dynamic HTML to PDF using Adobe PDF Services API as per the documentation - https://developer.adobe.com/document-services/docs/apis/#tag/Html-to-PDF/operation/pdfoperations.htm...

 `index.html` is trying to read data from a `json` file which is present within the same directory. When I am uploading the zip to `Upload Assets` API, it is all in the right file structure. However, the generated PDF is not displaying the contents.

I can open the html from localhost and it displays the content properly within a browser. I have uploaded a sample dataset that I used for my testing.

TOPICS
PDF Services API

Views

1.2K

Translate

Translate

Report

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 ,
Oct 31, 2023 Oct 31, 2023

Copy link to clipboard

Copied

I don't see the attached zip. If it's blocked, maybe email me at raymondcamden@gmail.com. If the zip isn't exactly right, it won't work.

Votes

Translate

Translate

Report

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
Community Beginner ,
Oct 31, 2023 Oct 31, 2023

Copy link to clipboard

Copied

I couldn't attach the zip file since it is not an allowed extension, I have sent an email.

Votes

Translate

Translate

Report

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 ,
Nov 01, 2023 Nov 01, 2023

Copy link to clipboard

Copied

I did some investigation and from what I can see, using fetch(), as the author did here, will not work with local assets. I was unable to fetch anything contained in the zip file. I was, however, able to fetch a remote API. 

 

I'll file a bug report about documenting this.

 

Now that being said, you could replace your existing JavaScript code and use local server code to get the same result. Given an html file index.html and some data, you could load in the file into a string variable, and your data, and add it that way. In your code you're appending to a div. There is a library, cheerio, that will let you find and manipulate HTML in Node. But you could literally do a regex as well. 

Votes

Translate

Translate

Report

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
Community Beginner ,
Nov 01, 2023 Nov 01, 2023

Copy link to clipboard

Copied

load in the file into a string variable, - that is what I am doing right now! I created this sample to be shared on the community, my actual use case is a huge JSON payload that is fetched from a remote backend server. Is there any other way to read the contents of the JSON file into the HTML that works with the API ? All the samples shared on Adobe github SDKs do not have any examples to read the data from json.js as they mention in the docs.

Votes

Translate

Translate

Report

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 ,
Nov 02, 2023 Nov 02, 2023

Copy link to clipboard

Copied

LATEST

Well technically, that isn't what you are doing now. Right now you send the zip that includes HTML and a JSON file, and you use JS to fetch the JSON and try to work with it. That's _different_ from the API we have that lets you pass in a zip file, and a _separate_ set of JSON data. When you use that feature (documented here, https://developer.adobe.com/document-services/docs/overview/pdf-services-api/howtos/create-pdf/#crea...), the JSON is added to a window object variable. Your HTML must do this as well:

 

<script src='./json.js' type='text/javascript'></script>

 

But the JSON isn't zipped up, it's included in the API call. The window object you use is window.json. If you download this, https://github.com/adobe/pdfservices-node-sdk-samples/blob/master/resources/createPDFFromDynamicHtml... you can see an example of it.

Votes

Translate

Translate

Report

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