问题
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.
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
<fo:declarations> <pdf:catalog xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf"> <pdf:string key="Lang">en</pdf:string> </pdf:catalog>
<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
回答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
).
回答2:
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.
来源:https://stackoverflow.com/questions/39017700/how-to-set-the-default-language-in-apache-fop