Skip to main content
Participant
Mar 7, 2024 7:57 AM UTC
Answered

How to programmatically generate interactive pdf documents?

Hello,
A. I would like to generate interactive pdf documents, having

* several combo boxes and, depending on user selection:

* show/hide some diagrams/maps

 

The pdf standard seems to support all that is needed for this:

form elements, optional content groups (OCGs), Layers and JavaScript to handle actions

=> What is the recommented way to "program" pdf documents? (I do not want to manully create them but need some automated workflow, where I can easily update the data etc. ) 

B. First I tried to use pymypdf but faced issues with enabling/showing OCGs:
https://github.com/pymupdf/PyMuPDF/discussions/3195

C. I also tried to use the node.js Services API (see code excample below). However, that API only seems to support convertion of *.docx, *.html content etc. instead of detailed ways to construct pdf 
documents from scratch / from its "low level building blocks"?
If the service api  supports what I am looking for, where can I find the documentation?

D. If the services api does not support this:
Is there an alternative to Services API that is thought for that purpose? 

Example to use node.js services api to create some pdf document:

const PDFServicesSdk = require('@adobe/pdfservices-node-sdk');

const id = "your client id";
const secret = "your secret credential";

let outputFilePath = 'demo.pdf';

const credentials = PDFServicesSdk.Credentials
.servicePrincipalCredentialsBuilder()
.withClientId(id)
.withClientSecret(secret)
.build();


const executionContext = PDFServicesSdk.ExecutionContext.create(credentials);
const createPdfOperation = PDFServicesSdk.CreatePDF.Operation.createNew();

//demo.docx currently is an empty document; did not find an example on how to
//construct pdf documents with services api from scratch
const input = PDFServicesSdk.FileRef.createFromLocalFile('demo.docx');
createPdfOperation.setInput(input);

createPdfOperation.execute(executionContext)
//.then(result => {
// const createOcgParams = {
// name: 'MyOptionalContentGroup',
// visibilityPolicy: 'VISIBLE',
// members: [], // Add your desired members here
// };
    // how to create form elements, ocgs, include javascript?
// return executionContext.createOCG(createOcgParams);
})
.then(result => result.saveAsFile(outputFilePath))
.catch(err => {
if(err instanceof PDFServicesSdk.Error.ServiceApiError
|| err instanceof PDFServicesSdk.Error.ServiceUsageError) {
console.log('Exception encountered while executing operation', err);
} else {
console.log('Exception encountered while executing operation', err);
}
});



    This topic is closed to new replies. Start a new post to keep the conversation going.
    Joel Geraci
    Joel GeraciCorrect answer
    Community Expert
    Mar 7, 2024 4:41 PM UTC

    At this time, the API does not support any form of PDF interactivity.

    2 replies

    Joel Geraci
    Community Expert
    Joel GeraciCommunity ExpertCorrect answer
    Community Expert
    Mar 7, 2024 4:41 PM UTC

    At this time, the API does not support any form of PDF interactivity.

    Translate
    Participant
    Mar 7, 2024 6:55 PM UTC

    Thank you for clarification

    Translate