本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.AddCell方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.AddCell方法的具體用法?C# PdfPTable.AddCell怎麽用?C# PdfPTable.AddCell使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.AddCell方法的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: ManipulatePdf
// ---------------------------------------------------------------------------
/**
* Manipulates a PDF file src with the file dest as result
* @param src the original PDF
*/
public byte[] ManipulatePdf(byte[] src) {
// Create a table with named actions
Font symbol = new Font(Font.FontFamily.SYMBOL, 20);
PdfPTable table = new PdfPTable(4);
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_CENTER;
Chunk first = new Chunk( ((char)220).ToString() , symbol);
first.SetAction(new PdfAction(PdfAction.FIRSTPAGE));
table.AddCell(new Phrase(first));
Chunk previous = new Chunk( ((char)172).ToString(), symbol);
previous.SetAction(new PdfAction(PdfAction.PREVPAGE));
table.AddCell(new Phrase(previous));
Chunk next = new Chunk( ((char)174).ToString(), symbol);
next.SetAction(new PdfAction(PdfAction.NEXTPAGE));
table.AddCell(new Phrase(next));
Chunk last = new Chunk( ((char)222).ToString(), symbol);
last.SetAction(new PdfAction(PdfAction.LASTPAGE));
table.AddCell(new Phrase(last));
table.TotalWidth = 120;
// Create a reader
PdfReader reader = new PdfReader(src);
using (MemoryStream ms = new MemoryStream()) {
// Create a stamper
using (PdfStamper stamper = new PdfStamper(reader, ms)) {
// Add the table to each page
PdfContentByte canvas;
for (int i = 0; i < reader.NumberOfPages; ) {
canvas = stamper.GetOverContent(++i);
table.WriteSelectedRows(0, -1, 696, 36, canvas);
}
}
return ms.ToArray();
}
}
示例3: CreatePdf
private void CreatePdf(FileStream outputStream)
{
var doc = new Document(PageSize.A4);
PdfWriter.GetInstance(doc, outputStream);
doc.Open();
WriteFrontPage(doc);
doc.NewPage();
WriteSpecification(doc);
foreach (var representation in _report.Representations)
{
doc.NewPage();
doc.Add(new Paragraph("Representation"));
}
PdfPTable table = new PdfPTable(2);
table.AddCell(new PdfPCell { Colspan = 1 });
PdfPCell cell = new PdfPCell { Colspan = 1, HorizontalAlignment = 1, Phrase = new Phrase("REPRESENTATIONSKOSTNADER") };
table.AddCell(cell);
table.AddCell("Col 1 Row 1");
table.AddCell("Col 2 Row 1");
table.AddCell("Col 3 Row 1");
table.AddCell("Col 1 Row 2");
table.AddCell("Col 2 Row 2");
table.AddCell("Col 3 Row 2");
doc.Add(table);
doc.Close();
}
示例4: ConfigurarConteudo
private static void ConfigurarConteudo(List<Tarefa> tarefas, Document document)
{
foreach (Tarefa tarefa in tarefas)
{
PdfPTable table = new PdfPTable(2);
PdfPCell cell = new PdfPCell(new Phrase( tarefa.ToString()));
cell.Colspan = 2;
cell.BackgroundColor = BaseColor.GRAY;
cell.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cell);
PdfPCell cellSubitem = new PdfPCell(new Phrase("Subitem"));
cellSubitem.BackgroundColor = BaseColor.LIGHT_GRAY;
cellSubitem.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
PdfPCell cellPercentual = new PdfPCell(new Phrase("Percentual"));
cellPercentual.BackgroundColor = BaseColor.LIGHT_GRAY;
cellPercentual.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
table.AddCell(cellSubitem);
table.AddCell(cellPercentual);
foreach (Subitem subitem in tarefa.Subitens)
{
table.AddCell(subitem.Titulo);
table.AddCell(subitem.Percentual.ToString());
}
document.Add(table);
document.Add(new Paragraph(" "));
}
}
示例5: GetTable
// ---------------------------------------------------------------------------
/**
* Creates a table that mimics cellspacing using table and cell events.
* @param connection
* @return a table
* @throws SQLException
* @throws DocumentException
* @throws IOException
*/
public PdfPTable GetTable() {
PdfPTable table = new PdfPTable(new float[] { 1, 2, 2, 5, 1 });
table.TableEvent = new PressPreviews();
table.WidthPercentage = 100f;
table.DefaultCell.Padding = 5;
table.DefaultCell.Border = PdfPCell.NO_BORDER;
table.DefaultCell.CellEvent = new PressPreviews();
for (int i = 0; i < 2; i++) {
table.AddCell("Location");
table.AddCell("Date/Time");
table.AddCell("Run Length");
table.AddCell("Title");
table.AddCell("Year");
}
table.DefaultCell.BackgroundColor = null;
table.HeaderRows = 2;
table.FooterRows = 1;
List<Screening> screenings = PojoFactory.GetPressPreviews();
foreach (Screening screening in screenings) {
Movie movie = screening.movie;
table.AddCell(screening.Location);
table.AddCell(String.Format(
"{0} {1}", screening.Date,
screening.Time.Substring(0, 5)
));
table.AddCell(String.Format("{0} '", movie.Duration));
table.AddCell(movie.MovieTitle);
table.AddCell(movie.Year.ToString());
}
return table;
}
示例6: OnStartPage
public override void OnStartPage(PdfWriter writer, iTextSharp.text.Document document)
{
iTextSharp.text.Image header = iTextSharp.text.Image.GetInstance(PathResolver.MapPath("images/ADB_Logo.gif"));
PdfPTable tableHeader = new PdfPTable(2);
tableHeader.WidthPercentage = 100;
PdfPCell imageHeaderCell = new PdfPCell(header);
imageHeaderCell.Rowspan = 2;
imageHeaderCell.HorizontalAlignment = 0; //0=Left, 1=Centre, 2=Right
imageHeaderCell.Border = 0;
imageHeaderCell.PaddingBottom = 3;
tableHeader.AddCell(imageHeaderCell);
Font helvetica20 = FontFactory.GetFont(FontFactory.HELVETICA, 16);
PdfPCell typeNameCell = new PdfPCell(new Phrase(TypesReader.GetDiagramName(this.type), helvetica20));
typeNameCell.HorizontalAlignment = 2;
typeNameCell.Border = 0;
tableHeader.AddCell(typeNameCell);
PdfPCell adbCell = new PdfPCell(new Phrase(GlobalStringResource.ADB, helvetica20));
adbCell.HorizontalAlignment = 2;
adbCell.Border = 0;
tableHeader.AddCell(adbCell);
PdfPCell lineCell = new PdfPCell();
lineCell.Colspan = 2;
lineCell.Border = 1;
lineCell.PaddingBottom = 5;
tableHeader.AddCell(lineCell);
document.Add(tableHeader);
}
示例7: 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);
}
示例8: writePdf
public override void writePdf(bool bBlackAndWhite=false)
{
initFile();
PdfPTable table = new PdfPTable(m_iCount + 1);
int cellHeight = ((int)m_doc.PageSize.Height - 200) / m_iCount;
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance("");
image.ScaleAbsolute(cellHeight / 2, cellHeight / 2);
for (int j = 0; j < m_iCount; j++)
{
int cnt = s_random.Next(1, m_iMax);
for (int i = 0; i < m_iMax; i++)
{
if (i < cnt)
{
table.AddCell(image);
}
else
{
table.AddCell(new Phrase(" "));
}
}
table.AddCell(rectangle);
}
m_doc.Add(table);
printSiteName();
m_doc.Close();
}
示例9: TestIncompleteTableAdd
public virtual void TestIncompleteTableAdd() {
const String file = "incomplete_add.pdf";
Document document = new Document(PageSize.LETTER);
PdfWriter.GetInstance(document, new FileStream(OUTPUT_FOLDER + file, FileMode.OpenOrCreate));
document.Open();
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitRows = false;
table.Complete = false;
for (int i = 0; i < 5; i++) {
table.AddCell("Header " + i);
}
for (int i = 0; i < 500; i++) {
if (i % 5 == 0) {
document.Add(table);
}
table.AddCell("Test " + i);
}
table.Complete = true;
document.Add(table);
document.Close();
CompareTablePdf(file);
}
示例10: TestNoChangeInSetSkipFirstHeader
public virtual void TestNoChangeInSetSkipFirstHeader() {
Document document = new Document();
Stream stream = new MemoryStream();
PdfWriter writer = PdfWriter.GetInstance(document, stream);
document.Open();
PdfPTable table = new PdfPTable(5);
table.HeaderRows = 1;
table.SplitRows = false;
table.Complete = false;
for (int i = 0; i < 5; ++i) {
table.AddCell("Header " + i);
}
table.AddCell("Cell 1");
document.Add(table);
Assert.False(table.SkipFirstHeader);
table.Complete = true;
for (int i = 1; i < 5; i++) {
table.AddCell("Cell " + i);
}
document.Add(table);
document.Close();
stream.Close();
}
示例11: Write
// ===========================================================================
public void Write(Stream stream)
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, stream);
// step 3
document.Open();
// step 4
// Create a table and fill it with movies
IEnumerable<Movie> movies = PojoFactory.GetMovies(3);
PdfPTable table = new PdfPTable(new float[] { 1, 5, 5, 1 });
foreach (Movie movie in movies)
{
table.AddCell(movie.Year.ToString());
table.AddCell(movie.MovieTitle);
table.AddCell(movie.OriginalTitle);
table.AddCell(movie.Duration.ToString());
}
// set the total width of the table
table.TotalWidth = 600;
PdfContentByte canvas = writer.DirectContent;
// draw the first three columns on one page
table.WriteSelectedRows(0, 2, 0, -1, 236, 806, canvas);
document.NewPage();
// draw the next three columns on the next page
table.WriteSelectedRows(2, -1, 0, -1, 36, 806, canvas);
}
}
示例12: 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();
}
示例13: WriteData
public void WriteData(string directoryPath)
{
var document = new Document();
var documentFileStream = new FileStream(directoryPath + "\\top ten sold products " + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + ".pdf", FileMode.Create);
var writer = PdfWriter.GetInstance(document, documentFileStream);
var topTenSoldProducts = this.salesRepository.All()
.OrderByDescending(s => s.QuantitySold)
.Take(10)
.Select(s => new
{
Code = s.Product.ProductCode,
Price = s.Product.Price,
QuantitySold = s.QuantitySold
});
var table = new PdfPTable(this.ColumnsNames.Count());
for(int i = 0; i < this.ColumnsNames.Count(); i++)
{
table.AddCell(this.ColumnsNames[i]);
}
foreach(var product in topTenSoldProducts)
{
table.AddCell(product.Code);
table.AddCell(product.Price.ToString());
table.AddCell(product.QuantitySold.ToString());
}
document.Open();
document.Add(table);
document.Close();
}
開發者ID:Databases-Team-Thallium,項目名稱:Marketing-Data-Managment,代碼行數:35,代碼來源:PdfTopSoldProductsTableWriter.cs
示例14: btndownload_Click
protected void btndownload_Click(object sender, EventArgs e)
{
PdfPTable pdftable = new PdfPTable(gvtimetable.HeaderRow.Cells.Count);
foreach(TableCell headercell in gvtimetable.HeaderRow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvtimetable.HeaderStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell(new Phrase(headercell.Text, font));
pdfcell.BackgroundColor = new BaseColor(gvtimetable.HeaderStyle.BackColor);
pdftable.AddCell(pdfcell);
}
foreach(GridViewRow gridviewrow in gvtimetable.Rows)
{
foreach(TableCell tablecell in gridviewrow.Cells)
{
Font font = new Font();
font.Color = new BaseColor(gvtimetable.RowStyle.ForeColor);
PdfPCell pdfcell = new PdfPCell(new Phrase(tablecell.Text));
//pdfcell.BackgroundColor = ;
pdftable.AddCell(pdfcell);
}
}
Document pdfdocument = new Document(PageSize.A4, 10f, 10f, 10f, 10f);
PdfWriter.GetInstance(pdfdocument, Response.OutputStream);
pdfdocument.Open();
pdfdocument.Add(pdftable);
pdfdocument.Close();
Response.ContentType = "application/pdf";
Response.AppendHeader("content-disposition", "attachment;filename=Student_Timetable.pdf");
Response.Write(pdfdocument);
Response.Flush();
Response.End();
}
示例15: AddComputerReportsTableColumns
private void AddComputerReportsTableColumns(PdfPTable table)
{
table.AddCell(ManufacturerColumnHeader);
table.AddCell(ModelColumnHeader);
table.AddCell(PriceColumnHeader);
table.AddCell(ClassColumnHeader);
}