8

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

Dimitris
  • 3,975
  • 5
  • 25
  • 27
  • Hm, trying to use the answers from http://stackoverflow.com/questions/38347687/ and the pdf reference I would `en...` (no idea where the ; in the xmlns comes from) (as well as `xml:lang="en"` in the fo:root) but it will not show the language in the acrobat tag neither – Stefan Hegny Aug 18 '16 at 13:56
  • On my previous comment, however, exiftool on that pdf file **will show** `Language : en` so it makes it into the file correctly. The problem may be that the field in the acrobat properties dialog refers to something different. See also [PDF16: Setting the default language using the /Lang entry in the document catalog of a PDF document](https://www.w3.org/TR/WCAG20-TECHS/PDF16.html) – Stefan Hegny Aug 18 '16 at 14:37
  • 1
    My guess is that it just does not work in Reader. If you go to the page above: https://www.w3.org/TR/WCAG20-TECHS/PDF16.html and then download the exact sample they reference and look at the properties, it shows blank. I also searched my PDFs from FOP, RenderX, Word ... some tagged, all kinds. I could not find a single one that had any value when viewed this way. – Kevin Brown Aug 22 '16 at 19:21
  • Thanks @KevinBrown looks like a limitation of Adobe Reader... Maybe you need the pro version – Dimitris Aug 23 '16 at 08:07
  • 1
    Do you have a sample of a PDF ... any PDF produced any way at all .. that shows the language in Reader? If you do, perhaps we can look at the PDF and see what is different. If you cannot find one, then the answer to the question is ... "ask Adobe" (although that would be too short for Stackoverflow as an answer :) ) – Kevin Brown Aug 23 '16 at 21:18
  • 1
    I have downloaded Adobe Acrobat Pro, when setting in xml:lang="en" it is displayed in Pro's properties, but not in Adobe Reader (free version). Looks like a limitation/bug – Dimitris Aug 24 '16 at 07:04

2 Answers2

1

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).

Tony Graham
  • 7,306
  • 13
  • 20
1

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.

Stefan Hegny
  • 2,107
  • 4
  • 23
  • 26
  • Well they work in they set the language of the document. You could put your question different: What is it that Adobe Reader does show in the Language field? Maybe this attracts those people that can answer it. Or maybe check some forums at adobe. – Stefan Hegny Aug 19 '16 at 12:27
  • let's see what comes out here [Reader Document Property "Language"](https://forums.adobe.com/message/8952443) – Stefan Hegny Aug 19 '16 at 18:56
  • I see you are also keen to know - asking the fop mailing list is also a good idea ;-) – Stefan Hegny Aug 22 '16 at 18:59