java - How to add multiple pages in PDFBox -


i want write content in pdf using pdfbox. once page height less margin need create page. want retain cursor information. s there way through can cursor information cursor present can subtract margin cursor position , add page it. right have done this

pdrectangle rect = page.getmediabox(); float positiony = rect.getwidth();  positiony = positiony - pdfwriter.defaultbottommargin; if(positiony < positionx) {                positiony = rect.getwidth();                 pdpage page2 = page;                rect = page2.getmediabox();                document.addpage(page2);                pdpagecontentstream contentstream = new pdpagecontentstream(document, page2);                contentstream.appendrawcommands("t*\n");                contentstream.begintext();               // contentstream.setfont(font, 12);                contentstream.movetextpositionbyamount(positionx, positiony);                contentstream.drawstring(tmptext[k]);                contentstream.endtext();                contentstream.close();                } 

you can use class level variables below maintains positiony throught execution of pdf generation.

float page_margin = 20; float newpagepositiony = page.findmediabox().getheight() - page_margin; float positiony = newpagepositiony; pdpage currentpage = new pdpage(); 

before adding content on pdf, check whether cursor has reached @ end of page or not. i.e. create funtion shown below

public boolean isendofpage(row row)  {     float currenty = this.positiony ;     boolean isendofpage = currenty  <= (page_margin + 10);      return isendofpage; } 

using above funtion, can create new page required.

if (isendofpage(row))  {     // reset positiony  newpagepositiony     this.positiony  = newpagepositiony;      this.currentpage = new pdpage();      // code } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -