baml.media.Pdf

A PDF document value.

Reference version

Signature

class baml.media.Pdf

A PDF document value.

Backed by a URL or by base64-encoded content. A file is read when the value is built from it: the value holds its content, never its path.

Source:<builtin>/baml/ns_media/media.bamlbytes 177–2805

Fields

_data

$rust_type

Static methods

function

from_base64

(base64: string, mime_type: string | null) -> pdf throws never

Creates a Pdf value from a base64-encoded string. Optionally specify mime_type.

function

from_file

(
file: string,
mime_type: string | null

Creates a Pdf value from the content of a local file, which is read now. The value is named by the file's base name. Optionally specify mime_type; otherwise it is inferred from the file's name.

Throws

  • Io if the file cannot be opened or read.
  • InvalidArgument only as baml.fs.open declares it: a path that cannot be opened is Io.
function

from_file_content

(file: string, base64: string, mime_type: string | null) -> pdf throws never

Creates a Pdf value from base64-encoded content that was read from file. The value is named by the file's base name. Optionally specify mime_type; otherwise it is inferred from the file's name.

function

from_url

(url: string, mime_type: string | null) -> pdf throws never

Creates a Pdf value from a URL. Optionally specify mime_type (defaults to "application/pdf").

function

infer_mime_type

(source: string) -> string throws never

Returns the MIME type that source, a file name or URL, implies for a PDF: by its extension, or the usual type for a PDF when the extension says nothing. A URL's query and fragment are not part of its extension.

Instance methods

function

base64

(self) -> string throws never

Returns the base64-encoded content of this PDF.

function

mime_type

(self) -> string | null throws never

Returns the MIME type of this PDF, or null if not set.

function

name

(self) -> string | null throws never

Returns the name of this PDF, or null if it has none. A PDF built from a file is named by the file's base name.

function

url

(self) -> string | null throws never

Returns the URL of this PDF, or null if it was not constructed from a URL.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 763–795