WordPress - How to translate a PDF ?

In this article, you’ll learn how to translate a PDF generated on your WordPress website with Weglot.



1. Which PDF can be translated by Weglot?

Weglot can translate PDFs generated by specific WordPress plugins, as long as the PDF is created from HTML content. By default, most PDF-generation plugins do not send this HTML to Weglot. Using a dedicated filter (code snippet), Weglot can retrieve this HTML and translate it before the PDF is produced.


Currently, Weglot supports PDF translation for:


Gravity PDF

Weglot provides developer documentation that includes the filter required to enable translation of PDFs generated by the Gravity PDF plugin:

https://developers.weglot.com/wordpress/use-cases/translate-pdf-with-gravity-pdf


WooCommerce PDF Invoice

Weglot also supports invoice PDFs generated by WooCommerce, using a similar filter. The documentation is available here:

https://developers.weglot.com/wordpress/use-cases/translate-pdf-for-woocommerce-pdf-invoice


If your website includes links to PDF files and you want these files to display translated versions depending on the selected language, you can refer to our article:

👉 How to change a Media file (Image, PDF, etc) on my translated website.


2. How to add the code snippet needed for PDF translation

To translate PDFs, you need to add a code snippet to your WordPress installation. You can do this in two different ways.



You can install a plugin such as Code Snippets to add the required code more easily.

  1. In your WordPress admin, install and activate the Code Snippets plugin.
  2. Click Snippets in the left menu.
  3. Click Add New at the top of the page to create a new snippet.

    Screenshot showing the location of the Add New button

  4. Paste the filter provided in our developer documentation into the code area.
  5. Make sure the snippet runs everywhere, so it applies to all pages where the PDF is generated.
  6. Save and activate the snippet.

    Screenshot showing the steps to follow in order to create a new snippet

  7. Clear your WordPress or server cache so the changes take effect.

Option 2 — Adding the snippet to your functions.php file


If you prefer, you can add the code snippet directly to your active theme.

  1. In your WordPress admin, go to Appearance > Theme Editor.

  2. In the right sidebar, select the functions.php file.

  3. Add the snippet at the bottom of the file.
  4. Save your changes and clear any caches.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us