Dim doc As New Printdoc
doc.PageSetting.PaperKind = 9 '纸张类型改为A4
Doc.PageSetting.LeftMargin = 16 '设置左边距
Doc.PageSetting.RightMargin = 16 '设置右边距
Doc.PageSetting.TopMargin = 25 '设置上边距
Doc.PageSetting.BottomMargin = 20 '设置下边距
Dim tbl As Table = Tables("数据")
For i As Integer = tbl.TopRow To tbl.BottomRow
Dim r As Row = tbl.Rows(i)
Dim rs As New prt.RenderText() '定义一个文本对象
Dim rt As prt.RenderTable
rt = New prt.RenderTable
'加入标题
rs.Text = Tables("系统设置")(0,"我的年级") & r("科目") & "卡片" '设置文本对象的内容
rs.Style.Font = New Font("宋体", 18 , FontStyle.Bold) '设置文本对象的字体
rs.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rs.Style.Spacing.Bottom = 6 '和下面的对象(表格)距离3毫米
doc.Body.Children.Add(rs) '加入到报表中
'指定行数?列数?列宽?行高
rt.Rows.Count = 4 '设置总行数
rt.Cols.Count = 2 '设置总列数
'rt.Height = 234 '设置表格的高度为80毫米
rt.Rows(0).Height = 18
rt.Rows(1).Height = 96
rt.Rows(2).Height = 96
rt.Rows(3).Height = 28
rt.Cols(0).Width = 9.5
rt.Cols(1).Width = 167
rt.CellStyle.Spacing.All = 1 '内容距离网格线1毫米
rt.Style.GridLines.All = New Prt.LineDef(0.2, Color.Black)
'设置合并单元格
rt.Cells(0,0).SpanCols = 2 '第5行第2个单元格向右合并3列
'指定每一个单元格的内容
rt.Style.TextAlignVert = prt.AlignVertEnum.Center '内容垂直居中
rt.Style.TextAlignHorz = prt.AlignHorzEnum.Center '水平居中排列
rt.Rows(0).Style.TextAlignHorz = prt.AlignHorzEnum.left '唯独第7行是备注,内容靠上对齐
Dim rm As New prt.RenderImage '定义一个图片对象
rm.Image = GetImage(ProjectPath & "Attachments\错题\" & r("编号") & "TM" &".jpg") '设置图片
rm.Width = "Parent.Width" '宽度等于页面宽度
rm.Height = "Auto" '高度由图片大小自动决定
rt.Cells(1,1).Image = rm.Image
rt.Cells(1,1).Style.ImageAlign.AlignHorz = prt.ImageAlignHorzEnum.Center '水平居中
doc.AutoRotate = False '禁止自动旋转打印内容
doc.Body.Children.Add(rt)
Next
doc.Preview