2016-02-05 36 views
0

我在生成pdf并将它们作为response:stream-binary文件下载时没有问题。但是,如果我尝试压缩制作的pdf并使用zip执行相同的操作,则会出现问题。它提供了下载的压缩结果。包含pdf,但没有大小(空文件)。如何在eXist-db和xQuery中运行函数时压缩二进制文件

let $pdf-binary := 
(
    if ($pdfQuality eq 'proof' and $template eq 'draft') 
     then xslfo:render(transform:transform($doc, $stylesProof,()), 'application/pdf',(), $proofConf) 
    else if ($pdfQuality eq 'print' and $template eq 'draft') 
     then xslfo:render(transform:transform($doc, $stylesPrint,()), 'application/pdf',(), $printConf) 
    else if ($pdfQuality eq 'print' and $template eq 'auc-geographica') 
     then xslfo:render(transform:transform($doc, $stylesAUCGeographica,()), 'application/pdf',(), $printConf) 
    else() 
) 
return 
    if (not($zipAll)) 
     then response:stream-binary($pdf-binary, 'application/pdf', $name || '.pdf') 
    else if ($zipAll) 
     then (
      let $entry := <entry name="{$name}.pdf" type="binary" method="store">{util:binary-doc($pdf-binary)}</entry> 
      let $zip-file := compression:zip($entry, false()) 
      return 
       response:stream-binary($zip-file, 'application/zip', 'test.zip') 
     ) 
    else() 

重要的是我不想在数据库中的任何地方存储pdf结果。

回答

1

完成。稍微重新安排项目会更好。我在调用渲染函数的查询中使用了整个逻辑。工作成果是:

... 
let $zip as item() := 
    (
     let $entries as item()+ := 
      (
       for $article at $count in $doc/article//tei:TEI 
       let $year as xs:string := $article//tei:date/string() 
       let $issue as xs:string := $article//tei:biblScope/string() 
       let $pdf as xs:base64Binary := fop:render-pdf($article, $template, $name, $pdfQuality) 
       return 
        <entry name="{lower-case($name)}-{$year}-{$issue}-{$count}.pdf" type="binary" method="store">{$pdf}</entry> 
      ) 
      return 
       compression:zip($entries, false()) 
    ) 
return 
     response:stream-binary($zip, 'application/zip', $name || '.zip') 

如果有人可以修改这个解决方案,我会很高兴。我了解到使用强大的打字功能并不依靠自动转换是非常好的主意。没有这个代码不起作用。非常感谢关于eXist-db的书,由Erik Siegel和Adam Retter在那里我看到了一个提示。

相关问题