2016-02-05 48 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在那裏我看到了一個提示。

相關問題