# Translate pdf with Gravity pdf

Below on example of how you can translate your PDF on the current language base on the gravity pdf filter here : <https://docs.gravitypdf.com/v6/developers/filters/gfpdf_pdf_html_output/>

```php
// Add this using plugin "Code Snippet"

// create a new meta entry to store the weglot_language for the Gravity form entries
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' => array( $this, 'update_entry_meta' ),
                );
    return $entry_meta;
}

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

//use the gform_after_submission hook to store the weglot language
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 );
}

// get the meta entries to translate the pdf
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: 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://developers.weglot.com/wordpress/use-cases/translate-pdf-with-gravity-pdf.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.
