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

Create PDF from dynamic HTML

New Here ,
Aug 21, 2023 Aug 21, 2023

Copy link to clipboard

Copied

Hi Team, I need to create pdf from dynamic html.
So I have HTML file, inline CSS and json data.

How I can  use new rest API's to create PDF.
I tried following steps - 
1.Create a zip file from html, css and json file.

2.Generate access token.

2.Upload them to adobe cloud and get asset ID.

3.Call api- https://pdf-services-ue1.adobe.io/operation/htmltopdf

but it's not working.

Can any one help me on this? As new rest api documentation is not clear

TOPICS
PDF Services API

Views

484

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 Expert ,
Aug 21, 2023 Aug 21, 2023

Copy link to clipboard

Copied

Are you bundling the JSON in the ZIP? If you run the index.html file from localhost does it display properly?

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
New Here ,
Aug 21, 2023 Aug 21, 2023

Copy link to clipboard

Copied

Yes, I am builiding json in zip.
Yes, If I run index.html from localhost it displaying properly.

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
New Here ,
Aug 21, 2023 Aug 21, 2023

Copy link to clipboard

Copied

My steps - 

1.To get access token
 
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'client_id=<client_id>' \
--data-urlencode 'client_secret=<client_secret>'
 
resp - it is returning access-token
 
2.To get upload URI and asset id
 
curl --location --request POST 'https://pdf-services.adobe.io/assets' \
--header 'X-API-Key: <client_id>' \
--header 'Authorization: Bearer <access_token>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "mediaType": "application/json"
}'
 
resp - upload_uri and assest_id
 
3.to upload file
 
curl -i --location -g --request PUT '<presigned upload url>' \
--header 'Content-Type: application/json' \
--data-binary '<zip_file_path>'
 
resp - status - 200
 
4.To create pdf
 
curl -i --location --request POST 'https://pdf-services.adobe.io/operation/htmltopdf' \
--header 'x-api-key: <client_id>' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <access_token>' \
--data-raw '{
    "assetID": "<assest_id>",
    "json": "{}"
    "includeHeaderFooter": true,
    "pageLayout": {
        "pageWidth": 11,
        "pageHeight": 8.5
    }
}'
 
 
resp - HTTP/1.1 400 Bad Request
{"reason":"Validation error Request id: wdqkjdc.","message":"Bad Request"}

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
New Here ,
Aug 22, 2023 Aug 22, 2023

Copy link to clipboard

Copied

Hi, Joel_Geraci, can you please check my comments and update as I have to complete this ASAP.

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 Expert ,
Aug 22, 2023 Aug 22, 2023

Copy link to clipboard

Copied

If you are bundling the JSON in the ZIP, you don't need the json parameter. 

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
New Here ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

I am passing json inside json.js file. can you please tell me better way to do that or it's better if you provide me a example to create pdf from dynamic html.
Thanks

 

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
New Here ,
Aug 23, 2023 Aug 23, 2023

Copy link to clipboard

Copied

Hi Joel, Thanks for your response.
I didn't pass json parameter then I am getting response - 

{'error': {'code': 'INVALID_ZIP', 'message': 'The zip file provided has invalid content.; requestId=2lFWxNqrJzC4zWxJ4hW3JCpf0eRPSN3l', 'status': 400}, 'status': 'failed'}

can you please provide valid content type? as it didn't mention clearly in documents.
Thanks

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 Expert ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

When creating a ZIP for a set of files, it's very common to select the folder and ZIP it. That's the exact wrong way to do it for this use case though. The index.html file needs to be at the top level of the ZIP file. To do this, do not select the folder. Instead, open the folder, select all of the folder contents, and compress that.

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
New Here ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

Yes Joel, I am creating zip in the same way (open the folder, select all of the folder contents, and compress) as you are telling as we were using same in older apis.
But I am getting content-type issue. As of now I am using content-type - application/json for all apis.

Can you tell me which content type should I use?

 

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
New Here ,
Aug 29, 2023 Aug 29, 2023

Copy link to clipboard

Copied

Hi @joel

I am using the file provided in github as example than also getting 

{'error': {'code': 'INVALID_ZIP', 'message': 'The zip file provided has invalid content.; requestId=mLcoPS2zId7XPi6dwpsyJqd2thxxSG5Q', 'status': 400}, 'status': 'failed'}

can you please help me on this.

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 Expert ,
Aug 31, 2023 Aug 31, 2023

Copy link to clipboard

Copied

LATEST

I think I see it now. In step 2, you may need to set the Content-Type to application/zip

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