本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.SetTotalWidth方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.SetTotalWidth方法的具體用法?C# PdfPTable.SetTotalWidth怎麽用?C# PdfPTable.SetTotalWidth使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.SetTotalWidth方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GeneratePdfElement
public override iTextSharp.text.IElement GeneratePdfElement()
{
TableStyle style = (Manifest != null) ? Manifest.Styles.GetMergedFromConfiguration(Style) : Style;
int columnCount = (Rows.Any()) ? Rows.First().Cells.Count : 0;
iTextPdf.PdfPTable table = new iTextPdf.PdfPTable(columnCount)
{
HorizontalAlignment = (int) (style.HorizontalAlignment ?? TableStyle.Default.HorizontalAlignment.Value),
SpacingBefore = style.SpacingBefore ?? TableStyle.Default.SpacingBefore.Value,
SpacingAfter = style.SpacingAfter ?? TableStyle.Default.SpacingAfter.Value,
LockedWidth = style.LockedWidth ?? TableStyle.Default.LockedWidth.Value,
};
Rows.SelectMany(r => r.Cells).ForEach(c => table.AddCell((iTextPdf.PdfPCell) c.GeneratePdfElement()));
if (style.Widths != null && style.Widths.Any())
{
table.SetTotalWidth(style.Widths);
}
if (style.WidthPercentage.HasValue)
{
table.WidthPercentage = style.WidthPercentage.Value;
}
return table;
}
示例2: Builder
public override void Builder()
{
if (table.Heads == null) throw new Exception();
var columns = table.Heads.Length;
headwidth = new float[columns];
PdfPTable pdfPTable = new PdfPTable(columns);
pdfPTable.LockedWidth = true;
BuildHeader(columns, pdfPTable);
pdfPTable.SkipFirstHeader = true;
BuilBodyData(pdfPTable);
pdfPTable.Complete = true;
pdfPTable.SetTotalWidth(headwidth);
var writer = _pdfBuilder.writer;
var Height = _pdfBuilder.Height;
if (pdfPTable.TotalHeight > Height)
{
Pager(pdfPTable);
}
else
{
pdfPTable.WriteSelectedRows(0, -1, 0, -1, table.Position.X, Math.Abs(table.Position.Y - Height), writer.DirectContent, true);
}
writer.DirectContent.Stroke();
}
示例3: CreateHardwareReport
public static void CreateHardwareReport(string fileName, IEnumerable<HardwareCountReport> hardwares)
{
try
{
Document document = new Document(PageSize.A4, 72, 72, 72, 72);
PdfWriter.GetInstance(document, new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None));
document.Open();
document.Add(new Paragraph(Element.ALIGN_CENTER, "Hardware Report", new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 16, Font.BOLD)));
document.Add(new Chunk(Chunk.NEWLINE));
var table = new PdfPTable(3);
table.SetTotalWidth(new float[] { 25f, 50f, 25f });
table.WidthPercentage = 100;
table.AddCell(new Phrase("Category"));
table.AddCell(new Phrase("Hardware Model/Type"));
table.AddCell(new Phrase("Total"));
foreach (var hw in hardwares)
{
table.AddCell(new Phrase(hw.Category));
table.AddCell(new Phrase(hw.Model));
table.AddCell(new Phrase(hw.Count));
}
document.Add(table);
document.Close();
}
catch (Exception x)
{
Log.Error("Error when creating report.", x);
}
}
示例4: MyEventHandler
public MyEventHandler() {
_header = new PdfPTable(1);
PdfPCell hCell = new PdfPCell(new Phrase("HEADER"));
hCell.Border = Rectangle.NO_BORDER;
_header.AddCell(hCell);
_header.SetTotalWidth(new float[]{300f});
_footer = new PdfPTable(1);
PdfPCell fCell = new PdfPCell(new Phrase("FOOTER"));
fCell.Border = Rectangle.NO_BORDER;
_footer.AddCell(fCell);
_footer.SetTotalWidth(new float[]{300f});
}
示例5: GeneratePDFAggregatedSalesReports
public void GeneratePDFAggregatedSalesReports(List<StoreReport> allReports, string outputPath)
{
string path = outputPath;
FileStream fileStream = File.Create(path);
Rectangle pageSize = new Rectangle(900, 700);
Document pdf = new Document(pageSize);
pdf.SetMargins(.1f, .1f, .1f, .1f);
//pdf.SetMargins(0f, 0f, 0f, 0f);
PdfWriter.GetInstance(pdf, fileStream);
pdf.Open();
var pdfTable = new PdfPTable(TABLE_COLUMNS);
pdfTable.SetTotalWidth(new float[] { 0.5f, 0.3f, 0.2f, 1f, .3f });
FillTable(pdfTable, allReports);
pdf.Add(pdfTable);
pdf.Close();
}
示例6: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var Response = context.HttpContext.Response;
var q = DbUtil.Db.PeopleQuery(id);
var q2 = from p in q
orderby p.Name2
select new
{
First = p.PreferredName,
Last = p.LastName,
p.PeopleId,
dob = p.DOB,
Phone = p.CellPhone.Length > 0 ? p.CellPhone : p.HomePhone,
p.DoNotPublishPhones
};
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "filename=foo.pdf");
var document = new Document(PageSize.LETTER);
document.SetMargins(40f, 36f, 32f, 36f);
var w = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
dc = w.DirectContent;
var cols = new float[] { W, W, W - 10f };
var t = new PdfPTable(cols);
t.SetTotalWidth(cols);
t.HorizontalAlignment = Element.ALIGN_CENTER;
t.LockedWidth = true;
t.DefaultCell.Border = PdfPCell.NO_BORDER;
if (!q2.Any())
document.Add(new Phrase("no data"));
else
foreach (var m in q2)
AddCell(t, m.First, m.Last, m.Phone, m.PeopleId, m.DoNotPublishPhones);
t.CompleteRow();
document.Add(t);
document.Close();
}
示例7: GetSalesAmountData
private PdfPTable GetSalesAmountData(int Invoiceid = 0)
{
double dSalesAmount = 0;
double dTax = 0;
double dTotalTax = 0;
double dTotalAmount = 0;
double dBalanceDue = 0;
decimal dPayment = 0;
string szNotes = "The note";
string szShipping = "";
string szPayment = "";
string szMsg = "";
Paragraph title = null;
//Get the invoice data
Invoice invoice = null;
invoice = db.Invoices.Find(Invoiceid);
if (invoice == null)
{
return null;
}
szNotes = invoice.Note;
szShipping = Convert.ToDecimal(invoice.ShippingHandling).ToString("C");
if (invoice.PaymentAmount == null)
{
dPayment = 0;
}
else
{
dPayment = Convert.ToDecimal(invoice.PaymentAmount);
}
szPayment = dPayment.ToString("C");
//Get the totals
TimelyDepotMVC.Controllers.InvoiceController invoiceCtrl = new Controllers.InvoiceController();
invoiceCtrl.GetInvoiceTotals(invoice.InvoiceId, ref dSalesAmount, ref dTotalTax, ref dTax, ref dTotalAmount, ref dBalanceDue);
string szSalesAmount = dSalesAmount.ToString("C");
string szTotalTax = dTotalTax.ToString("C");
string szTax = dTax.ToString("F2");
string szTotalAmount = dTotalAmount.ToString("C");
string szBalanceDue = dBalanceDue.ToString("C");
Font times01 = FontFactory.GetFont("helvetica-bold", 10, BaseColor.BLACK);
Font times02 = FontFactory.GetFont("helvetica-bold", 10, Font.ITALIC, BaseColor.BLACK);
Font times03 = FontFactory.GetFont("helvetica-bold", 10, Font.UNDERLINE, BaseColor.BLACK);
Font times04 = FontFactory.GetFont("helvetica", 10, BaseColor.BLACK);
Font times05 = FontFactory.GetFont("helvetica", 10, Font.UNDERLINE, BaseColor.BLACK);
Font times06 = FontFactory.GetFont("helvetica", 8, BaseColor.BLACK);
Font times07 = FontFactory.GetFont("helvetica", 10, Font.ITALIC, BaseColor.BLACK);
PdfPTable infotable = new PdfPTable(numColumns: 4);
infotable.WidthPercentage = 100;
infotable.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
infotable.SpacingBefore = 25;
PdfPCell nestingcell = null;
PdfPCell hlpCel = null;
//First Row Sales Amount
PdfPTable nested = new PdfPTable(numColumns: 3);
nested.SetTotalWidth(new float[] { 350.6f, 123.6f, 64.2f });
nested.LockedWidth = true;
szMsg = string.Format("Notes:");
title = new Paragraph(szMsg, times06);
hlpCel = new PdfPCell(title);
hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
hlpCel.BorderWidthLeft = 0;
hlpCel.BorderWidthRight = 0;
hlpCel.BorderWidthTop = 0;
hlpCel.BorderWidthBottom = 0;
hlpCel.PaddingTop = 4;
hlpCel.PaddingLeft = 0;
hlpCel.PaddingRight = 0;
hlpCel.PaddingBottom = 1;
//BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
nested.AddCell(hlpCel);
szMsg = string.Format("Sales Amount:");
title = new Paragraph(szMsg, times02);
hlpCel = new PdfPCell(title);
hlpCel.RunDirection = PdfWriter.RUN_DIRECTION_LTR;
hlpCel.BorderWidthLeft = 0;
hlpCel.BorderWidthRight = 0;
hlpCel.BorderWidthTop = 0;
hlpCel.BorderWidthBottom = 0;
hlpCel.PaddingTop = 4;
hlpCel.PaddingLeft = 0;
hlpCel.PaddingRight = 0;
hlpCel.PaddingBottom = 1;
//BorderColorTop = new BaseColor(System.Drawing.Color.LightGray),
hlpCel.HorizontalAlignment = Element.ALIGN_LEFT;
nested.AddCell(hlpCel);
szMsg = string.Format("{0}", szSalesAmount);
title = new Paragraph(szMsg, times02);
hlpCel = new PdfPCell(title);
//.........這裏部分代碼省略.........
示例8: PrintOrdersToPdf
//.........這裏部分代碼省略.........
notesTable.AddCell(cellOrderNote);
cellOrderNote = new PdfPCell(new Phrase(HtmlHelper.ConvertHtmlToPlainText(orderNote.FormatOrderNoteText(), true, true), font));
cellOrderNote.HorizontalAlignment = Element.ALIGN_LEFT;
notesTable.AddCell(cellOrderNote);
//should we display a link to downloadable files here?
//I think, no. Onyway, PDFs are printable documents and links (files) are useful here
}
doc.Add(notesTable);
}
}
#endregion
#region Footer
if (!String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn1) || !String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn2))
{
var column1Lines = String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn1) ?
new List<string>() :
pdfSettingsByStore.InvoiceFooterTextColumn1
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
var column2Lines = String.IsNullOrEmpty(pdfSettingsByStore.InvoiceFooterTextColumn2) ?
new List<string>() :
pdfSettingsByStore.InvoiceFooterTextColumn2
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
if (column1Lines.Count > 0 || column2Lines.Count > 0)
{
var totalLines = Math.Max(column1Lines.Count, column2Lines.Count);
const float margin = 43;
//if you have really a lot of lines in the footer, then replace 9 with 10 or 11
int footerHeight = totalLines * 9;
var directContent = pdfWriter.DirectContent;
directContent.MoveTo(pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight);
directContent.LineTo(pageSize.GetRight(margin), pageSize.GetBottom(margin) + footerHeight);
directContent.Stroke();
var footerTable = new PdfPTable(2);
footerTable.WidthPercentage = 100f;
footerTable.SetTotalWidth(new float[] { 250, 250 });
footerTable.RunDirection = GetDirection(lang);
//column 1
if (column1Lines.Count > 0)
{
var column1 = new PdfPCell(new Phrase());
column1.Border = Rectangle.NO_BORDER;
column1.HorizontalAlignment = Element.ALIGN_LEFT;
foreach (var footerLine in column1Lines)
{
column1.Phrase.Add(new Phrase(footerLine, font));
column1.Phrase.Add(new Phrase(Environment.NewLine));
}
footerTable.AddCell(column1);
}
else
{
var column = new PdfPCell(new Phrase(" "));
column.Border = Rectangle.NO_BORDER;
footerTable.AddCell(column);
}
//column 2
if (column2Lines.Count > 0)
{
var column2 = new PdfPCell(new Phrase());
column2.Border = Rectangle.NO_BORDER;
column2.HorizontalAlignment = Element.ALIGN_LEFT;
foreach (var footerLine in column2Lines)
{
column2.Phrase.Add(new Phrase(footerLine, font));
column2.Phrase.Add(new Phrase(Environment.NewLine));
}
footerTable.AddCell(column2);
}
else
{
var column = new PdfPCell(new Phrase(" "));
column.Border = Rectangle.NO_BORDER;
footerTable.AddCell(column);
}
footerTable.WriteSelectedRows(0, totalLines, pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight, directContent);
}
}
#endregion
ordNum++;
if (ordNum < ordCount)
{
doc.NewPage();
}
}
doc.Close();
}
示例9: OnStartPage
public override void OnStartPage(PdfWriter writer, Document document)
{
base.OnStartPage(writer, document);
Rectangle pageSize = document.PageSize;
PdfPTable headerTable = new PdfPTable(2);
headerTable.SetTotalWidth(new float[]{1,4});
float cellHeight = document.TopMargin;
headerTable.TotalWidth = pageSize.Width;
var leftTable = new PdfPTable(1); // logo y nit
PdfPCell leftTableCell = new PdfPCell( leftTable);
leftTableCell.FixedHeight = cellHeight;
leftTableCell.Padding=0;
leftTableCell.PaddingTop= 5;
leftTableCell.PaddingLeft = 0;
leftTableCell.Border= PdfPCell.NO_BORDER;
headerTable.AddCell(leftTableCell);
var cell = new PdfPCell(Image.GetInstance(LogoFile),false);
cell.FixedHeight = cellHeight*80/100;
cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER;
cell.Padding=0;
cell.PaddingTop=0;
cell.PaddingLeft = 0;
cell.Border= PdfPCell.NO_BORDER;
leftTable.AddCell(cell);
cell = new PdfPCell(new Phrase(Empresa.Nit, F8));
cell.HorizontalAlignment= PdfPCell.ALIGN_CENTER;
cell.Border= PdfPCell.NO_BORDER;
leftTable.AddCell(cell);
//------------------------------------------------------------------------
PdfPTable rightTable = new PdfPTable(4); // Consecutivo, Elaborado por etc...
rightTable.SetTotalWidth(new float[]{3,4,3,6});
PdfPCell rightTableCell = new PdfPCell(rightTable);
rightTableCell.HorizontalAlignment = PdfPCell.ALIGN_RIGHT;
rightTableCell.Padding = 2;
rightTableCell.PaddingTop= 10;
rightTableCell.PaddingBottom = 2;
rightTableCell.FixedHeight = cellHeight;
rightTableCell.Border= PdfPCell.NO_BORDER;
headerTable.AddCell(rightTableCell);
cell = new PdfPCell(new Phrase("", F10));
cell.Border= PdfPCell.NO_BORDER;
cell.Colspan=3;
rightTable.AddCell(cell);
var textoFormato=Empresa.Formato;
cell = new PdfPCell(new Phrase(textoFormato, F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase("", F10));
cell.Border= PdfPCell.NO_BORDER;
cell.Colspan=3;
rightTable.AddCell(cell);
textoFormato=Empresa.Edicion;
cell = new PdfPCell(new Phrase(textoFormato, F10));
cell.Border= PdfPCell.NO_BORDER;
cell.PaddingBottom = 8;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase("Oferta No:", F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase(string.Format("{0}-{1}", Prefijo, Pedido.Consecutivo), F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase("Forma de Pago:", F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase(Pedido.DescripcionFormaPago, F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase("Fecha Envio:", F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase(Pedido.FechaEnvio.HasValue? Pedido.FechaEnvio.Value.Format():"BORRADOR !!!",
F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase("Fecha Aceptación:", F10));
cell.Border= PdfPCell.NO_BORDER;
rightTable.AddCell(cell);
cell = new PdfPCell(new Phrase(Pedido.FechaAceptacion.Format(), F10));
//.........這裏部分代碼省略.........
示例10: GetCarWaybillsPDF
//.........這裏部分代碼省略.........
BarCode.Code128 _Code = new BarCode.Code128();
_Code.ValueFont = new System.Drawing.Font("宋體", 20);
System.Drawing.Bitmap imgTemp = _Code.GetCodeImage(order_id, BarCode.Code128.Encode.Code128A);
imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
iTextSharp.text.Image IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
IMG.ScaleToFit(200, 40);
Chunk orderidck = new Chunk(IMG, 0, 0); //圖片可設置 偏移
imgTemp = _Code.GetCodeImage("D" + dr["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
imgTemp.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
IMG = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
IMG.ScaleToFit(200, 40);
Chunk deliveridck = new Chunk(IMG, 0, 0); //圖片可設置 偏移
//PdfContentByte cb = writer.DirectContent;
// cb.BeginText();
if (i % 2 == 0 && i != 0)
{
document.NewPage();
}
PdfPTable totaltable = new PdfPTable(3);
totaltable.WidthPercentage = 100;
totaltable.SetWidths(new int[] { 45, 2, 53 });
totaltable.DefaultCell.DisableBorderSide(1);
totaltable.DefaultCell.DisableBorderSide(2);
totaltable.DefaultCell.DisableBorderSide(4);
totaltable.DefaultCell.DisableBorderSide(8);
PdfPCell cell;
#region 左邊框
PdfPTable table = new PdfPTable(4);
table.SetTotalWidth(new float[] { 60, 75, 10, 100 });
table.DefaultCell.UseAscender = true;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
table.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
cell = new PdfPCell(new Phrase("出貨日", font));
cell.FixedHeight = 17f;
table.AddCell(cell);
table.AddCell(new Phrase("預定配送日", font));
cell = new PdfPCell(new Phrase("指定時段", font));
cell.Colspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
cell.FixedHeight = 17f;
table.AddCell(cell);
//table.AddCell(new Phrase(DateTime.Now.ToString("yyyyMMdd"), font));
table.AddCell(new Phrase(estimated_delivery_date, font));
table.AddCell(new Phrase(estimated_arrival_period, font));
table.AddCell(new Phrase(sestimated_arrival_period, font));
table.AddCell(new Phrase("收\n件\n人", font));
cell = new PdfPCell(pinfor);
cell.Colspan = 3;
table.AddCell(cell);
table.AddCell(new Phrase("寄件人", font));
font = new iTextSharp.text.Font(bfChinese, 7, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
cell = new PdfPCell(new Phrase("台北市南港區八德路四段768巷5號4F之一 \n\n 吉甲地好市集股份有限公司", font));
cell.UseAscender = true;
cell.HorizontalAlignment = 3;
cell.Colspan = 3;
table.AddCell(cell);
font = new iTextSharp.text.Font(bfChinese, 10, iTextSharp.text.Font.NORMAL, new iTextSharp.text.BaseColor(0, 0, 0));//黑
table.AddCell(new Phrase("訂單編號", font));
cell = new PdfPCell(new Phrase(orderidck));
示例11: GetDeliverDetailsPDF
//.........這裏部分代碼省略.........
}
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, estimated_arrival_period, 350, 765, 0);
}
Phrase ph = new Phrase();
BarCode.Code128 _Code = new BarCode.Code128();
_Code.ValueFont = new System.Drawing.Font("宋體", 20);
System.Drawing.Bitmap imgTemp1 = _Code.GetCodeImage("D" + deliverdetail.Rows[0]["deliver_id"].ToString().PadLeft(8, '0'), BarCode.Code128.Encode.Code128A);
imgTemp1.Save(System.AppDomain.CurrentDomain.BaseDirectory + "\\ImportUserIOExcel\\" + "Code.gif", System.Drawing.Imaging.ImageFormat.Gif);
iTextSharp.text.Image IMG1 = iTextSharp.text.Image.GetInstance(Server.MapPath("../ImportUserIOExcel/Code.gif"));
IMG1.ScaleToFit(200, 30);
Chunk ck = new Chunk(IMG1, 345, -100); //圖片可設置 偏移
ph.Add(ck);
document.Add(ph);
cb.SetFontAndSize(bfChinese, 10);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "付款單號:", 10, 680, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購時間:", 10, 660, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "轉單日期:", 200, 660, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "訂購人:", 10, 640, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, "收貨人:", 200, 640, 0);
string address = string.Empty;
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_id"].ToString(), 80, 680, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_createdate"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["order_createdate"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 80, 660, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["money_collect_date"].ToString() != "0" ? CommonFunction.GetNetTime(long.Parse(deliverdetail.Rows[0]["money_collect_date"].ToString())).ToString("yyyy-MM-dd HH:mm:ss") : "", 250, 660, 0);
//cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["holiday_deliver"].ToString() == "1" ? "可" : "不可", 250, 620, 0);
//cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["note_order"].ToString(), 80, 600, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["order_name"].ToString(), 80, 640, 0);
cb.ShowTextAligned(PdfContentByte.ALIGN_LEFT, deliverdetail.Rows[0]["delivery_name"].ToString(), 250, 640, 0);
if (deliverdetail.Rows[0]["type"].ToString() != "3")
{
PdfPTable ptable = new PdfPTable(4);
ptable.SetTotalWidth(new float[] { 100, 320, 70, 70 });
PdfPCell cell = new PdfPCell();
cell.BorderWidth = 0.1f;
cell.BorderColor = new BaseColor(0, 0, 0);
cell = new PdfPCell(new Phrase("商品編號", font));
ptable.AddCell(cell);
cell = new PdfPCell(new Phrase("商品名稱", font));
ptable.AddCell(cell);
cell = new PdfPCell(new Phrase("數量", font));
ptable.AddCell(cell);
cell = new PdfPCell(new Phrase("售價", font));
ptable.AddCell(cell);
PdfPCell td = new PdfPCell();
td.BorderWidth = 0.1f;
int j = 0;
foreach (var item in deliverdetails)
{
j++;
for (int i = 0; i < item.Count(); i++)
{
string item_id = string.Empty;
if (item[i]["item_mode"].ToString() == "1")
{
item_id = item[i]["parent_id"].ToString();
}
else
{
item_id = item[i]["item_id"].ToString();
}
cell = new PdfPCell(new Phrase(item_id, font));
ptable.AddCell(cell);
string datacontent = ((item[i]["item_mode"].ToString() == "2") ? " *" : "") + item[i]["product_name"].ToString() + item[i]["product_spec_name"].ToString();
cell = new PdfPCell(new Phrase(item[i]["brand_name"].ToString() + "-" + datacontent, font));
示例12: End
//.........這裏部分代碼省略.........
// an
// attribute or style, try to enlarge the table
// to
// its
// minimum width (= widestWords array).
float pageWidth = GetHtmlPipelineContext(ctx).PageSize.Width;
if (GetTableWidth(widestWords, outerWidth) < pageWidth) {
targetWidth = GetTableWidth(widestWords, outerWidth);
leftToReduce = 0;
} else {
// If all columnWidths are set to the
// widestWordWidths and the table is still
// to
// wide
// content will fall off the edge of a page,
// which
// is similar to HTML.
targetWidth = pageWidth - outerWidth;
leftToReduce = 0;
}
}
}
}
// Enlarge width of columns to fit the targetWidth.
} else if (initialTotalWidth < targetWidth) {
for (int column = 0; column < columnWidths.Length; column++) {
if (fixedWidths[column] == 0) {
columnWidths[column] *= targetPercentage;
}
}
}
}
try {
table.SetTotalWidth(columnWidths);
table.LockedWidth = true;
table.DefaultCell.Border = Rectangle.NO_BORDER;
} catch (DocumentException e) {
throw new RuntimeWorkerException(LocaleMessages.GetInstance().GetMessage(LocaleMessages.NO_CUSTOM_CONTEXT), e);
}
float? tableHeight = new HeightCalculator().GetHeight(tag, GetHtmlPipelineContext(ctx).PageSize.Height);
float? tableRowHeight = null;
if (tableHeight != null && tableHeight > 0)
tableRowHeight = tableHeight / tableRows.Count;
int rowNumber = 0;
foreach (TableRowElement row in tableRows) {
int columnNumber = -1;
float? computedRowHeight = null;
/*if ( tableHeight != null && tableRows.IndexOf(row) == tableRows.Count - 1) {
float computedTableHeigt = table.CalculateHeights();
computedRowHeight = tableHeight - computedTableHeigt;
}*/
IList<HtmlCell> rowContent = row.Content;
if(rowContent.Count < 1)
continue;
foreach (HtmlCell cell in rowContent) {
IList<IElement> compositeElements = cell.CompositeElements;
if (compositeElements != null) {
foreach (IElement baseLevel in compositeElements) {
if (baseLevel is PdfPTable) {
TableStyleValues cellValues = cell.CellValues;
float totalBordersWidth = cellValues.IsLastInRow ? styleValues.HorBorderSpacing * 2
: styleValues.HorBorderSpacing;
totalBordersWidth += cellValues.BorderWidthLeft + cellValues.BorderWidthRight;
float columnWidth = 0;
for (int currentColumnNumber = columnNumber + 1; currentColumnNumber <= columnNumber + cell.Colspan; currentColumnNumber++){
columnWidth += columnWidths[currentColumnNumber];
示例13: PrintOrdersToPdf
//.........這裏部分代碼省略.........
foreach (var orderNote in orderNotes)
{
cell = new PdfPCell();
cell.AddElement(new Paragraph(_dateTimeHelper.ConvertToUserTime(orderNote.CreatedOnUtc, DateTimeKind.Utc).ToString(), font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
notesTable.AddCell(cell);
cell = new PdfPCell();
cell.AddElement(new Paragraph(HtmlHelper.ConvertHtmlToPlainText(orderNote.FormatOrderNoteText(), true, true), font));
cell.HorizontalAlignment = Element.ALIGN_LEFT;
notesTable.AddCell(cell);
}
doc.Add(notesTable);
}
}
#endregion
#region Footer
if (!String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn1) || !String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn2))
{
var column1Lines = String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn1) ?
new List<string>() :
_pdfSettings.InvoiceFooterTextColumn1
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
var column2Lines = String.IsNullOrEmpty(_pdfSettings.InvoiceFooterTextColumn2) ?
new List<string>() :
_pdfSettings.InvoiceFooterTextColumn2
.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
.ToList();
if (column1Lines.Count > 0 || column2Lines.Count > 0)
{
var totalLines = Math.Max(column1Lines.Count, column2Lines.Count);
const float margin = 43;
//if you have really a lot of lines in the footer, then replace 9 with 10 or 11
int footerHeight = totalLines * 9;
var directContent = pdfWriter.DirectContent;
directContent.MoveTo(pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight);
directContent.LineTo(pageSize.GetRight(margin), pageSize.GetBottom(margin) + footerHeight);
directContent.Stroke();
var footerTable = new PdfPTable(2);
footerTable.WidthPercentage = 100f;
footerTable.SetTotalWidth(new float[] { 250, 250 });
//column 1
if (column1Lines.Count > 0)
{
var column1 = new PdfPCell();
column1.Border = Rectangle.NO_BORDER;
column1.HorizontalAlignment = Element.ALIGN_LEFT;
foreach (var footerLine in column1Lines)
{
column1.AddElement(new Phrase(footerLine, font));
}
footerTable.AddCell(column1);
}
else
{
var column = new PdfPCell(new Phrase(" "));
column.Border = Rectangle.NO_BORDER;
footerTable.AddCell(column);
}
//column 2
if (column2Lines.Count > 0)
{
var column2 = new PdfPCell();
column2.Border = Rectangle.NO_BORDER;
column2.HorizontalAlignment = Element.ALIGN_LEFT;
foreach (var footerLine in column2Lines)
{
column2.AddElement(new Phrase(footerLine, font));
}
footerTable.AddCell(column2);
}
else
{
var column = new PdfPCell(new Phrase(" "));
column.Border = Rectangle.NO_BORDER;
footerTable.AddCell(column);
}
footerTable.WriteSelectedRows(0, totalLines, pageSize.GetLeft(margin), pageSize.GetBottom(margin) + footerHeight, directContent);
}
}
#endregion
ordNum++;
if (ordNum < ordCount)
{
doc.NewPage();
}
}
doc.Close();
}
示例14: ExecuteResult
public override void ExecuteResult(ControllerContext context)
{
var ctl = new MailingController { UseTitles = titles ?? false, UseMailFlags = useMailFlags ?? false };
var Response = context.HttpContext.Response;
IEnumerable<MailingController.MailingInfo> q = null;
switch (format)
{
case "Individual":
q = ctl.FetchIndividualList(sort, id);
break;
case "GroupAddress":
q = ctl.GroupByAddress(id);
break;
case "Family":
case "FamilyMembers":
q = ctl.FetchFamilyList(sort, id);
break;
case "ParentsOf":
q = ctl.FetchParentsOfList(sort, id);
break;
case "CouplesEither":
q = ctl.FetchCouplesEitherList(sort, id);
break;
case "CouplesBoth":
q = ctl.FetchCouplesBothList(sort, id);
break;
default:
Response.Write("unknown format");
return;
}
if (!q.Any())
{
Response.Write("no data found");
return;
}
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "filename=foo.pdf");
var document = new Document(PageSize.LETTER);
document.SetMargins(50f, 36f, 32f, 36f);
var w = PdfWriter.GetInstance(document, Response.OutputStream);
document.Open();
dc = w.DirectContent;
var cols = new float[] { W, W, W - 25f };
var t = new PdfPTable(cols);
t.SetTotalWidth(cols);
t.HorizontalAlignment = Element.ALIGN_CENTER;
t.LockedWidth = true;
t.DefaultCell.Border = PdfPCell.NO_BORDER;
t.DefaultCell.FixedHeight = H;
t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
t.DefaultCell.PaddingLeft = 8f;
t.DefaultCell.PaddingRight = 8f;
t.DefaultCell.SetLeading(2.0f, 1f);
if (skip > 0)
{
var blankCell = new PdfPCell(t.DefaultCell);
for (int iX = 0; iX < skip; iX++)
{
t.AddCell(blankCell);
}
}
foreach (var m in q)
{
var c = new PdfPCell(t.DefaultCell);
var ph = new Paragraph();
if (format == "GroupAddress")
ph.AddLine(m.LabelName + " " + m.LastName, font);
else
ph.AddLine(m.LabelName, font);
ph.AddLine(m.Address, font);
ph.AddLine(m.Address2, font);
ph.AddLine(m.CityStateZip, font);
c.AddElement(ph);
if (usephone)
{
var phone = Util.PickFirst(m.CellPhone.FmtFone("C "), m.HomePhone.FmtFone("H "));
var p = new Paragraph();
c.PaddingRight = 7f;
p.Alignment = Element.ALIGN_RIGHT;
p.Add(new Chunk(phone, smfont));
p.ExtraParagraphSpace = 0f;
c.AddElement(p);
}
t.AddCell(c);
}
t.CompleteRow();
document.Add(t);
document.Close();
}
示例15: GenerateXMLReport
public void GenerateXMLReport()
{
try
{
this.doc.Open();
RenderLogo();
//RenderHeaderAddress();
RenderReportJobInfo();
#region Add Details Table
PdfPTable myTable = new PdfPTable(ColList.Count );
myTable.SetTotalWidth(this.Headerwidths);
myTable.LockedWidth = true;
myTable.HorizontalAlignment = Element.ALIGN_LEFT;
myTable.DefaultCell.BorderWidth = 1;
myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;
foreach (var x in this.ColList)
{
myTable.AddCell(new Phrase(x, fntHeading));
}
//myTable.EndHeaders();
Font myDetailFont = fntDetails;
foreach (var x in this.ReportRows)
{
for (int i = 0; i < ColList.Count; i++)
{
myTable.DefaultCell.BackgroundColor = Color.WHITE;
if (x.row[i].type == CellType.Number)
myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
else
myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_LEFT;
myTable.AddCell(new Phrase(x.row[i].value, myDetailFont));
}
}
myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
myTable.DefaultCell.BackgroundColor = Color.LIGHT_GRAY;
int colindex = 0;
foreach (var x in this.FooterList)
{
//decimal.Parse(FooterList[colindex]) >
myTable.AddCell(new Phrase(x, footerFont));
colindex++;
}
myTable.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
myTable.DefaultCell.BackgroundColor = Color.BLUE;
foreach (var x in this.SacoList)
{
myTable.AddCell(new Phrase(x, SacoFont));
}
doc.Add(myTable);
#endregion
}
catch (Exception ex)
{
//MessageBox.Show("Error: " + ex.Message);
}
doc.Close();
writer.Close();
}