Does FOP 2.1 support ViewerPreferences?

北慕城南 提交于 2019-12-17 20:52:40

问题


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?


回答1:


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)




回答2:


As supplement to @lfurini's excellent finding, here are some more thing that can be done that way easily, tested with fop 2.1, but could also work from 2.0:, remove the comments from the relevant sections to try:

<fo:declarations>
  <pdf:catalog xmlns:pdf="http://xmlgraphics.apache.org/fop/extensions/pdf">
    <!-- this opens in full-screen mode, e.g. as presentation -->
    <!-- pdf:name key="PageMode">FullScreen</pdf:name -->

    <!-- this opens then second page so it is fully visible -->
    <!-- (count seems to start at 0) -->
    <!-- pdf:array key="OpenAction">
      <pdf:number>1</pdf:number>
      <pdf:name>Fit</pdf:name>
    </pdf:array -->

    <!-- this will replace the window title from filename to below dc:title -->
    <pdf:dictionary type="normal" key="ViewerPreferences">
      <pdf:boolean key="DisplayDocTitle">true</pdf:boolean>
    </pdf:dictionary>
  </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/">
        <!-- Dublin Core properties go here -->
        <dc:title>Sample Document title</dc:title>
      </rdf:Description>
    </rdf:RDF>
  </x:xmpmeta>
</fo:declarations>

Details of possible values can be looked up in the pdf specification (from page 139 in this v1.7 version, TABLE 3.25 Entries in the catalog dictionary), take care not to use values that would normally be set by fop anyway, restrict yourself to viewer/reader relevant stuff.



来源:https://stackoverflow.com/questions/38347687/does-fop-2-1-support-viewerpreferences

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!