如何像 Microsoft Office Publisher 一样一次打印身份证件?
How to print collection of ID cards in one print like Microsoft Office Publisher?
在我的应用程序中,我有一个用于创建员工身份证的表格。一切都很好,但我在将所有选定的身份证添加到页面时遇到打印问题。就像在 1 页中打印大约 4 张横向卡片非常容易,这可以使用打印文档方法和 rdlc 报告来完成。我在哪里使用 printdocument 的 PrintPage 事件来完成作业和 rdlc 报告的参数。但两者都限制为每次打印 4 张卡片。但是我想要的是假设有二十个新员工需要身份证,我想一次打印出来。
我尝试了什么?
打印文档方法
将所有身份证添加到DataGridView,然后在PrintDocument的PrintPage事件中使用此代码
Dim i as integer = 25
For j as Integer = 0 To dgv.rowcount - 1
e.Graphics.DrawImage(dgv.rows(j).Cells(0).Value, 25, i, 375, 236)
i += 241
Next
i = 25
But this can only print up to 4 cards per print. I tried to use e.HasMorePages = True
but couldn't make it work to get what I want.
RDLC报告方法
创建一个数据集 DS1,并添加一个 tables,其列名与我的 datagridview 列名相同,然后使用数据集 DS1 创建一个 rdlc 报告,并在其中添加一个 table只有图像列可见。
But unfortunately this was the biggest fail in this case as it cannot even show a single picture. So I had an option to create pictures on the report and use the Parameter method to get the values from the form which again restricts me from printing more than 4 cards per print.
下面是一个在多页上打印项目列表的示例。在这种情况下,它在一页上完成了四次。
Const ITEMS_PER_PAGE As Integer = 4
Private items As List(Of Object)
Private itemIndex As Integer
Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
'Start from the beginning of the list.
itemIndex = 0
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
For i = 1 To ITEMS_PER_PAGE
If itemIndex = items.Count Then
'We're done.
Exit For
End If
Dim item = items(itemIndex)
'Print item here.
itemIndex += 1
Next
'Print another page if and only if we are not at the end of the list.
e.HasMorePages = itemIndex < items.Count
End Sub
请注意 itemIndex
在 PrintPage
事件处理程序调用之间保持其值。
在我的应用程序中,我有一个用于创建员工身份证的表格。一切都很好,但我在将所有选定的身份证添加到页面时遇到打印问题。就像在 1 页中打印大约 4 张横向卡片非常容易,这可以使用打印文档方法和 rdlc 报告来完成。我在哪里使用 printdocument 的 PrintPage 事件来完成作业和 rdlc 报告的参数。但两者都限制为每次打印 4 张卡片。但是我想要的是假设有二十个新员工需要身份证,我想一次打印出来。
我尝试了什么?
打印文档方法
将所有身份证添加到DataGridView,然后在PrintDocument的PrintPage事件中使用此代码
Dim i as integer = 25
For j as Integer = 0 To dgv.rowcount - 1
e.Graphics.DrawImage(dgv.rows(j).Cells(0).Value, 25, i, 375, 236)
i += 241
Next
i = 25
But this can only print up to 4 cards per print. I tried to use
e.HasMorePages = True
but couldn't make it work to get what I want.
RDLC报告方法
创建一个数据集 DS1,并添加一个 tables,其列名与我的 datagridview 列名相同,然后使用数据集 DS1 创建一个 rdlc 报告,并在其中添加一个 table只有图像列可见。
But unfortunately this was the biggest fail in this case as it cannot even show a single picture. So I had an option to create pictures on the report and use the Parameter method to get the values from the form which again restricts me from printing more than 4 cards per print.
下面是一个在多页上打印项目列表的示例。在这种情况下,它在一页上完成了四次。
Const ITEMS_PER_PAGE As Integer = 4
Private items As List(Of Object)
Private itemIndex As Integer
Private Sub PrintDocument1_BeginPrint(sender As Object, e As PrintEventArgs) Handles PrintDocument1.BeginPrint
'Start from the beginning of the list.
itemIndex = 0
End Sub
Private Sub PrintDocument1_PrintPage(sender As Object, e As Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
For i = 1 To ITEMS_PER_PAGE
If itemIndex = items.Count Then
'We're done.
Exit For
End If
Dim item = items(itemIndex)
'Print item here.
itemIndex += 1
Next
'Print another page if and only if we are not at the end of the list.
e.HasMorePages = itemIndex < items.Count
End Sub
请注意 itemIndex
在 PrintPage
事件处理程序调用之间保持其值。