csv - Generate a table and append it to a pdf using c#? -
i have 2 parts c# project company , company wants me generate pdf file csv.
i need populate fields of pdf need add table below populated section on blank area of page (and table needs able rollover next page).
i able these things separately (populate pdf , create table). cannot merge them. have tried doing doc.add(table) result in table being on next page of pdf, don't want.
i need able specify table starts on page (so wouldn't overlap existing content) , stamp table onto existing pdf.
my other option if doesn't work trying add fields original pdf filled table contents (so instead field-based table).
any suggestions?
edit:
i'm new itext , have not used columntext before, i'm trying test out in following code table not being displayed. looked @ other columntext examples , have not seen columntext added pdf.
//create filled form pdf pdfreader reader = new pdfreader(sourcepath); pdfstamper pdfstamper = new pdfstamper(reader, new fileoutputstream(destpath)); pdfstamper.setformflattening(true); acrofields form = pdfstamper.getacrofields(); form.setfield("id", "99999"); form.setfield("addr1", "425 test street"); form.setfield("addr2", "test, wa 91334"); form.setfield("phnbr", "(999)999-9999"); form.setfield("name", "john smith"); //create table pdfptable table = new pdfptable(3); font bfbold12 = new font(fontfamily.helvetica, 12, font.bold, new basecolor(0, 0, 0)); insertcell(table, "table", element.align_center, 1, bfbold12); table.completerow(); columntext column = new columntext(pdfstamper.getovercontent(1)); column.addelement(table); pdfstamper.close(); reader.close();
either csv data invalid (not formatted, e.g. additional linebreaks or commas) or messing data "\n-1" string building. (your console output varies 8 9 lines per dataset)
for debugging, skip building "content" string , write data directly csv line pdf cells, like:
document doc = new document(); pdfwriter.getinstance(doc, new filestream(server.mappath("file6.pdf"), filemode.create)); doc.open(); pdfptable table = new pdfptable(7); using (textfieldparser parser = new textfieldparser("t.csv")) { parser.textfieldtype = fieldtype.delimited; parser.setdelimiters(","); while (!parser.endofdata) { //processing row string[] fields = parser.readfields(); table.addcell(new pdfpcell(new paragraph(field[2])); table.addcell(new pdfpcell(new paragraph(field[3])); table.addcell(new pdfpcell(new paragraph(field[4])); //...... } } doc.add(table); doc.close();
Comments
Post a Comment