【问题标题】:Wraping continous text in Itext sharp在 Itextsharp 中换行连续文本
【发布时间】:2018-03-03 01:30:51
【问题描述】:

我已将代码添加到 itext sharp 以换行连续文本。这里例如一个网址。 这些 css 在 Web 浏览器中工作时工作正常,但是当我导出为 pdf 时,url 不换行。

我无法找到确切的问题。

在线和pdf视图的参考行为图片:

有没有办法用css包装url

.background-color-dark-blue {
    background-color: #485679;
}
.color-light {
    color: #fff !important;
}


.white-space-pre-wrap a {
     word-break: break-all !important;
     word-wrap: break-word;
    word-wrap: break-word !important;
   
}
.break-all {
    word-break: break-all;
    word-wrap: break-word;
}

.url-style a {
    /*font-size: 14px;*/
    line-height: 1.3;
    color: #2a99d4;
    font-weight: 700;
    text-decoration: none;
    margin-top: 0px !important;
}
<table>
                                                <colgroup>
                                                    <col class="col-3">
                                                    <col class="col-4">
                                                    <col class="col-5">
                                                </colgroup>
                                                <thead>
                                                    <tr class="background-color-dark-blue ">
                                                        <th class="color-light">
                                                            Document Name</th>
                                                        <th class="color-light">
                                                            Document Description</th>
                                                        <th class="color-light">
                                                            Location/Link</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    
                                        <tr class="bg-color-lighter">
                                            <td class="va-top">FATF 40 Recommendations</td>
                                            <td class="va-top">Global standard for AML/CFT published by the Financial Action Task Force </td>
                                            <td class="review-report-url-fix  padding-left-5 break-all va-top">
                                                <div class="break-all  va-top">
                                                <a id="SiteContentPlaceHolder_AppendicesReviewControl_ReferenceDocumentListView_ReferenceDocumentLink_0" title="http://www.fatf-gafi.org/publications/fatfrecommendations/
 http://www.fatf-gafi.org/publications/fatfrecommendations/documents/risk-based-approach-banking-sector.html" class="url-style white-space-pre-wrap" href="http://www.fatf-gafi.org/publications/fatfrecommendations/%0d%0a%20http://www.fatf-gafi.org/publications/fatfrecommendations/documents/risk-based-approach-banking-sector.html" target="_blank">http://www.fatf-gafi.org/publications/fatfrecommendations/
 http://www.fatf-gafi.org/publications/fatfrecommendations/documents/risk-based-approach-banking-sector.html</a>
                                                    </div>
                                                
                                            </td>

                                        </tr>
                                    
                                        <tr class="bg-color-dashboard-table">
                                            <td class="va-top">Risk Based Approach Guidance for Legal Professionals</td>
                                            <td class="va-top">Guidance on the AML/CFT Risk Based Approach for lawyers and the legal profession</td>
                                            <td class="review-report-url-fix  padding-left-5 va-top">
                                                <div class="break-all  va-top">
                                                <a id="SiteContentPlaceHolder_AppendicesReviewControl_ReferenceDocumentListView_ReferenceDocumentLink_1" title="http://www.fatf-gafi.org/publications/fatfrecommendations/documents/riskbasedapproachguidanceforlegalprofessionals.html" class="url-style white-space-pre-wrap" href="http://www.fatf-gafi.org/publications/fatfrecommendations/documents/riskbasedapproachguidanceforlegalprofessionals.html" target="_blank">http://www.fatf-gafi.org/publications/fatfrecommendations/documents/riskbasedapproachguidanceforlegalprofessionals.html</a>
                                                    </div>
                                                
                                            </td>

                                        </tr>                                   
                                    
                                                </tbody>
                                            </table>

【问题讨论】:

  • 只是为了确定:您使用哪个 iText 版本? 5.5.x 与 XmlWorker 或 7.0.x 与 HtmlConverter?
  • 我刚刚在 iText 支持系统中查看了最近一张工单的详细信息,您就是举报此问题的同一位客户。我负责这个问题的同事会通过 JIRA 给你一个解决方案,我们不会在 Stack Overflow 上发布解决方案。但是,一旦您从我们这里获得该解决方案,您就可以将该解决方案复制到 Stack Overflow。
  • 我使用的是 Itext 7.0 版

标签: css itext word-wrap


【解决方案1】:

Itext 7.0 版有内置库函数

SetSplitCharacters(ISplitCharacters splitCharacters);

所以要在 Itext 7 中使用代码分割字符

 public string SplitChars { get; set; } = ".+-/";
var document = new Document(pdf, PageSize.LETTER, false)
document.SetSplitCharacters(new CustomSplitCharacters(SplitChars));

所以现在一个连续的 url 将在每个 .+-/ 处中断,当它位于表格单元格的末尾时

引用库函数的url

http://itextsupport.com/apidocs/itext7/7.0.4/com/itextpdf/layout/ElementPropertyContainer.html

【讨论】:

    猜你喜欢
    • 2015-09-30
    • 2011-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-08
    相关资源
    最近更新 更多