We're using Jaspersoft iReport Designer to create bilingual PDF outputs—each file contains both English and French text.
For accessibility reasons, we'd like to tag each block of text with its appropriate language in the resulting PDF. See PDF19: Specifying the language for a passage or phrase with the Lang entry in PDF documents for what we're trying to do.
Modifying the PDF files manually is not an option since we email them directly to our users.
Does Jaspersoft support this?
No JasperReports version<=6.7.0 do not support this, there is no available property in Configuration Reference to set
Lang
property to single textElement.You have 2 options:
Post elaborate the pdf with for example iText as Dave Jarvis suggested. You can either try to change the dictionary or recreate the pdf adding this additional info. These methods are both fairly complex and naturally runtime will increase since you will need to read/recreate the pdf.
Modify source code of JasperReport to add support. Directly modify the JRPdfExporter, JRPdfExporterTagHelper or add your new exporter (to keep original library intact)
In this answer I will show you how you can modify the original lib adding additional tags (adding a LANG entry in the dictionary)
Background
The example in PDF19: Specifying the language for a passage or phrase with the Lang entry in PDF documents, show this PDF Object tree using iText RUPS.
I will assume that it is sufficient to add
/Lang
in our output related to the specific text that is not in default language of pdf. Note: If you need to add other entry as well the technique remains the same you just need to modify the below code example.Source code modification
Modification to JRPdfExporterTagHelper.java
Add static property identifier to follow code style
Modify
startText(boolean isHyperLink)
andstartText(String text, boolean isHyperlink)
, only first method is shown in this example (principal is same in second), we need to change method signature addingJRPrintText
so that we can retrive properties.Since we change method signature we now need to modify JRPdfExporter.java so that we can recompile
Modify
exportText(JRPrintText text)
You could remove the boolean
text.getLinkType() != null
, since we are actually passing the text object now, but I wanted to keep similar code for simplicity of exampleExample
jrxml
Exported to pdf with modifications above and visualized with iText RUPS
Is this enough according to PDF19: Specifying the language for a passage or phrase with the Lang entry in PDF documents
As far as I can see, yes but I'm not an expert in this matter, in any case if you need to add other tags the procedure is the same.