# Save handlers

*Save handlers* are powerful tools that allow you to make additional changes to a PDF document after the layout process is complete, but before it is saved. *Save handlers* are simple callable functions that can be easily implemented, they require the following signature:

```php
callable(\Typesetsh\Pdf\Document $document): void
```

To use a *save handler*, it must be registered at `Typesetsh\HtmlToPdf::$saveHandler` with an arbitrary key, along with the save handler.&#x20;

When the document is being saved, each registered handler will be called in the order in which they were registered, passing in the PDF document as a parameter. The following example demonstrates how to initialize an HTML to PDF service and register two *save handlers*.

```php
$html = 'Hello <strong>World</string>!';

$service = new \Typesetsh\HtmlToPdf();
$service->saveHandler['pdf_a'] = new \Typesetsh\HtmlToPdf\A_1B_Web();
$service->saveHandler['producer'] = function(\Typesetsh\Pdf\Document $document): void {
    $document->Info->Producer = 'My awesome application';
};

$resolveUri = \Typesetsh\UriResolver::all();

$result = $service->render($html, $resolveUri);
$result->toFile(__DIR__.'/hello.pdf');

```

Typeset.sh comes with a variety of predefined save handlers that offer additional functionality for manipulating your PDF documents. These save handlers are thoroughly described in their corresponding documentation pages, providing detailed explanations on how to use them and their specific capabilities.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.typeset.sh/advanced-guides/save-handlers.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
