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

使用org.dita.pdf2插件转换时无空格文本单元格溢出问题

解决DITA-OT 3.7.4 + org.dita.pdf2转PDF时无空格文本超出表格单元格的问题

方法1:修改FO样式强制单元格内文本换行

org.dita.pdf2基于XSL-FO生成PDF,直接自定义XSL规则让表格单元格支持自动换行:

  • 找到你的PDF自定义样式文件(比如项目里的custom.xsl,没有的话新建一个),添加以下模板:
    <xsl:template match="*[contains(@class, 'topic/entry')]">
      <fo:table-cell xsl:use-attribute-sets="entry">
        <fo:block wrap-option="wrap" hyphenate="true" hyphenation-character="-">
          <xsl:apply-templates/>
        </fo:block>
      </fo:table-cell>
    </xsl:template>
    
  • 说明:wrap-option="wrap"强制文本换行,hyphenate="true"允许英文长单词断字;如果是中文长文本,要确保使用的FO处理器(比如Apache FOP)支持中文断字,可能需要额外配置中文字体的断字字典。

方法2:在DITA源文件中处理长文本

针对特定的无空格长字符串(比如URL、代码串),直接在源文件里做处理:

  • 插入软连字符&shy;,让文本可以在指定位置断行:
    <entry>verylongstringthatneedstobreak&shy;hereisanotherpart</entry>
    
  • 或者给长文本套<codeph>标签,再配置其FO样式支持换行:
    源文件写法:
    <entry><codeph>verylongcodewithoutspaces</codeph></entry>
    
    然后在custom.xsl里添加模板:
    <xsl:template match="*[contains(@class, 'topic/codeph')]">
      <fo:inline wrap-option="wrap" hyphenate="false">
        <xsl:apply-templates/>
      </fo:inline>
    </xsl:template>
    

方法3:调整FO处理器配置

DITA-OT 3.7.4默认使用Apache FOP,检查FOP的配置文件fop.xconf,开启自动断字和换行支持:

<fop version="1.0">
  <renderers>
    <renderer mime="application/pdf">
      <auto-hyphenation>true</auto-hyphenation>
      <hyphenation-limit>2</hyphenation-limit>
    </renderer>
  </renderers>
</fop>

修改后通过命令行参数让DITA-OT加载该配置:dita -f pdf2 -Dfop.config=./fop.xconf

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 17:12:36