Pdf

Pdf values to BAML functions can be created in client libraries. This document explains how to use these functions both at compile time and runtime to handle Pdf data. For more details, refer to pdf types.

Pdf instances must be created from Base64 or local file data; URLs are not supported.

Usage Examples

1from baml_py import Pdf
2from baml_client import b
3
4async def test_pdf_input():
5 # Create a Pdf object from Base64 data
6 pdf_b64 = "JVBERi0K..."
7 pdf = Pdf.from_base64("application/pdf", pdf_b64)
8 res = await b.TestPdfInput(pdf=pdf)

Static Methods

fromBase64
(mediaType: string, base64: string) => Pdf

Creates a Pdf object using Base64 encoded data along with the given MIME type.

fromFile
(file: File) => Promise<Pdf>

Only available in browser environments. @boundaryml/baml/browser
Creates a Pdf object from a File object. Available in browser environments only.

Instance Methods

asBase64
() => [string, string]

Get the base64 data and media type if the Pdf is stored as base64. Returns [base64Data, mediaType]. Throws an Error if the Pdf is not stored as base64.

toJSON
() => { base64: string; media_type: string }

Convert the Pdf to a JSON representation. Returns a base64 object with media type.