c# - Dynamic PDF Row Mockup -
i have little problem , reply obvious , simple, guess have failed in searching net answer, 1 time 1 time again came guys.
i'm dynamically generating pdf file in asp.net c#, , right i'm making base of operations it. 1 of things generates table in cart content should revealed (yes i'm talking invoice) , i'm trying give table mockup, mock upper row different rest. (the header in columns defined (quantity, title, unit price, discount , total)
here's code (it's first time did don't yell @ me xd)
pdfpcell quantity = new pdfpcell(new phrase("quantity")); pdfpcell title = new pdfpcell(new phrase("title")); pdfpcell unipr = new pdfpcell(new phrase("unit price")); pdfpcell disc = new pdfpcell(new phrase("discount")); pdfpcell total = new pdfpcell(new phrase("total")); pdfpcell[] cartheaderc = { quantity, title, unipr, disc, total }; pdfprow cartheader = new pdfprow(cartheaderc); so i've tried way , say:
pdfprow.backgroundcolor = new basecolor(255,0,0); since works cells, thought might create sense, apparently didn't. can when take each cell apart, there should easier way, right?
that's 1 problem, sadly enough, i've got 1 more (although 10x more stupid , 10x easier). color want utilize #c5c5c5, doesn't want recognize color code.
here list of systems itextsharp i'm using (this beside standard systems visual studio , sqlserver , no, rather not want add together more systems if possible):
using system.io; using itextsharp.text; using itextsharp.text.pdf;
you have 2 questions:
you usingpdfprow, you're not supposed that. pdfprow class internal utilize only. should work @ pdfpcell level. if want color finish rows, can using pdfptableevent. see instance colored rows in alternating.pdf. colored in alternatingbackground table event. you have difficulties creating color #c5c5c5. hexadecimal value c5 equals 197, hence want create next color object: new basecolor(197, 197, 197); your main error create pdfprow adding array of pdfpcell objects. did inspiration so? if find wrote such example, please allow me know , if he's near, i'll spank him ;-)
tables created this:
pdfptable table = new pdfptable(5); pdfpcell quantity = new pdfpcell(new phrase("quantity")); table.addcell(quantity); pdfpcell title = new pdfpcell(new phrase("title")); table.addcell(title); pdfpcell unipr = new pdfpcell(new phrase("unit price")); table.addcell(unipr); pdfpcell disc = new pdfpcell(new phrase("discount")); table.addcell(disc); pdfpcell total = new pdfpcell(new phrase("total")); table.addcell(total); there easier way this. easier way allows define background color every cell:
pdfptable table = new pdfptable(5); table.defaultcell.backgroundcolor = new basecolor(197, 197, 197); table.addcell("quantity"); table.addcell("title"); table.addcell("unit price"); table.addcell("discount"); table.addcell("total"); the addcell() method wrap strings within phrase. create pdfpcell phrase , apply properties you've defined defaultcell cell. way, can create sure cell have same ground color (or border, or...). obviously, properties of defaultcell ignored if create pdfpcell instances yourself.
c# asp.net pdf itextsharp dynamicpdf
No comments:
Post a Comment