You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用xhtmltopdf转HTML到PDF时遇Declaration group closing '}'未找到错误

Fixing "Declaration group closing '}' not found" in xhtmltopdf with CSS Keyframes

The error you're hitting comes down to xhtmltopdf's limited support for modern CSS3 features, specifically the prefixed -webkit-keyframes syntax. The library's CSS parser (built on older rendering engines) can't properly parse this animation declaration, leading to the missing closing } error you saw.

Here are two straightforward fixes to resolve this:

  • Option 1: Remove the keyframe code entirely
    PDFs are static documents—CSS animations like your spinning effect won't render or work in the final output anyway. Just delete the problematic @-webkit-keyframes block from your CSS. This is the simplest solution and eliminates the parsing error immediately.

  • Option 2: Wrap the animation code in a media query to exclude it from PDF rendering
    If you need to keep the animation for web display but want xhtmltopdf to ignore it, use a @media not print wrapper (xhtmltopdf defaults to processing print styles):

    @media not print {
      @-webkit-keyframes spin { 
        0% { -webkit-transform: rotate(0deg); } 
        100% { -webkit-transform: rotate(360deg); } 
      }
    }
    

    This way, the animation applies to web browsers but gets skipped entirely during PDF conversion.

Why this happens:

xhtmltopdf relies on older rendering technology (ReportLab under the hood) that doesn't support many CSS3 dynamic features like keyframes, transitions, or transforms. Even if you fixed the syntax, the animation wouldn't appear in the PDF—so removing or excluding it is both a fix for the error and a logical choice for static PDF output.

内容的提问来源于stack exchange,提问作者Prashant Jha

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 07:17:10