0

我已经修改了 XMLWorkerHelper.ParseToElementList 方法,以便我使用 UTF-8 编码来转换附加的 HTML。

<p>​&lt;span style="font-size: 10pt; font-family: &quot;tahoma&quot;, &quot;sans-serif&quot;">Med pripravo vozil za ladjo M/V SEA PATRIS, dne 19.02.2017 je prišlo do delovne nezgode in poškodbe dveh vozil Seat Ateca. Voznik ( RETRANS d.o.o.) je z vozilom Seat Ateca VIN: VSSZZZ5FZH6536022 &#160;zapeljal vzvratno in trčil v stoječe vozilo Seat Ateca VIN: VSSZZZ5FZH6545134.</span> </p>
<div><span style="font-size: 10pt; font-family: &quot;tahoma&quot;, &quot;sans-serif&quot;">&#160;</span></div>
<div><span style="font-size: 10pt; font-family: &quot;tahoma&quot;, &quot;sans-serif&quot;">Priloge: fotografije, seznam poškodb&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; </span></div>
<div><span style="font-size: 10pt; font-family: &quot;tahoma&quot;, &quot;sans-serif&quot;">&#160;</span></div>
<table class="MsoNormalTable" border="1" cellspacing="0" cellpadding="0" style="border-top: black 1pt solid; border-right: black 1pt solid; background: white; border-bottom: black 1pt solid; border-left: black 1pt solid"><tbody><tr><td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">#</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">PR</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">DATUM PREGLEDA</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">VIN</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">DEL</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">OPIS DELA</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">POŠK</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">OPIS POŠKODBE</span></b></div></td>
<td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><b><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">DIMENZIJE / OPOMBE</span></b></div></td></tr>
<tr><td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">1</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">ZP</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">2017-02-19&#160;11:56:52.0</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">VSSZZZ5FZH6536022</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">43</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">zadnji&#160;odbijač</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">12</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">PODRSANO</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">100X10&#160;20X2&#160;10X2&#160;50X2</span></div></td></tr>
<tr><td style="border-top: gray 1pt solid; border-right: gray 1pt solid; background: #ededed; border-bottom: gray 1pt solid; padding-bottom: 0.75pt; padding-top: 0.75pt; padding-left: 1.5pt; border-left: gray 1pt solid; padding-right: 1.5pt"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: black">2</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">ZP</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">2017-02-19&#160;11:57:38.0</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">VSSZZZ5FZH6545134</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">43</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">zadnji&#160;odbijač</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">12</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">PODRSANO</span></div></td>
<td style="border-top: #cccccc 1pt solid; border-right: #cccccc 1pt solid; border-bottom: #cccccc 1pt solid; padding-bottom: 0cm; padding-top: 0cm; padding-left: 1.5pt; border-left: #cccccc 1pt solid; padding-right: 1.5pt; background-color: transparent"><div><span style="font-size: 8.5pt; font-family: &quot;verdana&quot;, &quot;sans-serif&quot;; color: #303030">800X50</span></div></td></tr></tbody></table>
<p>&#160;</p>

编码设置为 UTF-8。

//ParseToElementList overided method (UTF-8)
public static ElementList ParseToElementList(String html, String css)
{
    // CSS
    ICSSResolver cssResolver = new StyleAttrCSSResolver();
    if (css != null)
    {
        ICssFile cssFile = XMLWorkerHelper.GetCSS(new MemoryStream(Encoding.UTF8.GetBytes(css)));
        cssResolver.AddCss(cssFile);
    }

    // HTML
    CssAppliers cssAppliers = new CssAppliersImpl(FontFactory.FontImp);
    HtmlPipelineContext htmlContext = new HtmlPipelineContext(cssAppliers);
    htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
    htmlContext.AutoBookmark(false);

    // Pipelines
    ElementList elements = new ElementList();
    ElementHandlerPipeline end = new ElementHandlerPipeline(elements, null);
    HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, end);
    CssResolverPipeline cssPipeline = new CssResolverPipeline(cssResolver, htmlPipeline);

    // XML Worker
    XMLWorker worker = new XMLWorker(cssPipeline, true);
    XMLParser p = new XMLParser(worker);
    p.Parse(new MemoryStream(Encoding.UTF8.GetBytes(html)));

    return elements;
}

将解析后的 H​​TML 填充到 PdfCell 中

List<IElement> elementsIzv = ParseToElementList(nonConformity[Helper_ND_Display.porociloIzvedba].ToString(), null);
foreach (IElement e in elementsIzv)
{
    porociloData.AddElement(e);
}
resitevTable.AddCell(porociloData);

除了字符 č(Č) (č) 之外的所有工作都没有被转换(丢失)。我错过了什么或者 ParseToElementList 方法中是否存在错误?使用 GetInstance 方法转换 HTML

XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, reader);

正在根据需要转换所有字符。

4

0 回答 0