本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.SetWidths方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.SetWidths方法的具體用法?C# PdfPTable.SetWidths怎麽用?C# PdfPTable.SetWidths使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.SetWidths方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: WriteTOC
protected virtual void WriteTOC(List<PdfContentParameter> contents, PdfWriter writer, Document document)
{
document.NewPage();
PdfPTable t = new PdfPTable(2);
t.WidthPercentage = 100;
t.SetWidths(new float[] { 98f, 2f });
t.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);
t.AddCell(new PdfPCell(
new Phrase(GlobalStringResource.TableOfContents,
FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 16))
) { Colspan = 2, Border = Rectangle.NO_BORDER, PaddingBottom = 25 });
foreach (PdfContentParameter item in contents)
{
if (!string.IsNullOrEmpty(item.Header))
{
t.AddCell(
new PdfPCell(
new Phrase(item.Header,
FontFactory.GetFont(FontFactory.HELVETICA_BOLD, 8)
)
) { Border = Rectangle.NO_BORDER, NoWrap = false, FixedHeight = 15, }
);
PdfPCell templateCell = new PdfPCell(Image.GetInstance(item.Template));
templateCell.HorizontalAlignment = Element.ALIGN_RIGHT;
templateCell.Border = Rectangle.NO_BORDER;
t.AddCell(templateCell);
}
}
float docHeight = document.PageSize.Height - heightOffset;
document.Add(t);
}
示例2: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable footer = new PdfPTable(3);
footer.SetWidths(new float[] { 88f, 7f, 5f });
footer.WidthPercentage = 100;
footer.TotalWidth = document.PageSize.Width - (document.LeftMargin + document.RightMargin);
PdfPCell emptycell = new PdfPCell();
emptycell.Border = 0;
footer.AddCell(emptycell);
Chunk text = new Chunk(string.Format(GlobalStringResource.PageOfFooter,
document.PageNumber), FontFactory.GetFont(FontFactory.HELVETICA, 8));
PdfPCell footerCell = new PdfPCell(new Phrase(text));
footerCell.Border = 0;
footerCell.HorizontalAlignment = Element.ALIGN_RIGHT;
footer.AddCell(footerCell);
PdfPCell cell = new PdfPCell(iTextSharp.text.Image.GetInstance(total));
cell.Border = 0;
cell.HorizontalAlignment = Element.ALIGN_LEFT;
footer.AddCell(cell);
footer.WriteSelectedRows(0, -1, 50, (document.BottomMargin - 10), writer.DirectContent);
}
示例3: CreateTable
private static PdfPTable CreateTable()
{
PdfPTable table = new PdfPTable(2);
//actual width of table in points
table.TotalWidth = 216f;
//fix the absolute width of the table
table.LockedWidth = true;
//relative col widths in proportions - 1/3 and 2/3
float[] widths = new float[] { 1f, 2f };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
//leave a gap before and after the table
table.SpacingBefore = 20f;
table.SpacingAfter = 30f;
PdfPCell cell = new PdfPCell(new Phrase("Products"));
cell.Colspan = 2;
cell.Border = 0;
cell.HorizontalAlignment = 1;
table.AddCell(cell);
// Seed data:
for (int i = 0; i < DummySeed.Info.Count; i++)
{
table.AddCell(DummySeed.Info[i].Id.ToString());
table.AddCell(DummySeed.Info[i].Name);
}
return table;
}
示例4: Rowspan_Test
public virtual void Rowspan_Test() {
String file = "rowspantest.pdf";
string fileE = CMP_FOLDER + file;
Console.Write(File.Exists(fileE));
Document document = new Document();
PdfWriter writer = PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.Create));
document.Open();
PdfContentByte contentByte = writer.DirectContent;
Rectangle rect = document.PageSize;
PdfPTable table = new PdfPTable(4);
table.TotalWidth = rect.Right - rect.Left + 1;
table.LockedWidth = true;
float[] widths = new float[] {
0.1f, 0.54f, 0.12f, 0.25f
};
table.SetWidths(widths);
PdfPCell cell_1_1 = new PdfPCell(new Phrase("1-1"));
cell_1_1.Colspan = 4;
table.AddCell(cell_1_1);
PdfPCell cell_2_1 = new PdfPCell(new Phrase("2-1"));
cell_2_1.Rowspan = 2;
table.AddCell(cell_2_1);
PdfPCell cell_2_2 = new PdfPCell(new Phrase("2-2"));
cell_2_2.Colspan = 2;
table.AddCell(cell_2_2);
PdfPCell cell_2_4 = new PdfPCell(new Phrase("2-4"));
cell_2_4.Rowspan = 3;
table.AddCell(cell_2_4);
PdfPCell cell_3_2 = new PdfPCell(new Phrase("3-2"));
table.AddCell(cell_3_2);
PdfPCell cell_3_3 = new PdfPCell(new Phrase("3-3"));
table.AddCell(cell_3_3);
PdfPCell cell_4_1 = new PdfPCell(new Phrase("4-1"));
cell_4_1.Colspan = 3;
table.AddCell(cell_4_1);
table.WriteSelectedRows(0, -1, rect.Left, rect.Top, contentByte);
document.Close();
// compare
CompareTool compareTool = new CompareTool(OUTPUT_FOLDER + file, CMP_FOLDER + file);
String errorMessage = compareTool.CompareByContent(OUTPUT_FOLDER, "diff");
if (errorMessage != null) {
Assert.Fail(errorMessage);
}
}
示例5: CreatePdf
public void CreatePdf(String dest)
{
Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(dest, FileMode.Create));
document.Open();
PdfPTable table = new PdfPTable(5);
table.SetWidths(new int[] {1, 2, 2, 2, 1});
PdfPCell cell;
cell = new PdfPCell(new Phrase("S/N"));
cell.Rowspan = 2;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Name"));
cell.Colspan = 3;
table.AddCell(cell);
cell = new PdfPCell(new Phrase("Age"));
cell.Rowspan = 2;
table.AddCell(cell);
table.AddCell("SURNAME");
table.AddCell("FIRST NAME");
table.AddCell("MIDDLE NAME");
table.AddCell("1");
table.AddCell("James");
table.AddCell("Fish");
table.AddCell("Stone");
table.AddCell("17");
document.Add(table);
document.Close();
}
示例6: GenerarDocumento
public void GenerarDocumento(Document document)
{
int i, j;
PdfPTable datatable = new PdfPTable(dataGridView1.ColumnCount);
datatable.DefaultCell.Padding = 3;
float[] headerwidths = GetTamañoColumnas(dataGridView1);
datatable.SetWidths(headerwidths);
datatable.WidthPercentage = 100;
datatable.DefaultCell.BorderWidth = 2;
datatable.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
for (i = 0; i < dataGridView1.ColumnCount; i++)
{
datatable.AddCell(dataGridView1.Columns[i].HeaderText);
}
datatable.HeaderRows = 1;
datatable.DefaultCell.BorderWidth = 1;
for (i = 0; i < dataGridView1.Rows.Count; i++)
{
for (j = 0; j < dataGridView1.Columns.Count; j++)
{
if (dataGridView1[j, i].Value != null)
{
datatable.AddCell(new Phrase(dataGridView1[j, i].Value.ToString()));//En esta parte, se esta agregando un renglon por cada registro en el datagrid
}
}
datatable.CompleteRow();
}
document.Add(datatable);
}
示例7: GenerateData
private void GenerateData(Document document, TravelAgencyDbContext dbContext)
{
var excursions = dbContext
.Excursions
.Select(x => new ReportExcursion()
{
ExcName = x.Name,
Destination = x.Destination.Country,
Distance = x.Destination.Distance.ToString(),
ClientCount = x.Clients,
StartDate = x.StartDate,
EndDate = x.EndDate,
Guide = x.Guide.Name,
Experience = x.Guide.Experience
})
.ToList();
PdfPTable table = new PdfPTable(5);
int[] widths = new int[] { 20, 20, 20, 15, 11 };
table.SetWidths(widths);
table.AddCell(this.CreateCell(new Phrase("Excursion name"), true));
table.AddCell(this.CreateCell(new Phrase("Destination"), true));
table.AddCell(this.CreateCell(new Phrase("Clients count"), true));
table.AddCell(this.CreateCell(new Phrase("Clients satisfaction"), true));
table.AddCell(this.CreateCell(new Phrase("Duration in days"), true));
this.InputData(excursions, table);
document.Add(table);
}
示例8: ExportToPdf
public string ExportToPdf(DateTime startDate, DateTime endDate)
{
DataTable dt = this.CreateTableForReport(startDate, endDate);
Document document = new Document();
var exportPath = this.exportFileName;
PdfWriter.GetInstance(document, new FileStream(exportPath, FileMode.Create));
document.Open();
Font font7 = FontFactory.GetFont(FontFactory.HELVETICA, 7);
Font font7bold = FontFactory.GetFont(FontFactory.HELVETICA, 7, Font.BOLD);
Font font10 = FontFactory.GetFont(FontFactory.HELVETICA, 10, Font.BOLD);
PdfPTable table = new PdfPTable(dt.Columns.Count);
float[] widths = new float[] { 2f, 4f, 3f, 3f, 4f, 3f };
table.SetWidths(widths);
table.WidthPercentage = 100;
PdfPCell cell = new PdfPCell(new Phrase("Products"));
cell.Colspan = dt.Columns.Count;
PdfPCell header = new PdfPCell(new Phrase("Aggregated Sales Report", font10));
header.Colspan = 6;
header.HorizontalAlignment = 1;
header.VerticalAlignment = 1;
header.PaddingTop = 10;
header.PaddingBottom = 10;
table.AddCell(header);
foreach (DataColumn c in dt.Columns)
{
table.AddCell(new PdfPCell(new Phrase(c.ColumnName, font7bold)) { BackgroundColor = new BaseColor(250, 200, 140), Padding = 2 });
}
foreach (DataRow r in dt.Rows)
{
if (dt.Rows.Count > 0)
{
table.AddCell(new PdfPCell(new Phrase(r[0].ToString(), font7bold))
{
Colspan = 6,
BackgroundColor = new BaseColor(250, 230, 200),
Padding = 2
});
table.AddCell(new Phrase(""));
table.AddCell(new Phrase(r[1].ToString(), font7));
table.AddCell(new Phrase(r[2].ToString(), font7));
table.AddCell(new Phrase(r[3].ToString(), font7));
table.AddCell(new Phrase(r[4].ToString(), font7));
table.AddCell(new PdfPCell(new Phrase(r[5].ToString(), font7))
{
BackgroundColor = new BaseColor(250, 200, 140),
Padding = 2
});
}
}
document.Add(table);
document.Close();
return ExportPdfReportSuccess;
}
示例9: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
document.Add(new Paragraph("Movies:"));
IEnumerable<Movie> movies = PojoFactory.GetMovies();
foreach (Movie movie in movies)
{
PdfPTable table = new PdfPTable(2);
table.SetWidths(new int[] { 1, 4 });
PdfPCell cell;
cell = new PdfPCell(new Phrase(movie.Title, FilmFonts.BOLD));
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.Colspan = 2;
table.AddCell(cell);
if (!string.IsNullOrEmpty(movie.OriginalTitle))
{
cell = new PdfPCell(PojoToElementFactory.GetOriginalTitlePhrase(movie));
cell.Colspan = 2;
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell(cell);
}
List<Director> directors = movie.Directors;
cell = new PdfPCell(new Phrase("Directors:"));
cell.Rowspan = directors.Count;
cell.VerticalAlignment = Element.ALIGN_MIDDLE;
table.AddCell(cell);
int count = 0;
foreach (Director pojo in directors)
{
cell = new PdfPCell(PojoToElementFactory.GetDirectorPhrase(pojo));
cell.Indent = (10 * count++);
table.AddCell(cell);
}
table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell("Year:");
table.AddCell(movie.Year.ToString());
table.AddCell("Run length:");
table.AddCell(movie.Duration.ToString());
List<Country> countries = movie.Countries;
cell = new PdfPCell(new Phrase("Countries:"));
cell.Rowspan = countries.Count;
cell.VerticalAlignment = Element.ALIGN_BOTTOM;
table.AddCell(cell);
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
foreach (Country country in countries)
{
table.AddCell(country.Name);
}
document.Add(table);
}
}
}
示例10: AttendByRank
public FileStreamResult AttendByRank(int tournamentId)
{
InitDocument();
document.Open();
PdfPTable headerTable = new PdfPTable(2);
headerTable.HorizontalAlignment = Element.ALIGN_LEFT;
headerTable.DefaultCell.VerticalAlignment = Element.ALIGN_MIDDLE;
headerTable.DefaultCell.Border = Rectangle.NO_BORDER;
headerTable.WidthPercentage = 100f;
headerTable.SetWidths(new float[] { 10, 90 });
headerTable.AddCell(Image.GetInstance(Server.MapPath("/Content/images/reportLogo.gif")));
headerTable.AddCell(new Phrase("Attendance By Rank", fontH1));
document.Add(headerTable);
Font fontRank = new Font(baseFont, 12, Font.BOLD);
Font fontAgeGroup = new Font(baseFont, 10, Font.BOLD);
IEnumerable<CompetitorDivision> competitorDivisions = db.CompetitorDivisions.Where(m => m.Competitor.TournamentId == tournamentId).OrderBy(m => m.Division.RankId).ThenBy(m => m.Division.AgeGroupId);
foreach (IGrouping<int, CompetitorDivision> rankDivisions in competitorDivisions.ToLookup(m => m.Division.RankId))
{
PdfPTable rankTable = new PdfPTable(4);
rankTable.SpacingBefore = 10f;
rankTable.HorizontalAlignment = Element.ALIGN_LEFT;
rankTable.WidthPercentage = 100f;
rankTable.DefaultCell.Border = Rectangle.NO_BORDER;
rankTable.SetWidths(new float[] { 70, 10, 10, 10 });
Rank rank = rankDivisions.First().Division.Rank;
rankTable.AddCell(new Phrase(rank.Description, fontRank));
rankTable.AddCell(new Phrase("Total", fontRank));
rankTable.AddCell(new Phrase("M", fontRank));
rankTable.AddCell(new Phrase("F", fontRank));
foreach (IGrouping<int, CompetitorDivision> ageGroupDivisions in rankDivisions.Where(m => !m.Division.AgeGroup.IsSparringGroup).ToLookup(m => m.Division.AgeGroupId))
{
AgeGroup ageGroup = ageGroupDivisions.First().Division.AgeGroup;
PdfPCell ageGroupCell = iTextSharpHelper.CreateCell(ageGroup.Description, fontAgeGroup, 0, Element.ALIGN_LEFT, null);
ageGroupCell.Colspan = 4;
rankTable.AddCell(ageGroupCell);
fillAttendByRankTable(ageGroupDivisions.Where(m => !m.Division.AgeGroup.IsSparringGroup).ToLookup(m => m.DivisionId), rankTable);
// Include child age groups for sparring
fillAttendByRankTable(db.CompetitorDivisions.Where(m => m.Competitor.TournamentId == tournamentId && m.Division.RankId == rank.RankId & m.Division.AgeGroup.ParentAgeGroupId == ageGroup.AgeGroupId).ToLookup(m => m.DivisionId), rankTable);
}
document.Add(rankTable);
}
document.Close();
return getFileStreamResult(ms, "attendancebyrank.pdf");
}
示例11: CreateTable
/// <summary>
/// This metod create table in the pdf file
/// </summary>
public void CreateTable()
{
table = new PdfPTable(1);
table.WidthPercentage = 100;
table.SetWidths(new float[] { 812 });
}
示例12: ExportToPdf
//private void LoadNonFinancialAccountStatement()
//{
// var xSwitch = new Business.XSwitch();
// NonFinHistoryGridView.DataSource = xSwitch.getNonFinHistory(Global.ConnectionString, Session["UserId"].ToString());
// NonFinHistoryGridView.DataBind();
//}
public byte[] ExportToPdf(DataTable dt)
{
try
{
using (var ms = new MemoryStream())
{
Document document = new Document();
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
PdfWriter writer = PdfWriter.GetInstance(document, ms);
document.Open();
iTextSharp.text.Font font5 = iTextSharp.text.FontFactory.GetFont(FontFactory.HELVETICA, 5);
PdfPTable table = new PdfPTable(dt.Columns.Count);
PdfPRow row = null;
float[] widths = new float[] { 4f, 4f, 4f, 4f, 4f };
table.SetWidths(widths);
table.WidthPercentage = 100;
int iCol = 0;
string colname = "";
PdfPCell cell = new PdfPCell(new Phrase("Products"));
cell.Colspan = dt.Columns.Count;
foreach (DataColumn c in dt.Columns)
{
table.AddCell(new Phrase(c.ColumnName, font5));
}
foreach (DataRow r in dt.Rows)
{
if (dt.Rows.Count > 0)
{
table.AddCell(new Phrase(r[0].ToString(), font5));
table.AddCell(new Phrase(r[1].ToString(), font5));
table.AddCell(new Phrase(r[2].ToString(), font5));
table.AddCell(new Phrase(r[3].ToString(), font5));
table.AddCell(new Phrase(r[4].ToString(), font5));
}
}
document.Add(table);
document.Close();
return ms.ToArray();
}
}
catch (Exception ex)
{
Master.ErrorMessage = "Error: PDF Creation Failed.";
Response.Redirect(Request.RawUrl);
return null;
}
}
示例13: Table
public static PdfPTable Table(int column, float[] ratio)
{
PdfPTable table = new PdfPTable(column);
table.TotalWidth = 560f;
table.LockedWidth = true;
table.SetWidths(ratio);
table.HorizontalAlignment = 1;
table.SpacingBefore = 10f;
table.SpacingAfter = 10f;
return table;
}
示例14: CreateAirlineReportsTable
private PdfPTable CreateAirlineReportsTable()
{
PdfPTable table = new PdfPTable(PdfTableSize);
table.WidthPercentage = 100;
table.LockedWidth = false;
float[] widths = new float[] { 3f, 3f, 3f, 3f };
table.SetWidths(widths);
table.HorizontalAlignment = 0;
table.SpacingBefore = 20f;
table.SpacingAfter = 30f;
return table;
}
示例15: btnPrint_Click
private void btnPrint_Click(object sender, EventArgs e)
{
// Create a Document object
var document = new Document(PageSize.A4, 50, 50, 25, 25);
string file = "Choo.pdf";
// Create a new PdfWriter object, specifying the output stream
var output = new MemoryStream();
//var writer = PdfWriter.GetInstance(document, output);
var writer = PdfWriter.GetInstance(document, new FileStream(file, FileMode.Create));
// Open the Document for writing
document.Open();
var titleFont = FontFactory.GetFont("Arial", 18);
var subTitleFont = FontFactory.GetFont("Arial", 14);
var boldTableFont = FontFactory.GetFont("Arial", 12);
var endingMessageFont = FontFactory.GetFont("Arial", 10);
var bodyFont = FontFactory.GetFont("Arial", 12);
//document.Add(new Paragraph("Northwind Traders Receipt", titleFont);
Paragraph tit = new Paragraph();
Chunk c1 = new Chunk(" Ingresos Diarios \n", titleFont);
Chunk c2 = new Chunk("Ciclo Escolar 2012 - 2013 \n");
Chunk c3 = new Chunk("Dia consultado : 25/01/2013");
tit.Add(c1);
tit.Add(c2);
tit.Add(c3);
tit.IndentationLeft = 200f;
document.Add(tit);
PdfContentByte cb = writer.DirectContent;
cb.MoveTo(50, document.PageSize.Height / 2);
cb.LineTo(document.PageSize.Width - 50, document.PageSize.Height / 2);
cb.Stroke();
var orderInfoTable = new PdfPTable(2);
orderInfoTable.HorizontalAlignment = 0;
orderInfoTable.SpacingBefore = 10;
orderInfoTable.SpacingAfter = 10;
orderInfoTable.DefaultCell.Border = 0;
orderInfoTable.SetWidths(new int[] { 1, 4 });
orderInfoTable.AddCell(new Phrase("Order:", boldTableFont));
orderInfoTable.AddCell("textorder");
orderInfoTable.AddCell(new Phrase("Price:", boldTableFont));
orderInfoTable.AddCell(Convert.ToDecimal(444444).ToString("c"));
document.Add(orderInfoTable);
document.Close();
System.Diagnostics.Process.Start(file);
}