【发布时间】:2012-03-23 08:50:24
【问题描述】:
使用 Itextsharp 的 MVC3 VB.NET 应用程序。我有一段代码可以生成一个 pdf 文件,一切看起来都很棒,但我想在 pdf 文件中的 2 种颜色之间交替使用线条颜色,以便查看它的人容易理解这些值。有没有办法根据字体大小将整行的背景颜色设置为设置颜色?我将在其中使用的函数如下:
For Each _reg_ In _reg
Dim _registrant As reg_info = _reg_
If y_line1 <= 30 Then
doc.NewPage()
_Page = _Page + 1
y_line1 = 670
End If
If y_line1 = 670 Then
cb.BeginText()
cb.SetFontAndSize(BF_Times, 6)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _datePrinted + " " + _timePrinted, 500, 770, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, "Page Number" + " " + _Page, 600, 770, 0)
cb.SetFontAndSize(BF_Times, 8)
cb.ShowTextAligned(PdfContentByte.ALIGN_CENTER, _reportHead + " Overrides ", 304, 720, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "First Name", 20, 700, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Last Name", 80, 700, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Last Four", 160, 700, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "Email Address", 300, 700, 0)
cb.EndText()
End If
cb.BeginText()
cb.SetFontAndSize(BF_Times, 8)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _registrant.first_name, 20, y_line1, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _registrant.last_name, 80, y_line1, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _registrant.last_four_social, 160, y_line1, 0)
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, _registrant.email, 300, y_line1, 0)
_total += 1
cb.EndText()
y_line1 = y_line1 - 15
Next
我考虑过使用 y_line1 设置线条的背景颜色,并使用模数来确定颜色应该是灰色还是白色。但是我在任何地方都没有找到关于如何设置整行背景颜色的代码示例。有什么想法吗????
【问题讨论】:
标签: vb.net pdf-generation itextsharp