2017-03-08 26 views
0

我正在使用iTextSharp程序集版本5.5.10,並認爲要面對一個錯誤。當我將我的SetSimpleColumns放置在某個未知的原因時,第11到第14t列保留在同一行上。 我首先想到它與邊距有關,但我的矩形具有相同的座標位置正確。SetSimpleColumn在第10行後不對齊

這是結果的樣子:

position example

的代碼如下:

Dim iADsPerPage As Integer = 14 
Dim iRow As Integer = 0 
dBottom = 760 'Next Line (one line = 15) 

For Each oRow As DataRow In dtADs.Rows 
    iRow = iRow + 1 
    dBottom = dBottom - 43.6 'Next Line (one line = 15) 

    myText = New Phrase(oRow("BulletinReference").ToString, oFont) 
    dLeftSide = 102.0 
    dCellSize = 106.0 
    ct.SetSimpleColumn(myText, dLeftSide, dBottom + dFontLine, dLeftSide + dCellSize, dCellSize, 0, Element.ALIGN_CENTER) 
    ct.Go() 

    myText = New Phrase(Left(oRow("BulletinReference").ToString, 40), oFont) 
    dLeftSide = 210.0 
    dCellSize = 302.0 
    cb.Rectangle(dLeftSide, dBottom, dCellSize, dCellHeight) 
    cb.Stroke() 
    Response.Write(">" & " " & dLeftSide & " " & dBottom + dFontLine & " " & dLeftSide + dCellSize & " " & dCellSize & "<<br>") 
    ct.SetSimpleColumn(myText, dLeftSide, dBottom + dFontLine, dLeftSide + dCellSize, dCellSize, 0, Element.ALIGN_LEFT) 
    ct.Go() 

    If iRow = 11 Then 'force position as test 
     myText = New Phrase("hello world!!!!!!!!!!!!!!!!!", oFont) 
     ct.SetSimpleColumn(myText, 210, 100, 210 + 302, 302, 0, Element.ALIGN_LEFT) 
     ct.Go() 
    End If 
Next 
+0

可惜我不能重現這種行爲。數據行的內容可能有些可疑。你不檢查'ct.Go()'調用的結果,也許有些內容不能正確設置。 – mkl

+0

我也在期待這個,但請查看hello world的例子。還有一個被放置在相同的位置。沒有什麼特別的文字。我注意到的一點是,當我將最後一個座標設置爲0而不是302時似乎工作。只有我不完全理解背後的邏輯。 – WiVM

回答

0

您在SetSimpleColumn第五個參數使用錯誤的值(和在第三,但這並不完全錯誤):

ct.SetSimpleColumn(myText, dLeftSide, dBottom + dFontLine, dLeftSide + dCellSize, dCellSize, 0, Element.ALIGN_CENTER) 

當你看到你總是使用dCellSize那裏,大概假設參數是區域的高度,但該方法被定義爲:

/** 
* Simplified method for rectangular columns. 
* @param phrase a <CODE>Phrase</CODE> 
* @param llx the lower left x corner 
* @param lly the lower left y corner 
* @param urx the upper right x corner 
* @param ury the upper right y corner 
* @param leading the leading 
* @param alignment the column alignment 
*/ 
virtual public void SetSimpleColumn(Phrase phrase, float llx, float lly, float urx, float ury, float leading, int alignment) 

即第五個參數應該是該區域的座標上限(顯然不是常數)。

有效的「上部Ÿ」用於第一行實際上表示的底部ÿ和你的「低級Ÿ」頂部ÿ。隨着「更正」加入dFontLine即創造了理想的結果。

只要你的「低Ÿ」實際上開始表示底部Ÿ,頂部Ÿ保持不變,所以從那裏所有條目在同一高度進行打印。

這也說明了你的觀察從評論:

東西我注意到是,似乎當我把最後一個座標爲0,而不是302

這樣,你的「工作上部「仍然是頁面的底部。因此,「上」和「下」保持切換,但始終如此。

我假設你要沿着這條線的東西:

ct.SetSimpleColumn(myText, dLeftSide, dBottom, dLeftSide + dCellSize, dBottom + dCellHeight, 0, Element.ALIGN_CENTER) 
+0

這似乎是訣竅: ct.SetSimpleColumn(myText,dLeftSide,dBottom + dFontLine,dLeftSide + dCellSize,dBottom - dCellHeight,0,Element。ALIGN_CENTER) 謝謝! – WiVM

+0

@WiVM那麼,這個參數組合實際上是使用頂部和底部的** y **以相反的順序,但這是iText在內部糾正的;如果由於某種原因,您碰巧有一行的單元格內容太長,您將得到第二行,這將重疊您的單元格邊界。如果這對您沒有問題,請使用這些參數。 – mkl