本文整理匯總了C#中iTextSharp.text.pdf.PdfPTable.WriteSelectedRows方法的典型用法代碼示例。如果您正苦於以下問題:C# PdfPTable.WriteSelectedRows方法的具體用法?C# PdfPTable.WriteSelectedRows怎麽用?C# PdfPTable.WriteSelectedRows使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類iTextSharp.text.pdf.PdfPTable
的用法示例。
在下文中一共展示了PdfPTable.WriteSelectedRows方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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();
}
}
示例2: OnStartPage
public override void OnStartPage(PdfWriter writer, Document document)
{
base.OnStartPage(writer, document);
if ((tipoDocumento == "contrato") || (tipoDocumento == "contrato_preimpreso")) //no se ponen cabeceras ni fotter
{
}
else
{
if (tipoDocumento == "clausula")
{
//imagen de la cabecera
float escala = 85; //%
Image imagenHeader = Image.GetInstance(dirImagenHeader);
imagenHeader.ScalePercent(escala);
PdfPTable table = new PdfPTable(1);
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
//logo
PdfPCell cell = new PdfPCell(imagenHeader);
cell.Border = 0;
cell.BorderWidth = 0;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 20, writer.DirectContent);
}
else
{
if (tipoDocumento == "apertura_cuenta")
{
//imagen de la cabecera
float escala = 70; //%
Image imagenHeader = Image.GetInstance(dirImagenHeader);
imagenHeader.ScalePercent(escala);
PdfPTable table = new PdfPTable(1);
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
//logo
PdfPCell cell = new PdfPCell(imagenHeader);
cell.Border = 0;
cell.BorderWidth = 0;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 90, writer.DirectContent);
}
else
{
if (tipoDocumento == "autos_recomendacion")
{
//imagen de la cabecera
float escala = 70; //%
Image imagenHeader = Image.GetInstance(dirImagenHeader);
imagenHeader.ScalePercent(escala);
PdfPTable table = new PdfPTable(1);
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
//logo
PdfPCell cell = new PdfPCell(imagenHeader);
cell.Border = 0;
cell.BorderWidth = 0;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 20, writer.DirectContent);
}
else
{
if (tipoDocumento == "orden_compra")
{
//imagen de la cabecera
float escala = 70; //%
Image imagenHeader = Image.GetInstance(dirImagenHeader);
imagenHeader.ScalePercent(escala);
PdfPTable table = new PdfPTable(1);
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin;
//logo
PdfPCell cell = new PdfPCell(imagenHeader);
cell.Border = 0;
cell.BorderWidth = 0;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 20, writer.DirectContent);
}
else
{
if (tipoDocumento == "entrevista")
{
//imagen de la cabecera
float escala = 85; //%
Image imagenHeader = Image.GetInstance(dirImagenHeader);
//.........這裏部分代碼省略.........
示例3: 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);
}
}
示例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: 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();
}
示例6: 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);
}
示例7: OnEndPage
//override the OnPageEnd event handler to add our footer
public override void OnEndPage(PdfWriter writer, Document doc)
{
//I use a PdfPtable with 2 columns to position my footer where I want it
PdfPTable footerTbl = new PdfPTable(2);
//set the width of the table to be the same as the document
footerTbl.TotalWidth = doc.PageSize.Width;
//Center the table on the page
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
//Create a paragraph that contains the footer text
Paragraph para;// = new Paragraph("", Fuentes.footer);
DateTime time = DateTime.Now; // Use current time
string format = "dd/MM/yyyy"; // Use this format
para = new Paragraph(time.ToString(format), Fuentes.Footer);
//add a carriage return
para.Add(Environment.NewLine);
para.Add("");
//create a cell instance to hold the text
PdfPCell cell = new PdfPCell(para);
//set cell border to 0
cell.Border = 0;
//add some padding to bring away from the edge
cell.PaddingLeft = 10;
//add cell to table
footerTbl.AddCell(cell);
//Creo el contenido de la 2da celda
int pageN = writer.PageNumber;
//DateTime time = DateTime.Now; // Use current time
//string format = "dd/MM/yyyy"; // Use this format
//para = new Paragraph(time.ToString(format), Fuentes.footer);
//para.Add(Environment.NewLine);
para = new Paragraph(pageN.ToString(), Fuentes.Footer);
//create new instance of cell to hold the text
cell = new PdfPCell(para);
//align the text to the right of the cell
cell.HorizontalAlignment = Element.ALIGN_RIGHT;
//set border to 0
cell.Border = 0;
// add some padding to take away from the edge of the page
cell.PaddingRight = 10;
//add the cell to the table
footerTbl.AddCell(cell);
//write the rows out to the PDF output stream.
footerTbl.WriteSelectedRows(0, -1, 0, (doc.BottomMargin + 10), writer.DirectContent);
}
示例8: OnStartPage
public override void OnStartPage(PdfWriter writer, Document doc)
{
PdfPTable headerTbl = new PdfPTable(1);
headerTbl.TotalWidth = doc.PageSize.Width;
Image logo = Image.GetInstance(HttpContext.Current.Server.MapPath("/IMG/Logopdf.jpg"));
logo.ScalePercent(50);
PdfPCell cell = new PdfPCell(logo);
cell.HorizontalAlignment = Element.ALIGN_CENTER;
cell.PaddingRight = 20;
cell.Border = 0;
headerTbl.AddCell(cell);
headerTbl.WriteSelectedRows(0, -1, 0, (doc.PageSize.Height - 10), writer.DirectContent);
}
示例9: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable table = new PdfPTable(2);
table.SetWidths(new float[] { 48, 2 });
table.TotalWidth = document.PageSize.Width - document.RightMargin - document.LeftMargin;
table.LockedWidth = true;
table.DefaultCell.FixedHeight = 20;
table.DefaultCell.Border = Rectangle.NO_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell(new Phrase(String.Format("Página {0} de", writer.CurrentPageNumber), ffont));
PdfPCell cell = new PdfPCell(Image.GetInstance(pageCount));
cell.Border = Rectangle.NO_BORDER;
table.AddCell(cell);
table.WriteSelectedRows(0, -1, 34, document.PageSize.Height - (document.TopMargin - 20), writer.DirectContent);
}
示例10: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
//PdfPTable table = new PdfPTable(1);
////table.WidthPercentage = 100; //PdfPTable.writeselectedrows below didn't like this
//table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]
//PdfPTable table2 = new PdfPTable(2);
////logo
////PdfPCell cell2 = new PdfPCell("Tan");
////cell2.Colspan = 2;
////table2.AddCell(cell2);
////title
//Font black9BoldFont = FontFactory.GetFont("swis721 cn BT", 9f, Font.BOLD, BaseColor.BLACK);
//PdfPCell cell2 = new PdfPCell(new Phrase("\nTITLE", black9BoldFont));
//cell2.HorizontalAlignment = Element.ALIGN_CENTER;
//cell2.Colspan = 2;
//table2.AddCell(cell2);
//PdfPCell cell = new PdfPCell(table2);
//table.AddCell(cell);
//table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
if (!string.IsNullOrEmpty(_footerText)) {
Paragraph footer = new Paragraph(_footerText, FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_CENTER;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
}
示例11: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
Configurar();
//base.OnEndPage(writer, document);
PdfPTable tabla = new PdfPTable(new float[]{4,1});
tabla.AddCell(new PdfPCell(new Phrase(_Empresa.Descripcion,ChicaNegrita)) { Border = Rectangle.NO_BORDER });
//logo
Image imagen = Image.GetInstance(String.Format(@"{0}\imagenes\LogosEmpresas\logo{1}.jpg",_path,_Empresa.Codigo.Trim()));
tabla.AddCell(new PdfPCell(imagen,true) { Rowspan = 3, Border = Rectangle.NO_BORDER });
tabla.AddCell(new PdfPCell(new Phrase(_Empresa.Direccion, ChicaNegrita)) { Border = Rectangle.NO_BORDER });
tabla.AddCell(new PdfPCell(
new Phrase(
String.Format("Fono: {0}", (_Empresa.Fono ?? String.Empty).Trim()), ChicaNegrita)
) { Border = Rectangle.NO_BORDER });
tabla.AddCell(new PdfPCell(new Phrase(String.Format("Fecha Informe: {0}", DateTime.Now.ToShortDateString()), ChicaNegrita)) { Border = Rectangle.NO_BORDER });
tabla.TotalWidth = document.Right - document.Left- 20;
tabla.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 18, writer.DirectContent);
}
示例12: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable table = new PdfPTable(3);
try
{
table.SetWidths(new int[] { 24, 24, 2 });
table.TotalWidth = 527;
table.LockedWidth = true;
table.DefaultCell.FixedHeight = 20;
table.DefaultCell.Border = Rectangle.BOTTOM_BORDER;
table.DefaultCell.HorizontalAlignment = Element.ALIGN_RIGHT;
table.AddCell(string.Format("{0}", writer.PageNumber));
table.WriteSelectedRows(0, -1, 34, 803, writer.DirectContent);
}
catch (DocumentException de)
{
throw de;
}
}
示例13: OnEndPage
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
Font FooterFont = new Font(BaseFont, 10);
if (ShowFooter)
{
PdfPTable placeTable = new PdfPTable(8);
placeTable.HorizontalAlignment = Element.ALIGN_LEFT;
placeTable.TotalWidth = document.PageSize.Width - 100;
placeTable.SetWidths(new float[] { 7.5f, 16.5f, 9.5f, 16.5f, 8.5f, 16.5f, 8.5f, 16.5f });
/*PdfPCell titleCell = iTextSharpHelper.CreateCell("Please ensure that you complete this form (including the placings section at the bottom)", new Font(BaseFont, 10, Font.ITALIC), Rectangle.NO_BORDER, Element.ALIGN_LEFT, null);
titleCell.Colspan = 8;
placeTable.AddCell(titleCell);*/
PdfPCell placeCell = iTextSharpHelper.CreateCell(string.Empty, FooterFont, Rectangle.BOTTOM_BORDER, Element.ALIGN_LEFT, null);
placeTable.AddCell(iTextSharpHelper.CreateCell("First", FooterFont, 0, Element.ALIGN_LEFT, null));
placeTable.AddCell(placeCell);
placeTable.AddCell(iTextSharpHelper.CreateCell("Second", FooterFont, 0, Element.ALIGN_LEFT, 10f));
placeTable.AddCell(placeCell);
placeTable.AddCell(iTextSharpHelper.CreateCell("Third", FooterFont, 0, Element.ALIGN_LEFT, 10f));
placeTable.AddCell(placeCell);
placeTable.AddCell(iTextSharpHelper.CreateCell("Fourth", FooterFont, 0, Element.ALIGN_LEFT, 10f));
placeTable.AddCell(placeCell);
placeTable.WriteSelectedRows(0, 1, document.PageSize.GetLeft(40), document.PageSize.GetBottom(90), cb);
PdfPTable judgeTable = new PdfPTable(4);
judgeTable.HorizontalAlignment = Element.ALIGN_LEFT;
judgeTable.TotalWidth = document.PageSize.Width - 100;
judgeTable.SetWidths(new float[] { 20f, 40f, 20f, 40f });
judgeTable.AddCell(iTextSharpHelper.CreateCell("Center Judge", new Font(BaseFont, 11), 0, Element.ALIGN_LEFT, null));
judgeTable.AddCell(placeCell);
judgeTable.AddCell(iTextSharpHelper.CreateCell("Scorekeeper", new Font(BaseFont, 11), 0, Element.ALIGN_LEFT, 10f));
judgeTable.AddCell(placeCell);
judgeTable.WriteSelectedRows(0, 1, document.PageSize.GetLeft(40), document.PageSize.GetBottom(60), cb);
}
}
示例14: DisplayTable
private void DisplayTable(string title, float width, float x, float y, List<string> reasons)
{
var t = new PdfPTable(new float[] { 1.3f, width-1.3f });
t.TotalWidth = width * cm2pts;
t.SetNoBorder();
t.LockedWidth = true;
t.DefaultCell.MinimumHeight = 1f * cm2pts;
t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
t.AddPlainRow(title, bfont);
foreach (var r in reasons)
{
t.AddRight("_____", font);
t.Add(r, font);
}
t.WriteSelectedRows(0, -1, x * cm2pts, y * cm2pts, dc);
}
示例15: DisplayNotes
private void DisplayNotes(string title, int nrows, float width, float x, float y)
{
var t = new PdfPTable(1);
t.TotalWidth = width * cm2pts;
t.LockedWidth = true;
t.DefaultCell.MinimumHeight = 1f * cm2pts;
t.DefaultCell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
t.AddPlainRow(title, bfont);
for (int r = 0; r < nrows; r++ )
t.AddCell("");
t.WriteSelectedRows(0, -1, x * cm2pts, y * cm2pts, dc);
}