如何在Ant脚本中使用Sejda?

时间:2018-12-05 22:55:05

标签: java ant sejda

我知道,Ant不再流行,但是我们仍在使用它。我想从Ant调用setheaderfooter任务。不幸的是,我无法到达那里。

首先,我成功运行了以下命令,从命令行测试了它的工作原理:

  C:\tools\sejda-console-3.2.66-bin\sejda-console-3.2.66\bin>sejda-console.bat setheaderfooter -f c:\Temp\test.pdf -o c:\temp\out.pdf -s all -y top -x center -t Courier-Bold -l "This publication is under embargo until 3 December 2018, 11:00 UTC" -c #ff0000 --overwrite

接下来,我试图让它在Ant目标中运行,就像这样:

<target name="Watermark">
    <java  fork="yes" classname="org.sejda.cli.Main" maxmemory="1024m">
        <arg value="-Dfile.encoding=UTF8"/>
        <arg value="-Dapp.name=&quot;sejda-console&quot;"/>
        <arg value="-Dapp.repo=&quot;${sejda.path}/lib&quot;"/>
        <arg value="-Dapp.home=&quot;${sejda.path}&quot;"/>
        <arg value="-Dbasedir=&quot;${sejda.path}&quot;"/>
        <arg value="setheaderfooter"/>
        <arg value="-f c:\Temp\test.pdf"/>
        <arg value="-o c:\temp\out.pdf"/>
        <arg value="-s all"/>
        <arg value="-y top"/>
        <arg value="-x center"/>
        <arg value="-t Courier-Bold"/>
        <arg value="-l 'This publication is under embargo until 3 December 2018, 11:00 UTC'"/>
        <arg value="-c #ff0000"/>
        <arg value="--overwrite"/>
        <classpath>
            <pathelement path="${sejda.path}/etc"/>
            <pathelement location="${sejda.path}/lib/sejda-conversion-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-core-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/validation-api-1.0.0.GA.jar"/>
            <pathelement location="${sejda.path}/lib/hibernate-validator-4.2.0.Final.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-model-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-sambox-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-fonts-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-image-writers-3.2.66.jar"/>
            <pathelement location="${sejda.path}/lib/imageio-core-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/common-lang-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/common-io-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/common-image-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/imageio-metadata-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/imageio-tiff-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/imageio-jpeg-3.3.1.jar"/>
            <pathelement location="${sejda.path}/lib/imgscalr-lib-4.2.jar"/>
            <pathelement location="${sejda.path}/lib/bcmail-jdk15on-1.56.jar"/>
            <pathelement location="${sejda.path}/lib/bcpkix-jdk15on-1.56.jar"/>
            <pathelement location="${sejda.path}/lib/bcprov-jdk15on-1.56.jar"/>
            <pathelement location="${sejda.path}/lib/metadata-extractor-2.10.1.jar"/>
            <pathelement location="${sejda.path}/lib/xmpcore-5.1.3.jar"/>
            <pathelement location="${sejda.path}/lib/commons-csv-1.5.jar"/>
            <pathelement location="${sejda.path}/lib/jcl-over-slf4j-1.7.25.jar"/>
            <pathelement location="${sejda.path}/lib/jul-to-slf4j-1.7.25.jar"/>
            <pathelement location="${sejda.path}/lib/jewelcli-0.8.2.jar"/>
            <pathelement location="${sejda.path}/lib/commons-lang3-3.5.jar"/>
            <pathelement location="${sejda.path}/lib/commons-io-2.6.jar"/>
            <pathelement location="${sejda.path}/lib/logback-classic-1.2.2.jar"/>
            <pathelement location="${sejda.path}/lib/logback-core-1.2.2.jar"/>
            <pathelement location="${sejda.path}/lib/sambox-1.1.46.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-io-1.1.4.jar"/>
            <pathelement location="${sejda.path}/lib/fontbox-2.0.12.jar"/>
            <pathelement location="${sejda.path}/lib/slf4j-api-1.7.25.jar"/>
            <pathelement location="${sejda.path}/lib/sejda-console-3.2.66.jar"/>
        </classpath>
    </java>
</target>

这里的输出是:

Watermark:
     [java] Configuring Sejda 3.2.66
     [java] Document root element "sejda", must match DOCTYPE root "null".
     [java] Document is invalid: no grammar found.
     [java] Starting execution with arguments: '-Dfile.encoding=UTF8 -Dapp.name=sejda-console -Dapp.repo=C:/tools/sejda-
