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

GemBox Document HTML转PDF时REPRINT文本无法垂直显示的解决方法

解决GemBox.Document转换HTML到PDF时垂直文本不生效的问题

方案1:升级GemBox.Document到最新版本

  • GemBox后续版本对CSS布局属性的支持有所增强,优先尝试升级到最新稳定版,很多CSS兼容性问题在新版本中已修复。
  • 在NuGet包管理器中更新GemBox.Document包,或通过命令行执行:
    Install-Package GemBox.Document -Version [LatestVersion]
    

方案2:替换CSS属性为GemBox支持的替代方案

如果升级后仍不生效,可改用旋转样式模拟垂直文本:

  1. 修改HTML中的样式,将writing-mode: vertical-lr替换为旋转属性,同时调整定位避免布局错乱:
    <span style="display: inline-block; transform: rotate(90deg); transform-origin: top left;">REPRINT</span>
    
  2. 在C#转换代码中启用CSS转换支持:
    var options = new HtmlLoadOptions();
    options.CssLoadOptions.AllowTransform = true;
    
    var document = DocumentModel.Load("input.html", options);
    document.Save("output.pdf");
    

方案3:使用GemBox的文本旋转API手动处理

若上述方法均无效,可在转换后通过API手动旋转目标文本:

  1. 加载HTML文档并定位包含"REPRINT"的元素:
    var document = DocumentModel.Load("input.html");
    var reprintText = document.Content.Find("REPRINT").FirstOrDefault();
    
  2. 对该文本应用旋转格式:
    if (reprintText != null)
    {
        var paragraph = reprintText.Parent as Paragraph;
        if (paragraph != null)
        {
            paragraph.Format.TextRotation = TextRotation.Right;
        }
    }
    document.Save("output.pdf");
    

注意:不同版本的GemBox对CSS属性的支持范围不同,优先尝试升级版本是最直接的解决方式。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.16 19:31:03