See all tutorials

Tutorials » How to localize the generated PDF files

Web applications that have users spread across multiple countries will likely need to support localization, if these applications needs to generate PDF files then the localization technical solution will need to cover the PDF documents too.
One of the previous tutorials covered the websites localization with Webpagebytes CMS, see how to implement localization in a web application.

This tutorial will extend the previous tutorial, how to include a dynamic QR code image in a PDF file and will add support for another language, French.

In order to add localization support for generated PDF files, take the following tasks

Extract the static text strings into site messages

Step 1

In Webpagebytes CMS administration interface navigate to the site page that contains the XLS-FO content, extract the static strings and create site messages. The static strings will be replaced with references to site messages by using the wpbMessages model key.

In the site page XLS-FO, the static text strings like
...
<fo:block text-align="right">  
    Tutorial on how to generate a PDF file with dynamic content
</fo:block>	
...
will be replaced with wpbMessages references.
...
<fo:block text-align="right">  
    ${wpbMessages["pdf.about"]}
</fo:block>	
...

Add support for new languages

Step 2

In Webpagebytes CMS administration web interface navigate to Site Settings - Locale Settings and select the new project languages.

Translate the static strings

Step 3

In Webpagebytes CMS administration web interface navigate to Messages section and add translations for the new language(s).

Create language specific URIs to get the localized PDF file

Step 4

In Webpagebytes CMS administration web interface navigate to Site urls section and create a language specific url to publish the PDF resource.
The site URL will follow the regular localization pattern /{language}/pdf

Test the localized PDF file

Step 4

In a browser load the French PDF resource at http://localhost:9090/fr/pdf and the English resource at http://localhost:9090/en/pdf or http://localhost:9090/pdf
PDF localization example with Webpagebytes CMS

Fork me on GitHub