### Typst Variable Substitution Syntax Example Source: https://hexdocs.pm/imprintor Demonstrates Typst's syntax for accessing nested data structures within templates, using `sys.inputs.elixir_data`. ```typst = Customer Report *Name:* #sys.inputs.elixir_data.customer.name *Email:* #sys.inputs.elixir_data.customer.email == Orders #for order in sys.inputs.elixir_data.orders [ - #order.product: \$#order.total ] ``` -------------------------------- ### Basic PDF Generation with Imprintor Source: https://hexdocs.pm/imprintor Generate a simple PDF from a Typst template with basic data. Ensure the template and data are correctly defined before compilation. ```elixir # Define a Typst template with data access template = """ = Hello #elixir_data.name! *Date:* #elixir_data.date This is a sample document generated using Imprintor. == Details Here are some details: - *Name:* #sys.inputs.elixir_data.name - *Email:* #sys.inputs.elixir_data.email - *Age:* #sys.inputs.elixir_data.age Thanks for using Imprintor! """ # Provide data to fill the template data = %{ "name" => "John Doe", "date" => "2024-01-15", "email" => "john@example.com", "age" => 30 } # Create a configuration and generate PDF config = Imprintor.Config.new(template, data) {:ok, pdf_binary} = Imprintor.compile_to_pdf(config) # Save to file File.write!("output.pdf", pdf_binary) ``` -------------------------------- ### Using Tagged Bytes for pdf.attach in Typst Source: https://hexdocs.pm/imprintor Attach binary data, such as XML files for standards like Factur-X, to a PDF using the `pdf.attach` function in Typst. Use `Imprintor.bytes/1` to correctly format binary data. ```elixir template = """ #set document(date: datetime.today()) #pdf.attach( "factur-x.xml", sys.inputs.elixir_data.factur_x_xml, relationship: "alternative", mime-type: "application/xml", description: "Factur-X XML", ) = Invoice """ data = %{ "factur_x_xml" => Imprintor.bytes("...") } config = Imprintor.Config.new(template, data, pdf_standard: "a-3a") {:ok, pdf_binary} = Imprintor.compile_to_pdf(config) ``` -------------------------------- ### Working with Complex Data and Iteration in Typst Templates Source: https://hexdocs.pm/imprintor Generate a PDF using a Typst template that iterates over a complex, nested data structure. This is useful for generating lists or directories from dynamic data. ```elixir # Template with data iteration using elixir_data template = """ = Employee Directory #for employee in sys.inputs.elixir_data.employees [ == #employee.name *Position:* #employee.position *Department:* #employee.department *Email:* #employee.email --- ] """ # Complex nested data structure data = %{ "employees" => [ %{ "name" => "Alice Johnson", "position" => "Software Engineer", "department" => "Engineering", "email" => "alice@company.com" }, %{ "name" => "Bob Smith", "position" => "Product Manager", "department" => "Product", "email" => "bob@company.com" } ] } config = Imprintor.Config.new(template, data) {:ok, pdf_binary} = Imprintor.compile_to_pdf(config) File.write!("employee_directory.pdf", pdf_binary) ``` -------------------------------- ### Add Imprintor to Mix Dependencies Source: https://hexdocs.pm/imprintor Add the Imprintor library to your project's dependencies in the mix.exs file. ```elixir def deps do [ {:imprintor, "~> 0.1.0"} ] end ``` -------------------------------- ### Setting PDF Standard Option in Imprintor Source: https://hexdocs.pm/imprintor Configure Imprintor to generate PDFs adhering to specific PDF standards, such as 'a-3a'. This is crucial for compliance with certain document requirements. ```elixir template = """ #set document(date: datetime.today()) = Invoice """ config = Imprintor.Config.new(template, %{}, pdf_standard: "a-3a") {:ok, pdf_binary} = Imprintor.compile_to_pdf(config) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.