using System;
using System.Collections.Generic;
using System.Text;
using iTextSharp.text;
using iTextSharp.text.pdf;
using PdfModel = Supplier.Model.PdfModel;
using PackingDetailModel = Supplier.Model.PackingDetailModel;
using GatherNumberModel = Supplier.Model.GatherNumberModel;
namespace Supplier.Common
{
public sealed class GeneratePDF
{
public static void GenerateMainTable(PdfModel pdf, GatherNumberModel gatherNumber, Document document, string[] viaTypeArray, IList<string> dataList, IList<PackingDetailModel> packingDetailList)
{
for (int p = 0; p < pdf.PageCount; p++)//总页数
{
pdf.PageIndex = p;//设置页码索引
PdfPTable table = new PdfPTable(1);//生成一个只有一列的表
table.WidthPercentage = 100f;//表占页面100%宽度
table.SetTotalWidth(new float[] { 585f });//表的总宽度
table.LockedWidth = true;//必须固定表的宽度,然后再可以设置表中单元格的各个宽度.
PdfPCell cell;
#region The first child table
PdfPTable cellTable1 = new PdfPTable(3);
cellTable1.SetTotalWidth(new float[] { 100f, 330f, 150f });//第一个字表,共3列,每列的宽度
cellTable1.LockedWidth = true;//固定每列宽度
PdfPCell cell1;
Phrase phrase1;
//first row
phrase1 = new Phrase(" PRIME MODERN LIMITED", PdfFont.FB18());
cell1 = new PdfPCell(phrase1);
cell1.Colspan = 2;
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0.1f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase("PACKING LIST", PdfFont.FB18());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 2;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0.1f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
//second row
phrase1 = new Phrase(" BILL TO:", PdfFont.FB8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
cell1 = new PdfPCell(new Phrase(" "));
cell1.BorderWidth = 0f;
cellTable1.AddCell(cell1);
cell1 = new PdfPCell(new Phrase(" "));
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
//third row
string[] billTo = StringHelper.StringToArray(dataList[0], ';');
phrase1 = new Phrase(" " + billTo[0].Trim(), PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.NoWrap = true;
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase("SHIPPING LINE", PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 2;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase(dataList[2], PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
//fourth row
phrase1 = new Phrase(" " + billTo[1].Trim(), PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 0;
cell1.NoWrap = true;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase("SHIPPED VIA", PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 2;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase(dataList[4], PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
//fifth row
string thirdBill = (billTo.Length > 2) ? billTo[2].Trim() : " ";
phrase1 = new Phrase(" " + thirdBill, PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.NoWrap = true;
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase("DATE SENT", PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 2;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase(DateHelper.EuropeanDate(dataList[3]), PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0.1f;
cellTable1.AddCell(cell1);
//sixth row
string fourthBill = (billTo.Length > 3) ? billTo[3].Trim() : " ";
phrase1 = new Phrase(" " + fourthBill, PdfFont.FN8());
cell1 = new PdfPCell(phrase1);
cell1.NoWrap = true;
cell1.HorizontalAlignment = 0;
cell1.BorderWidthLeft = 0.1f;
cell1.BorderWidthTop = 0f;
cell1.BorderWidthBottom = 0f;
cell1.BorderWidthRight = 0f;
cellTable1.AddCell(cell1);
phrase1 = new Phrase(viaTypeArray[0], PdfFont.FN8());
cell1 = new PdfPCell(ph
PDF生成嵌套表格,分页,自定义字体等综合应用
最新推荐文章于 2024-07-21 03:50:00 发布
本文介绍了如何在PDF中创建复杂的嵌套表格,实现分页功能,并详细讲解了自定义字体的设置过程,提供了一个实用的PDF生成综合应用案例。
摘要由CSDN通过智能技术生成