Asp.net

如何在 iTextSharp 中顯示水平線

  • June 5, 2013

我正在創建一個 pdf,需要在頁面中放置一條水平線。誰能告訴我該怎麼做?

我有一個 xml 文件,其中包含我的 html 標籤(<table>....</table>)。並且文件的全部內容xml被解析string​​為用於創建pdf. 現在不支持某些標籤。其中之一是<hr>。那麼我可以在文件中使用任何其他標籤,以便在使用 xml 數據創建 pdf 時xml繪製一個 。line

下面是一個xml xontent的例子

<table>
  <tr>
    <td>
      <span>
          This is working properly.
      </span>
    </td>
  <tr>
</table>

<table>
  <tr>
    <td>
      <span>
          <hr>
          This is not working properly.
      </span>
    </td>
  <tr>
</table>

如果需要更多資訊,請告訴我。

提前致謝。

以下創建了一條幾像素厚的全寬黑線,我正在使用HTMLWorker.Parse

<table>
  <tr>
   <td>
      <span>
          This is working properly.
      </span>
   </td>
  <tr>
</table>

<table>
  <tr>
   <td>
      <span>
      <table border="1" cellpadding="0" cellspacing="0"><tr><td> </td></tr></table>

          This is working properly now too!
      </span>
   </td>
  <tr>
</table>

您可以從起始位置 (moveto)、LineTo 繪製線條,然後描邊(送出線條):

...
PdfContentByte cb = writer.DirectContent;
....
cb.MoveTo(doc.PageSize.Width / 2, doc.PageSize.Height / 2);     
cb.LineTo(doc.PageSize.Width / 2, doc.PageSize.Height);     
cb.Stroke();
...

引用自:https://stackoverflow.com/questions/15335431