vb.net - Itextsharp fit width and give border -
i designing table in pdf using itextsharp. want ask if knows:
- how give border (like color = silver, 1px, fit width) header text?
- how make table fit page width (like 100%)?
i using vb.net
protected sub create_pdf_click(sender object, e eventargs) handles create_pdf.click dim pdfdoc new document() dim pdfwrite pdfwriter = pdfwriter.getinstance(pdfdoc, new filestream("d://pdf/myfile.pdf", filemode.create)) pdfdoc.open() pdfdoc.add(new paragraph("here header text")) dim table new pdfptable(3) dim cell new pdfpcell(new phrase("header spanning 3 columns")) cell.colspan = 3 cell.horizontalalignment = 1 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") pdfdoc.add(table) pdfdoc.close() end sub
when define document
this:
dim pdfdoc new document()
you define document pages of size a4 , margins of 36 user units. if don't want margins, need create document this:
document doc = new document(pagesize.a4, 0f, 0f, 0f, 0f);
when create pdfptable
this:
dim table new pdfptable(3)
you create table takes 80% of available width. can change 100% adding line:
table.widthpercentage = 100
or, if want specify specific width, can use:
table.totalwidth = 595f table.lockedwidth = true
note 595
width (in user units) of a4 page.
borders defined @ level of pdfpcell
:
pdfpcell cell = new pdfpcell(phrase) cell.bordercolor = basecolor.red cell.borderwidth = 3f cell.border = rectangle.box
of course, can define each border separately. explained here: itextsharp: set table cell border color
in case, may want define these properties defaultcell
. way, don't have define them on , on again each separate cell.
it lead far if go more detail (e.g. talk table events , cell events, instance draw dashed borders). please download free ebook the best itext questions on stackoverflow find answers questions less trivial yours.
Comments
Post a Comment