Я пытаюсь сделать принтер этикеток со штрих-кодом через ячейки. У меня есть pdfTable с 3 столбцами. Но каждый раз, когда я пытался экспортировать pdfTable с количеством ячеек, которое не равно или не делится на 3 (это количество столбцов), количество ячеек всегда увеличивается или уменьшается на 1.
Например :
Попытался экспортировать 30 ячеек, которые делятся на столбцы pdfTable, равные 3 (отлично работает)
Пытался экспортировать 1 или 10 ячеек, которые не делятся на столбцы pdfTable, равные 3 (количество ячеек всегда отключено на 1). В результате 1 ячейка становится 2 ячейками, а 10 ячеек становятся 11 ячейками.
Я всегда проверяю, есть ли что-то не так с моим циклом, из-за которого ячейки увеличиваются на 1, но я ничего не могу найти.
Вот мой код для экспорта PDF:
Public Function print_itembarcodes(lbl169 As Label)
Dim pdfTable As New PdfPTable(3) 'pdfTable Column Count'
pdfTable.DefaultCell.Padding = 3
pdfTable.WidthPercentage = 100
pdfTable.HorizontalAlignment = Element.ALIGN_CENTER
pdfTable.DefaultCell.Border = Rectangle.NO_BORDER
Dim emptyCell As New PdfPCell
emptyCell.Border = 0
Dim count As Integer
count = 0
For i As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows.Count - 1 'Read item one by one'
Admin_Menu.Label169.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(1).Value
Admin_Menu.Label170.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(0).Value
Admin_Menu.Label171.Text = Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(4).Value
Barcode.process_printbarcode(Admin_Menu.Label169)
save_printbarcode()
For j As Integer = 0 To Admin_Menu.BarcodePrintListGrid.Rows(i).Cells(5).Value 'Cell quantity to be exported for one item'
pdfTable.AddCell(create_barcodecell) 'Create a cell with barcode'
count = count + 1
Next
Next
For k As Integer = 0 To count Mod 3
pdfTable.AddCell(emptyCell)
Next
count = 0
Try
'Exporting to PDF'
Dim folderPath As String = "C:\Temp\"
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using stream As New FileStream(folderPath & "temp2.pdf", FileMode.Create)
Dim pdfdoc As New Document(PageSize.A4, 15.0F, 15.0F, 10.0F, 20.0F)
PdfWriter.GetInstance(pdfdoc, stream)
pdfdoc.Open()
pdfdoc.Add(pdfTable)
pdfdoc.Close()
stream.Close()
System.Diagnostics.Process.Start("C:\\Temp\\temp2.pdf")
End Using
Catch ex As MySqlException
MsgBox(ex.Message)
Finally
MysqlConn.Dispose()
End Try
Return True
End Function
Вот мой код для функции создания ячейки со штрих-кодом:
Public Function create_barcodecell()
Dim SaveFileDialog1 = "D:\School\Capstone\Sta. Lucia East Bowling and Billiard Hall Management System\Item Barcodes\"
Dim Barcode2 As Image = Image.GetInstance(SaveFileDialog1 + Admin_Menu.Label169.Text + ".png")
Barcode2.ScaleAbsolute(170.0F, 50.0F)
img.ScalePercent(20.0F)
img.Alignment = iTextSharp.text.Image.ALIGN_CENTER
Dim itemname, itemprice, itemcode As New Paragraph
itemname.Alignment = Element.ALIGN_CENTER
itemprice.Alignment = Element.ALIGN_CENTER
itemcode.Alignment = Element.ALIGN_CENTER
Dim codeFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 10)
Dim tagFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
Dim priceFont = FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 11)
codeFont.Color = BaseColor.WHITE
tagFont.Color = BaseColor.WHITE
priceFont.Color = BaseColor.WHITE
itemname.Add(New Chunk(Admin_Menu.Label170.Text, tagFont))
itemprice.Add(New Chunk("P " + Admin_Menu.Label171.Text + ".00", priceFont))
itemcode.Add(New Chunk(Admin_Menu.Label169.Text, codeFont))
Dim pdfCell As New PdfPCell
pdfCell.UseVariableBorders = True
pdfCell.BackgroundColor = BaseColor.RED
pdfCell.BorderColorLeft = BaseColor.BLACK
pdfCell.BorderColorRight = BaseColor.BLACK
pdfCell.BorderColorTop = BaseColor.BLACK
pdfCell.BorderColorBottom = BaseColor.BLACK
pdfCell.PaddingTop = 10
pdfCell.PaddingBottom = 10
pdfCell.PaddingLeft = 8
pdfCell.PaddingRight = 10
pdfCell.AddElement(img)
pdfCell.AddElement(itemname)
pdfCell.AddElement(Barcode2)
pdfCell.AddElement(itemcode)
pdfCell.AddElement(itemprice)
Return pdfCell
End Function