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

Using the HTMltoPDF API with Python Requests

New Here ,
Sep 08, 2022 Sep 08, 2022

Copy link to clipboard

Copied

Hi,

 

I'm trying to convert a local HTML file to a PDF using the htmlToPDF API.

 

I'm able to hit the API successfully using a CURL, but I'm running into a weird error when sending my request using the python.requests library:

{"cpf:status":{"completed":true,"type":"Invalid papi Engine","title":"Invalid engines input for papi request ","status":400,"report":"{\"error_code\":\"INVALID_REQUEST\"}"}}

Is there a successful POST implementation with a file I can mimic to help diagnose the issue? Here's my full code:

 

import requests
import json



BEARER="Bearer {{Token}}"
API_KEY = "{{client_secret}}"

requestUri = 'https://cpf-ue1.adobe.io/ops/:create?respondWith%3D%7B%22reltype%22%3A%20%22http%3A%2F%2Fns.adobe.com%2Frel%2Fprimary%22%7D'
headers = {
    'Authorization': BEARER,
    'x-api-key' : API_KEY,
    'Accept': "application/json, text/plain, */*",
    'Prefer': "respond-async,wait=0"
}





def makeRequest(inputHtmlFilePath, outputPdfFilePath):

    contentAnalyzerRequests = json.dumps({
        "cpfengine": {
            "repo:assetId": "urn:aaid:cpf:Service-e2ee120a2b06427cb449592f5db967e7"
        },
        "cpf:inputs": {
            "documentIn": {
                "dc:format": "text/html",
                "cpf:location": "InputFile0"
            }
        },
        "cpf:outputs": {
            "documentOut": {
                "dc:format": "application/pdf",
                "cpf:location": outputPdfFilePath
            }
        }
    })

    with open(inputHtmlFilePath, 'rb') as inFile:
        print(inFile.read)

        payload = {
            'contentAnalyzerRequests': contentAnalyzerRequests,
            'InputFile0': inFile
        }
    
        response = requests.post(requestUri, files=payload, headers=headers)
        print(response.text)
        print(response.json())

    return ()


makeRequest('out.html', 'testadobe.pdf')

 

TOPICS
PDF Extract API , PDF Services API

Views

181

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
no replies

Have something to add?

Join the conversation
Resources