We want to generate Notepad monthly reports with operational metrics and save a PDF version in Foundry (having the PDF version instead of Notepad file will help with auditing and tracking metrics at a specific point in time). We currently use a Webhook to hit the Notepad API, generate the Notepad reports, and save them to a Compass folder dynamically. But we want to modify this so the output is a PDF and not a Notepad file. Is there a potential path to do this?
Hi there,
One of the ‘secret’ Foundry APIs can be used for this:
When you generate a PDF from a Notepad document, it’s sent to a service called ‘resource-renderer’. You can actually call this programatically, but do note that this is might change at a moments notice, and will not be considered production grade by any measure. However, it will help you solve your problem.
Below is the code to get started. Note that you need to set up autorization, and it could also be worth looking at the data in export_config, to tailor your export.
import requests
headers = {
'authorization': 'INSERT AUTORIZATION METHOD HERE',
'content-type': 'application/json',
}
export_config = {
'exportFormat': 'PDF',
'renderCompletionCondition': {
'widgetsLoadedCondition': {
'maxWaitTime': 60,
},
'type': 'widgetsLoadedCondition',
},
'orientation': 'PORTRAIT',
'markingIds': [],
'browserLocale': 'en-US',
'overridePageSize': {
'preset': 'LETTER',
'type': 'preset',
},
}
response = requests.post(
'https://{hostname}/resource-renderer/api/notepad/{notepadRid}/render-async',
headers=headers,
json=export_data,
)
the response will be this JSON:
{"previewRid":"ri.resource-renderer.main.notepad-preview.uuid","createdAt":"2025-05-30T15:48:39.635405118Z"}
You use the previewRid-variable from this return to call this endpoint – add in a wait-condition, that uses the maxWaitTime variable in the export_config above.
pdf_endpoint = https://{hostname}/resource-renderer/api/notepad/{previewRid}/stream
This returns a binary stream, that you can output to a file. This will be the PDF rendering of your Notepad document.
Let me know how this works out for you.
I need this as well, but a production grade solution. How do one go about solving that?
The use of PDF (generating and storing) is a pretty common functionality
Hi @bobbyb,
If you want to use Notepad as the source, I’d write a script to pull the content of the notepad, convert it into Markdown, and then use one of the many libraries to convert that to a pdf (markdown-pdf, fpdf2, etc. – all available via PyPi).
The only non-totally-prod-safe thing here is the actual Notepad API itself, which is accessed via this URL:
https://{foundry_api_url}/notepad/api/notepad/{notepad_rid}
You can set up health checks to catch any issues there, and with that I would be reasonably confident that this solution would work well for you.