> For the complete documentation index, see [llms.txt](https://developers.weglot.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developers.weglot.com/cms/wordpress/use-cases/translate-pdf-with-gravity-pdf.md).

# Translate pdf with Gravity pdf

Since the version 3.7 of Weglot plugin, you can translate pdf generate by Gravity PDF.

Below is an example of how to translate a PDF generated by Gravity PDF into the current language, based on the `gfpdf_pdf_html_output` filter documented here: <https://docs.gravitypdf.com/v6/developers/filters/gfpdf_pdf_html_output/>

```php
// Add this using the "Code Snippets" plugin.

// Create a new meta entry to store the weglot_language on Gravity Forms entries.
add_filter( 'gform_entry_meta', 'get_entry_meta', 10, 2 );
function get_entry_meta( $entry_meta, $form_id ) {
	$entry_meta['weglot_language'] = array(
		'label'                      => 'Weglot language',
		'is_numeric'                 => false,
		'is_default_column'          => true,
		'update_entry_meta_callback' => 'update_entry_meta',
	);
	return $entry_meta;
}

function update_entry_meta( $key, $lead, $form ) {
	return ''; // Return the value of the entry meta.
}

// Store the Weglot language on submission.
add_action( 'gform_after_submission', 'after_submission' );
function after_submission( $entry ) {
	$request_url_services = weglot_get_service( 'Request_Url_Service_Weglot' );
	$current_language     = $request_url_services->get_current_language()->getExternalCode();
	gform_update_meta( $entry['id'], 'weglot_language', $current_language );
}

// Translate the PDF using the stored language.
add_filter( 'gfpdf_pdf_html_output', function( $html, $form, $entry, $settings, $Helper_PDF ) {
	$weglot_language = gform_get_meta( $entry['id'], 'weglot_language' );
	if ( $weglot_language === weglot_get_original_language() ) {
		return $html;
	}
	$qp                    = new GFPDF\Helper\Helper_QueryPath();
	$pdf_translate_service = weglot_get_service( 'Pdf_Translate_Service_Weglot' );
	$html                  = $pdf_translate_service->translate_pdf( $html, $weglot_language );
	$wrapper               = $qp->html5( $html['content'] );
	return $wrapper->top( 'html' )->innerHTML5();
}, 10, 5 );
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://developers.weglot.com/cms/wordpress/use-cases/translate-pdf-with-gravity-pdf.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
