1

I have asked this question on https://community.adobe.com/ and have not received an answer. If I do, I will include the response here.

I am able to create a pdf using the basic approach outlined by adobe at https://developer.adobe.com/document-services/docs/overview/document-generation-api/

Ideally, I don't want to have to send the base docx word document across in the api call each time I generate a new pdf. I would rather host the docx which can be retrieved at document generation time. One approach would be a reference url to a docx hosted on acrobat.adobe.com. At the moment I have to send the docx as well as the json data which seems inefficient.

I am using https://cpf-ue1.adobe.io/ops/:create

"cpf:inputs":{ "documentIn":{ "dc:format":"application/vnd.openxmlformats-officedocument.wordprocessingml.document", "cpf:location":"InputFile0" },

I guess if it can't be done, then that's okay, I just would like to know so I can implement accordingly.

thank you

Thomas
  • 11
  • 1

1 Answers1

2

the API endpoint you mentioned is deprecated and we have a new set of REST endpoints that support that. You can find the documentation for our new REST APIs here: https://developer.adobe.com/document-services/docs/apis/. You can find an introductory blog post here: https://blog.developer.adobe.com/announcing-the-new-adobe-document-services-rest-apis-8d85951176cf

Now, to your specific use case of re-using a Word doc, you can do that for up to 24 hours with one asset. Basically you upload the Word doc and then use the asset ID for multiple document generation calls.

I describe this process in detail here, https://medium.com/adobetech/multiple-performant-operations-with-the-new-adobe-document-services-rest-apis-7e56bec336af, but since SO doesn't like linking to existing stuff like that, I'll replicate it here a bit. :)

So basically, after the authenticating, you:

  • Ask for an upload URL, specifying the type, in this case application/vnd.openxmlformats-officedocument.wordprocessingml.document.
  • When given the URL, you POST your Word document up to it.
  • You then create a Document Generation job, which involves using the asset ID from the first step, and passing in your JSON data. Here's an example of a function that wraps this:
async function createDocumentGenerationJob(asset, outputFormat, data, clientId, token) {
    let body = {
        'assetID': asset,
        'outputFormat': outputFormat, 
        'jsonDataForMerge':data
    };
    body = JSON.stringify(body);

    let req = await fetch(REST_API+'operation/documentgeneration', {
        method:'post',
        headers: {
            'X-API-Key':clientId,
            'Authorization':`Bearer ${token}`,
            'Content-Type':'application/json'
        },
        body: body
    });

    return req.headers.get('location');
}
  • The result of the job creation API endpoint is a URL you can check for status, so keep checking that...
  • And when done, you'll be given a URL to download the result PDF.

If any of this doesn't make sense, just let me know.

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • 1
    Thank you! `application/vnd.openxmlformats-officedocument.wordprocessingml.document` was what I needed. `application/msword` is what I used before and it didn't work. Thanks again! – PhillipJacobs Jul 18 '23 at 07:29