i doing pdf document itextsharp. created header pageevent event, want header different in pages. works setting same header pages.
but, wish different.
example: page 1=>header 1 page 2=>header 1 page 3=>header 2 page 4=>header 2
i solve it, troubles come when happens:
writer.pageevent=new pdffooter(params); doc.open();
the pageevent event must created above doc.open();
when put below, generates error. using c# visual studio community 2013.
how solve this? thanks!!
i solved problem now.
the solution this:
pdffooter events=new pdffooter(); pdfwriter writer = pdfwriter.getinstance(doc, response.outputstream); doc.open(); foreach (var item in listreporte) { events = new pdffooter(); writer.pageevent = events; events.ciudad = item.ciudad; events.onstartpage(writer,doc); //this solution if (writer.pageevent != null) writer.pageevent = null; }
in each iteration, assign null pageevent property.
but first, created pdffooter object (the class pdffooter contains onstartpage , onendpages events...), so, in class declared attributes data wanted display.
previously, couldn't instantiate pdffooter class below of doc.open()
. code this:
writer.pageevent=new pdffooter(); doc.open():
so, tried create objet first , set pageevent property of writer object (i recommend this). , worked.
it feels wonderful.
Comments
Post a Comment