簡體   English   中英

如何在eXist-db和xQuery中的函數運行期間壓縮二進制文件

[英]How to zip binary files during function’s run in eXist-db and xQuery

我不會產生pdf並將其作為response:stream-binary提供問題response:stream-binary文件以供下載。 但是,如果我嘗試將生成的pdf壓縮並用zip進行壓縮,則會遇到問題。 它提供了zip結果供下載。 包含pdf,但沒有大小(空文件)。

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結果存儲在數據庫中的任何位置。

做完了 最好稍微重新安排項目。 我在調用渲染函數的查詢中使用了整個邏輯。 工作結果是:

...
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')

如果有人可以修改此解決方案,我將非常高興。 我了解到,使用強類型輸入並且不依賴自動轉換是一個好主意。 否則,該代碼將無法正常工作。 非常感謝Erik Siegel和Adam Retter撰寫的有關eXist-db的書,在這里我看到了提示。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM