Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/08/2010, 09:51
666lawyer
 
Fecha de Ingreso: julio-2008
Mensajes: 7
Antigüedad: 15 años, 9 meses
Puntos: 0
Pregunta itextsharp header c#

Hola tengo una aplicación que trabaja con las librerías de itextsharp. Y un evento que maneja el cambio de pagina. Funciona correctamente, salvo en la última página, que lo pone en la última línea y la sobreescribe????. Alguna idea?. Aqui va el código:

protected void Write()
{
MemoryStream m = new MemoryStream();
Document doc = new Document();
doc.SetMargins(50,20,30,30);
try
{
Response.ContentType = "application/pdf";
PdfWriter writer = PdfWriter.GetInstance(doc, m);
writer.CloseStream = false;
itsEvents ev = new itsEvents();
writer.PageEvent = ev;
ev.Header = insstr;
doc.Open();
PdfPTable tabla = gpdf.TablePDF(Adjudicatarios);
tabla.SetWidths(new Single[] {20,20,20,10,10,20,10,100,20,30});
doc.Add(tabla);
doc.Close();

}
catch (DocumentException ex)
{
Console.Error.WriteLine(ex.StackTrace);
Console.Error.WriteLine(ex.Message);
}
// step 6: Write pdf bytes to outputstream
Response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
Response.OutputStream.Flush();
Response.OutputStream.Close();
m.Close();


}

public class GestionPDF

{

String titulo;



public GestionPDF()

{

//

// TODO: Agregar aquí la lógica del constructor

//

}





// add a table to the PDF document

public PdfPTable TablePDF(DataTable tabla)

{



string[] col;

col = new string[tabla.Columns.Count];



int k = 0;

foreach (DataColumn cl in tabla.Columns)

{

col[k] = cl.ColumnName;

++k;

}





PdfPTable table = new PdfPTable(tabla.Columns.Count);

table.WidthPercentage = 100;

table.SpacingBefore = 10;





for (int i = 0; i < col.Length; ++i)

{

PdfPCell cell = new PdfPCell(new Phrase(col[i]));

cell.BackgroundColor = new BaseColor(204, 204, 204);

table.AddCell(cell);

}



foreach (DataRow row in tabla.Rows)

{

foreach (DataColumn cl in tabla.Columns)

{

table.AddCell(row[cl].ToString());

}

}



return table;

}



}

public class itsEvents : PdfPageEventHelper

{

private String _Header;



public String Header

{

get { return _Header; }

set { _Header = value; }

}



public override void OnStartPage(PdfWriter writer, Document document)

{

Paragraph p = new Paragraph(Header + " " + DateTime.Now.ToString() + " " + writer.PageNumber);

p.SpacingBefore = 10;



document.Add(p);



}



}
Cita:

Última edición por 666lawyer; 31/08/2010 a las 09:55 Razón: cambiar notificación