Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
528 views
in Technique[技术] by (71.8m points)

pdf generation - Does FOP 2.1 support ViewerPreferences?

I'm using FOP 2.1 and am trying to set ViewerPreferences, e.g. DisplayDocTitle -> true.

I'm trying (from this question

<fo:declarations>
    <pdf:dictionary type="Catalog" xmlns:pdf="http://xmlgraphics.apache/org/fop/extensions/pdf">
        <pdf:dictionary type="normal" key="ViewerPreferences">
            <pdf:entry key="DisplayDocTitle" type="boolean">true</pdf:entry>
        </pdf:dictionary>
    </pdf:dictionary>
    <x:xmpmeta xmlns:x="adobe:ns:meta/">
    ...

but getting

Jul 13, 2016 11:18:31 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xmlgraphics.apache/org/fop/extensions/pdf}dictionary" encountered (a child of fo:declarations}. (See position 242:105)
Jul 13, 2016 11:18:31 AM org.apache.fop.events.LoggingEventListener processEvent
WARNING: Unknown formatting object "{http://xmlgraphics.apache/org/fop/extensions/pdf}dictionary" encountered (a child of dictionary}. (See position 243:69)

and no ViewerPreferences inside the pdf.

When I put the dictionarys below the <x:xmpmeta xmlns:x="adobe:ns:meta/"> then I get no ViewerPreferences either, only pdfbox preflight will then complain about

The file test.pdf is not valid, error(s) :
7.3 : Error on MetaData, Cannot find a definition for the namespace http://xmlgraphics.apache/org/fop/extensions/pdf

What am I doing wrong, am I too early to try it? Where do I have to patch fop?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

According to the release notes FOP 2.0 introduced, among other things, a

  • Low level mechanism to augment PDF /Catalog and /Page dictionaries

but there are not many examples of its usage in the website.

Looking at the testcases included in the source distribution, in particular the ones named pdf-dictionary-extension_*.xml, I was able to put together something similar to your code which does not generate run-time exceptions; admittedly, I'm not familiar enough with this PDF feature to say whether the output actually achieves what you are trying to do:

<fo:declarations>
  <pdf:catalog xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf">
    <pdf:dictionary type="normal" key="ViewerPreferences">
      <pdf:boolean key="DisplayDocTitle">true</pdf:boolean>
    </pdf:dictionary>
  </pdf:catalog>
</fo:declarations>
  • there is no <pdf:dictionary type="Catalog">, there is pdf:catalog instead
  • there is not a single <pdf:entry key="..." type="..."> element, but there is a specific element for each possible entry type: pdf:array, pdf:boolean, pdf:name, pdf:number, pdf:string, ...

(disclosure: I'm a FOP developer, though not very active nowadays)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...