Prerequisites
- Access to Domo’s Pro-Code Editor.
- To get access to the beta, please reach out to your CSM.
- Basic understanding of JavaScript and the HTML2PDF.js library.
- Code engine enabled in your Domo instance.
Step 1: Set Up Your Pro-Code Environment
- Create a New Project in Pro-Code Editor:



Step 2: Define the Manifest File (manifest.json)
The manifest.json file defines your app’s metadata and data mappings in Domo. Update it according to your dataset’s structure.

Step 3: Handling PDF Generation within Code Engine
3.1. Setup Code Engine
- Navigate to WorkFlows in your environment and, on the left side, click on the Code Engine icon.


- Create a new Code Engine package, use Javascript as the language.


- Everytime you want to use the function, you have to save it and deploy it. Click on the arrow next to the save button on the upper right corner, and click on Deploy.

3.2. Setup Code Engine Helpers
- Import Code Engine:
- Start by importing the
codeenginemodule, which will handle all the API requests within your Code Engine function. - Define a
Helpersclass that includes a method for making HTTP requests (handleRequest). This method will streamline how API calls are made and manage any errors that might occur during the process.
- Start by importing the
3.3. Retrieve Cards from a Page
- Function:
getCardsOnPage:- This function retrieves all the cards on a given page by calling the
/api/content/v1/pages/{pageID}/cardsendpoint. - It utilizes the
Helpers.handleRequestmethod to make the API call and returns the list of cards.
- This function retrieves all the cards on a given page by calling the
- Set up the inputs and outputs of the function.
Input Parameters
pageID: string
OUTPUT Parameters
result: array

3.4. Generate PDF for Each Card
- Function:
getPDF:- This function is responsible for generating a PDF for a specific card using the card’s ID.
- It makes a
PUTrequest to the/api/content/v1/cards/kpi/{cardID}/renderendpoint, passing any necessary parameters, such as filters, to customize the PDF output.
Input Parameters
cardID: stringparams: object
OUTPUT Parameters
result: array

3.5. Convert Page to PDF
- Function:
page2PDF:- This is the core function that brings everything together. It:
- Calls
getCardsOnPageto retrieve all the cards on the page. - Iterates through each card and calls
getPDFto generate a PDF for each one. - Handles different chart types, setting custom dimensions for the generated PDFs.
- Collects all the generated PDFs into a
pdfResultarray. - Returns the final dashboard result, which includes the
pdfResultand any relevant metadata.
- Calls
- This is the core function that brings everything together. It:
Input Parameters
pageID: stringfilters: object
OUTPUT Parameters
dashboardResult: object

Step 4: Configure index.html
The index.html file serves as the main interface for your app. It includes an input field for Page ID, a button to trigger PDF conversion, and a result message.
Step 5: Styling with app.css
The app.css file defines styles for the app’s layout and elements.
Step 6: Write JavaScript Logic in app.js
The app.js file handles interactions like managing filters, merging PDFs, and triggering the PDF download.
6.1: Initialize Variables and Event Listeners
6.2: Handle Filters
Manage and display the filters applied to the data.6.3: Start PDF Conversion
This function triggers the PDF generation and handles user feedback on the result. It uses the Domo Code Engine function to generate the encoded PDF and call the merge function to build the pdf document with all tables and charts in the dashboard.6.4: Merge PDFs
This function merges individual PDF pages into a single document and downloads it. PDF-Lib is used for merging multiple PDFs, reordering or resizing pages, and adding customized content like titles or footers. Whereas HTML2PDF is used to generate downloadable PDF files from HTML content Any time you want to reference the documentaions, please access the HTML2PDF documentation and PDF-Lib documentation.-
Initialize PDF-lib and Create a New Document:
- Start by importing the PDF-lib library.
- Create a new
PDFDocumentobject calledmergedPdfto hold all pages from the PDFs being merged.
-
Clean Up the Title String:
- Clean up the
titleHtmlstring by removing any HTML tags and replacing special characters with newlines to ensure a clear, readable title in the final PDF.
- Clean up the
-
Iterate Over Each PDF Result:
- Create an array named
pdfArray, with each element (pdfResultfrom the code engine function response) as a base64-encoded PDF string. - Loop through each
pdfResultin the array, decode the base64 string, and load the PDF data into a newPDFDocument. - Retrieve all pages from the loaded PDF document.
- Create an array named
-
Conditional Title Addition:
- Add a title to the PDF if the
titleHtmlstring is not empty.
- Add a title to the PDF if the
-
Copy Pages to Merged PDF:
- For each page in the loaded PDF, copy it to the
mergedPdfdocument, accumulating all pages into a single document.
- For each page in the loaded PDF, copy it to the
-
Create a New Consolidated PDF Document:
- After merging pages into
mergedPdf, create anotherPDFDocumentobject namedconsolidatedPdf. - Add a title page to
consolidatedPdfthat displays the cleaned-up title and any applied filters.
- After merging pages into
-
Organize Pages Based on Size:
- Loop over each page in
mergedPdfand add it toconsolidatedPdf, positioning based on the page’s width.
- Loop over each page in
-
Save and Download the Consolidated PDF:
- Save
consolidatedPdfas a byte array and trigger a download of the final merged PDF using adownloadfunction.
- Save
Conclusion
By following this tutorial, you’ve built a functional app that converts Domo dashboards into downloadable PDFs, handling filters and merging multiple PDFs into a single file. This app can be further enhanced by adding more customization options and error handling.