我想针对一项创建多页帮助我

时间:2019-05-30 20:10:39

标签: c# barcode

我想针对一个项目创建多个条形码页面,例如项目具有3种颜色,这意味着如果项目具有3种颜色和3种大小,则自动创建3个页面。

我搜索了超过3天,但找不到任何解决方法

private byte[] GenerateItemBarCodePDF(int ItemId, int ItemDetailID, int ColorID)
{
    dsrptInventory ds = new dsrptInventory();
    ds.EnforceConstraints = false;
    dsrptInventoryTableAdapters.vItemBarcodeTableAdapter _taItemBarCode = new dsrptInventoryTableAdapters.vItemBarcodeTableAdapter();
    _taItemBarCode.Fill(ds.vItemBarcode, ItemId,ItemDetailID,ColorID);
    if (ds.vItemBarcode.Count > 0)
    {
        using (MemoryStream output = new MemoryStream())
        {
                var item = ds.vItemBarcode[0];

                iTextSharp.text.Rectangle small = new iTextSharp.text.Rectangle(144f, 72f);
                iTextSharp.text.Font smallfont = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 8);
                Document document = new Document(small, 15, 15, 10, 0);
                PdfWriter writer = PdfWriter.GetInstance(document, output);
                document.Open();

                PdfPTable table = new PdfPTable(1);
                table.WidthPercentage = 110;
                table. DefaultCell. Border = iTextSharp. text. Rectangle .NO_BORDER;
                PdfContentByte cb = writer.DirectContent;
                Barcode128 code128 = new Barcode128();
                code128.CodeType = iTextSharp.text.pdf.Barcode.CODE128;
                code128.ChecksumText = true;
                code128.GenerateChecksum = true;
                code128.StartStopText = true;
                code128.Font = null;
                code128.Code = item.ItemCode;
                code128.BarHeight = 18;
                table.AddCell(barCodeCell);
                PdfPCell itemNameCell = new PdfPCell(new Phrase(item.ItemName, smallfont));
                itemNameCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                itemNameCell.VerticalAlignment = Element.ALIGN_CENTER;
                itemNameCell.HorizontalAlignment = Element.ALIGN_CENTER;
                table.AddCell(itemNameCell);
                PdfPCell itemCodeCell = new PdfPCell(new Phrase(item.ItemCode, smallfont));
                itemCodeCell.Border = iTextSharp.text.Rectangle.NO_BORDER;
                itemCodeCell.VerticalAlignment = Element.ALIGN_CENTER;
                itemCodeCell.HorizontalAlignment = Element.ALIGN_CENTER;
                itemCodeCell.UseAscender = true;
                table.AddCell(itemCodeCell);
                document.Add(table);
                    document.Close();
            return output.ToArray();
        }
    }
    return null;
}

0 个答案:

没有答案