console-3.2.66/lib -Dapp.home=C:/tools/sejda-console-3.2.66 -Dbasedir=C:/tools/sejda-console-3.2.66 setheaderfooter -f c
:\Temp\test.pdf -o c:\temp\out.pdf -s all -y top -x center -t Courier-Bold -l 'This publication is under embargo until 3
 December 2018, 11:00 UTC' -c #ff0000 --overwrite'
     [java] Java version: '1.8.0_191'
     [java] Sejda Console
     [java]
     [java] Basic commands:
     [java]
     [java]  addbackpages         Takes one or more pages from a PDF document and adds them to
     [java]                       one or more PDF documents after each 'n' pages.

由于某些原因,Sejda无法识别setheaderfooter命令,而仅列出帮助信息。错误消息中有此部分

 [java] Document root element "sejda", must match DOCTYPE root "null".
 [java] Document is invalid: no grammar found.

这对我来说真的没有意义。我从来没有从Ant调用过一个类,仅从jar文件中调用过,所以我不确定如何进一步进行。 :-/

编辑:感谢@martin_clayton的评论,我将-D参数移到了jvmarg元素上,这使事情向前发展了一些,因为现在错误消息涉及sejda的实际选项:

 [java] Executing 'C:\Program Files\Java\jre1.8.0_191\bin\java.exe' with arguments:
 [java] '-Dapp.name="sejda-console"'
 [java] '-Dapp.repo="C:/tools/sejda-console-3.2.66/lib"'
 [java] '-Dapp.home="C:/tools/sejda-console-3.2.66"'
 [java] '-Dbasedir="C:/tools/sejda-console-3.2.66"'
 [java] '-Dfile.encoding=UTF8'
 [java] '-Xmx1024m'
 [java] '-classpath'
 [java] 'C:\tools\ .... snipped for brevity ....'
 [java] 'org.sejda.cli.Main'
 [java] 'setheaderfooter'
 [java] '--file 'c:\Temp\test.pdf''
 [java] '--output 'c:\temp\out.pdf''
 [java] '--pageRange all'
 [java] '-y top'
 [java] '-x center'
 [java] '-t 'Courier-Bold''
 [java] '-l 'This publication is under embargo until 3 December 2018, 11:00 UTC''
 [java] '-c #ff0000'
 [java] '--overwrite'
 [java]
 [java] The ' characters around the executable and arguments are
 [java] not part of the command.
 [java] Configuring Sejda 3.2.66
 [java] Document root element "sejda", must match DOCTYPE root "null".
 [java] Document is invalid: no grammar found.
 [java] Starting execution with arguments: 'setheaderfooter --file 'c:\Temp\test.pdf' --output 'c:\temp\out.pdf' --pageRange all -y top -x center -t 'Courier-Bold' -l 'This publication is under embargo until 3 December 2018, 11:00 UTC' -c #ff0000 --overwrite'
 [java] Java version: '1.8.0_191'
 [java] Unexpected Option: file 'c:\Temp\test.pdf'
 [java] Unexpected Option: output 'c:\temp\out.pdf'
 [java] Unexpected Option: pageRange all
 [java] Option must have a value: [--verticalAlign -y value] : vertical align defining if it's a header (top) or a footer (bottom). { top, bottom }. Default is 'bottom' (optional)
 [java] Unexpected Option:
 [java] Option must have a value: [--font -t value] : font as a standard font type 1, defined in Pdf reference 1.7, section 5.5.1. { Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Helvetica, Helvetica-Bold, Helvetica-Oblique, Helvetica-BoldOblique, Courier, Courier-Bold, Courier-Oblique, Courier-BoldOblique, Symbol, ZapfDingbats }. Default is 'Helvetica' (optional)
 [java] Option must have a value: --output -o value : output file or directory (required)
 [java] Option must have a value: [--outputPrefix -p value] : prefix for the output files name (optional)
 [java] Option must have a value: [--horizontalAlign -x value] : horizontal align { center, right, left }. Default is 'center' (optional)
 [java] Option must have a value: [--fontColor -c value] : font color. Defaults to black #000000. Ex: -c #AA3399 (optional)
 [java] Unexpected Option: e
 [java] Unexpected Option: n
 [java] Unexpected Option: r
 [java] Unexpected Option: '
 [java] Unexpected Option: C
.... and more ....

似乎没有理解arg作为参数。 :-|此外,它仍然具有有关Document元素“ sejda”的先前错误消息。

编辑:我刚刚测试了(已弃用,或至少“强烈建议避免使用”)<arg line=""/>,并且可以使用! “概念证明”:

<arg line="setheaderfooter -f c:/temp/test.pdf -o c:/temp/out.pdf -l 'BLAH'"/>

0 个答案:

没有答案