I am using Apache PDFBox(version : 2.0.8) to generate a PDF document from my .jspx page.
In my .jspx page form, there are many fields, so i decided to arrange all the fields as 2 column layout. So, I need suggestion to achieve the layout using PDFbox.
// Sample Code snippet I have used to generate PDF is as below.
PDDocument document = new PDDocument();
PDPage page = new PDPage();
document.addPage(page);
PDFont font = getFontDef();
PDPageContentStream contentStream =new PDPageContentStream(document, page);
contentStream.beginText();
contentStream.showText("Name: " );
contentStream.setFont(getFontDef().COURIER ,15);
contentStream.showText ("Rajeev");
contentStream.showText("Address: " +"BNG");
contentStream.newLine();
contentStream.showText("State: " +"KAR");
contentStream.showText("Country: " +"INDIA");
contentStream.endText();
contentStream.close();
I need to show label(i.e. Name, Address,State and Country) in bold font and Value(i.e. Rajeev, BNG,KAR,IND respectively) as normal font.
To get bold font for the label, I have tried as shown below
contentStream.setFont(getFontDef().COURIER ,15);
and it is working , but I have to add the above line before each label field. is there any better approaches I can use to set bold font for all the labels?
I am also facing some issue in aligning these form fields into two column layout. Ex
Name: Rajeev Address: BNG
State: KAR Country: IND
i.e. Name and Address in first line and Name should be in first column and Address should be in second column. Similarly, State and country in second line and State in first column and country is in second column.