Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the default language in Apache FOP

I'm generating PDF files using Apache FOP 2.1.

For this I am trying to set the default language to be English.
This is supposed to be verified after the creation of the PDF via Adobe Reader's option File/Properties/Advanced/Reading Options. This value currently is empty.

Image showing language is not set

I have tried setting xml:lang="en" in fo:root element, in first page-sequence or in the very first element of the .xsl file... Nothing seams to do the trick.

Any Advice?
Thanks Dimitris.

Update:
I have tried 2 more options as suggested in the answers, neither of the 2 worked

  1. <fo:declarations> <pdf:catalog xmlns:pdf="http://xmlgraphics.apache.org/fop/‌extensions/pdf"> <pdf:string key="Lang">en</pdf:string> </pdf:catalog>
  2. <x:xmpmeta xmlns:x="adobe:ns:meta/"> <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> <rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/"> <dc:title>the document title</dc:title> <dc:language>en</dc:language>

Update 2
Have started a bounty on this question.
Any help appreciated and rewarderd

like image 860
Dimitris Avatar asked Aug 18 '16 12:08

Dimitris


People also ask

What is FOP config?

The FOP configuration file is an XML file containing a variety of settings that are useful for controlling FOP's behavior, and for helping it find resources that you wish it to use. The easiest way to get started using a FOP configuration file is to copy the sample found at {fop-dir}/conf/fop.

What is Apache FOP Version?

Current status. The latest version of Apache FOP is 2.6.

Is Apache FOP thread safe?

Apache FOP may currently not be completely thread safe. The code has not been fully tested for multi-threading issues, yet.

How does Apache FOP work?

Apache™ FOP (Formatting Objects Processor) is a print formatter driven by XSL formatting objects (XSL-FO) and an output independent formatter. It is a Java application that reads a formatting object (FO) tree and renders the resulting pages to a specified output.


2 Answers

You may need to set language (http://www.w3.org/TR/xsl/#language). See 'language' in http://xmlgraphics.apache.org/fop/compliance.html

You'd think that xml:lang would work, but you say it doesn't. The FOP FAQ has an answer about setting language to control hyphenation, so it's worth a try even though language is defined to apply only to fo:block and fo:character.

You might need enable accessible PDF. See https://xmlgraphics.apache.org/fop/2.1/accessibility.html, which has references to the language being set in the PDF (including from xml:lang).

like image 122
Tony Graham Avatar answered Oct 24 '22 13:10

Tony Graham


According to everything I've tried, the Language field in the Document Properties shown by adobe reader has not much to do with the document language actually found in the pdf (It's alway empty).

The xml:lang="en" tag in the fo:root with FOP 2.1 is sufficient for exiftool to list the document as having english language and also for the PDFDebugger from pdfbox to show the /Lang Entry in the Document catalog which is where the language is specified according to the pdf_reference 1.7 Table 3.25 "Entries in the catalog dictionary".

The code

<fo:declarations>
 <pdf:catalog 
   xmlns:pdf="http://xmlgraphics.apache.org/fop/‌extensions/pdf"‌​>
    <pdf:string key="Lang">en</pdf:string>
   </pdf:catalog>

does exactly the same in the pdf output as the xml:lang.

Additonally you can also set the language in the metadata (also inside fo:declarations)

<x:xmpmeta 
  xmlns:x="adobe:ns:meta/" 
  xmlns:dc="http://purl.org/dc/elements/1.1/" 
  xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
    <rdf:RDF>
      <rdf:Description rdf:about="">
        <dc:language><rdf:Bag><rdf:li>en</rdf:li></rdf:Bag></dc:language>

But my fop 2.1 seems to set that too automagically if the xml:lang is there.

So it would be interesting if someone drops in who can explain what that document language property in the adobe reader actually shows.

like image 44
Stefan Hegny Avatar answered Oct 24 '22 13:10

Stefan Hegny