sorry english, have code creates document. in first third located rectangle text, representing header. code:
private void creategpdfbutton_click(object sender, eventargs e) { string pdfcesta = appdomain.currentdomain.basedirectory; document gdoc = new document(itextsharp.text.pagesize.a4, 42, 10, 42, 35); //***** definice fontů ***** //nastavení fontu, aby tisklo řádně česky string arialuni_tff = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "arialuni.ttf"); string consola_ttf = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "consola.ttf"); string cour_ttf = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "cour.ttf"); string courbd_ttf = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "courbd.ttf"); // courier tučné string times_ttf = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "times.ttf"); string timesbd_ttf = path.combine(environment.getfolderpath(environment.specialfolder.fonts), "timesbd.ttf"); // courier tučné //create base font object making sure specify identity-h basefont bf_arial = basefont.createfont(arialuni_tff, basefont.identity_h, basefont.not_embedded); basefont bf_consolas = basefont.createfont(consola_ttf, basefont.identity_h, basefont.not_embedded); basefont bf_courier = basefont.createfont(cour_ttf, basefont.identity_h, basefont.not_embedded); basefont bf_courier_bold = basefont.createfont(courbd_ttf, basefont.identity_h, basefont.not_embedded); basefont bf_times = basefont.createfont(times_ttf, basefont.identity_h, basefont.not_embedded); basefont bf_times_bold = basefont.createfont(timesbd_ttf, basefont.identity_h, basefont.not_embedded); //create specific font object itextsharp.text.font f = new itextsharp.text.font(bf_arial, 12, itextsharp.text.font.normal); itextsharp.text.font f1 = new itextsharp.text.font(bf_consolas, 10, itextsharp.text.font.normal); //***** konec fontů ***** try { pdfwriter gwriter = pdfwriter.getinstance(gdoc, new filestream(pdfcesta + "graphicspdf.pdf", filemode.create)); gdoc.open(); pdfcontentbyte cb = gwriter.directcontent; cb.savestate(); // uložení aktuálního nastavení grafiky cb.setcolorstroke(new basecolor(0,0,0)); cb.setcolorfill(new basecolor(255,192,203)); cb.setlinewidth(1.5f); // bottom left coordinates x & y, followed width, height , radius of corners. cb.roundrectangle(48f, 600f, 495.833f, 192.4f, 5f); cb.fillstroke(); cb.setlinewidth(0.5f); cb.rectangle((gdoc.pagesize.width / 2) - 35f, 630f,70f,10f); cb.stroke(); cb.rectangle((gdoc.pagesize.width / 2) - 35f, 640f, 70f, 10f); cb.stroke(); //zápis textu cb.begintext(); cb.setcolorfill(basecolor.black); cb.setfontandsize(bf_times_bold, 15f); cb.showtextaligned(pdfcontentbyte.align_center, "vÝkaz", gdoc.pagesize.width / 2, 753f, 0); cb.setfontandsize(bf_times_bold, 15f); cb.showtextaligned(pdfcontentbyte.align_center, "zisku ztrÁty", gdoc.pagesize.width / 2, 733f, 0); cb.setfontandsize(bf_times_bold, 5f); cb.showtextaligned(pdfcontentbyte.align_center, "v plném rozsahu", gdoc.pagesize.width / 2, 713f, 0); cb.setfontandsize(bf_times_bold, 12f); cb.showtextaligned(pdfcontentbyte.align_center, "31.12.2015", gdoc.pagesize.width / 2, 683f, 0); cb.setfontandsize(bf_times_bold, 7f); cb.showtextaligned(pdfcontentbyte.align_center, "v tisících kč", gdoc.pagesize.width / 2, 663f, 0); cb.setfontandsize(bf_times, 5f); cb.showtextaligned(pdfcontentbyte.align_center, "iČo", gdoc.pagesize.width / 2, 643f, 0); cb.setfontandsize(bf_times_bold, 5f); cb.showtextaligned(pdfcontentbyte.align_center, "00020711", gdoc.pagesize.width / 2, 633f, 0); cb.endtext(); //konec textu cb.restorestate(); // obnovení původního nastavení grafiky // tabulka // konec tabulky gdoc.close(); system.diagnostics.process.start(pdfcesta + "graphicspdf.pdf"); } catch (exception ex) { messagebox.show(ex.message); } }
i need insert table after rectangle. between comments
// tabulka // konec tabulky
how solve this?
you're adding lot of lines of text @ absolute positions. last line of text added @ position y = 633. want add table @ absolute position below last line position, let's @ position x = 36, y = 620. want table centered, width of table 523; that's gdoc.pagesize.width - 36 (left margin) - 36 (right margin).
how explained in official documentation. see instance answer question how add table bottom of last page? (please browse documentation , searches, instance writeselectedrows() method).
if you've created pdfptable
named table
, you'd need this:
table.totalwidth = 523; float y = table.writeselectedrows(0, -1, 36, 620, writer.directcontent);
the value of y
position of bottom of table.
Comments
Post a Comment