Change orientation of iText PdfPTable -


this i'm getting. how can rotate table - not document. columns wider if table rotated.resulting document

the code below reproduces problem on smaller scale 1 column.

private void exporttableaspdf(file outputfile) {      // pdf document     document pdfdocument = new document();     try {         pdfwriter pdfwriter = pdfwriter.getinstance(pdfdocument, new fileoutputstream(outputfile));          // used rotate page - itext recommended approach in answer question referenced below         // https://developers.itextpdf.com/question/how-rotate-page-while-creating-pdf-document         class rotateevent extends pdfpageeventhelper {             public void onstartpage(pdfwriter writer, document document) {                 writer.addpagedictentry(pdfname.rotate, pdfpage.seascape);             }         }          // rotates each page landscape         pdfwriter.setpageevent(new rotateevent());     } catch (exception e) {         e.printstacktrace();     }     pdfdocument.open();      // pdf table     pdfptable pdfptable = new pdfptable(1);      // add column header cell     pdfpcell datecell = new pdfpcell(new phrase("date"));     pdfptable.addcell(datecell);      // gets cell data     logentrymapper logentrymapper = new logentrymapper();     list<logentry> logentries = logentrymapper.readall();      // adds cell table "date" data     (logentry logentry : logentries) {         datecell = new pdfpcell(new phrase(logentry.getlogentrydate()));         pdfptable.addcell(datecell);     }      // adds table pdf document     try {         pdfdocument.add(pdfptable);     } catch (documentexception e) {         e.printstacktrace();     }      pdfdocument.close(); } 

this code block produces following result.enter image description here

the solution found (with page event listener) different problem: printing upright on document paper size , rotating page including content. problem (printing upright on rotated paper) need initialize document rotated paper size:

document pdfdocument = new document(pagesize.a4.rotate()); 

this way table makes use of additional page size.

you notice, though, there still free space both left , right. there 2 reasons that:

  • tables respect page margins configured document;
  • tables default use 80% of width available.

you can, therefore, reduce free space left , right by

  • reducing page margins, e.g. using yet document constructor

    document pdfdocument = new document(pagesize.a4.rotate(),                                     marginleft, marginright, margintop, marginbottom); 

    or using pdfdocument.setmargins(marginleft, marginright, margintop, marginbottom) before page in question created;

  • increasing percentage of available width used table

    pdfptable.setwidthpercentage(widthpercentage); 

    using widthpercentage value of e.g. 100.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -