Understanding widgets

MBWidget

MBWidget is a parent for all the widgets

Div

Div is a container unit that divides the document into sections and encapsulates other widgets. It implements BorderProperties and ColorProperties.

The available methods are:

Void setFreezeChildren(Boolean freezeChildren); 
boolean isFreezeChildren();

setfreezeChildren(true) will render all the child components of Div in a single page.

Example:

Div div = new Div(); 
div.setFreezeChildren(true); 
div.setWidth(200); 
div.setHeight(100); 
div.borders(true); 
div.setBorderColor(Color.decode("#057dcd")); 
Div childDiv1 = new Div();
childDiv1.setWidth(div.getWidth() / 2);
childDiv1.setHeight(90); 
childDiv1.borders(true); 
childDiv1.setBorderColor(Color.decode("#464646")); 
div.appendChild(childDiv1); 
Div childDiv2 = new Div(); 
childDiv2.setWidthPercentage(50); 
childDiv2.setHeight(90); 
childDiv2.borders(true); 
childDiv2.setMarginLeft(childDiv1.getWidth()); 
childDiv2.setBorderColor(Color.decode("#464646")); 
div.appendChild(childDiv2); 
page.addWidget(div);

Table

Table allows you to arrange data like text, images, links, etc. in rows and columns. It implements FontProperties.

The available methods are:

Float getCellPadding(); 
void setCellPadding(  
float cellPadding); 
TableRow createRow(); 
boolean isDrawLines(); 
void setDrawLines(Boolean drawLines); 
Color getBorderColor(); 
void setBorderColor(Color borderColor); 
float getBorderLineSize(); 
void setBorderLineSize(float borderLineSize); 
void setFontType(PDType1Font fontType);
PDType1Font getFontType(); 
void setFontSize(float fontSize); 
float getFontSize(); 
void setFontBold(Boolean isBold); 
boolean isFontBold();

Example:

Table table = new Table(); 
TableRow header = table.createRow(); 
header.setHeaderRow(true); 
TableCell cell1 = header.createCell(); 
cell1.setValue("Id"); 
TableCell cell2 = header.createCell(); 
cell2.setValue("Name"); 
TableRow row1 = table.createRow(); 
TableCell r1c1 = row1.createCell(); 
r1c1.setValue("1"); 
TableCell r1c2 = row1.createCell(); 
r1c2.setValue("Anne"); 
page.addWidget(table);

DataTable

DataTable is a wrapper on top of the Table to provide abstraction of low-level details for table construction like, creating table, row objects etc. It provides methods to deal with data.

The available methods are:

void  
setCellConfigs(List<CellConfig> cellConfigs); 
List<CellConfig> getCellConfigs(); 
void setRows(List<RowData> rowsData); 
List<RowData> getRows(); 
Color getHeaderBackgroundColor(); 
void setHeaderBackgroundColor(Color HeaderBackgroundColor); 
Color getHeaderFontColor(); 
void setHeaderFontColor(Color headerFontColor); 
Color getCellBackgroundColor(); 
void setCellBackgroundColor(Color cellBackgroundColor); 
Color getCellFontColor(); 
void setCellFontColor(Color cellFontColor); 
Alignment getHeaderCellAlignment(); 
void setHeaderCellAlignment(Alignment headerCellAlignment); 
boolean isHideHeader(); 
void setHideHeader(boolean hideHeader);

Example:

DataTable dataTable = new DataTable(); 
// Create each CellConfiguaration like title, backgroundColor etc.. 
CellConfig cell1Config = new CellConfig("id", "Id #"); 
cell1Config.setBackgroundColor(Color.BLUE); 
CellConfig cell2Config = new CellConfig("name", "Name"); 
List < CellConfig > cellConfigs = new ArrayList < > (); 
cellConfigs.add(cell1Config); 
cellConfigs.add(cell2Config); 
// Prepare the Data, a simple list of RowData Object 
List < RowData > rowsData = getData(); 
dataTable.setCellConfigs(cellConfigs);
dataTable.setRows(rowsData); 
page.addWidget(dataTable);

FormPanel

Formpanel allows you to arrange a row of data in a form-like structure and provides methods to customize the form.

The widget uses the properties of its parent component.

Example:

FormPanel formPanel = new FormPanel(); 
PanelData panelData = formPanel.createPanelData(); 
panelData.setAlignment(Alignment.HORIZONTAL); 
panelData.setCellConfigs(cellConfigs); 
panelData.setData(rowData); 
page.addWidget(panelData);

Image

Image is a container to hold an image. You can use all methods of widget provider.

The available constructors are:

public Image(String filePath, float, width, float, height); 
public Image(File file, float, width, float, height); 
public Image(URL remoteFileUrl, float, width, float, height); 
public Image(String filePath); 
public Image(File file); 
public Image(URL remoteFileUrl);

Example:

Image image = new Image( new File("path to image")); 
image.setWidth(100); 
image.setHeight(100); 
page.addWidget(image);

TextBox

TextBox is the wrapper for a paragraph in a PDF. It automatically breaks and aligns the paragraph to fit into its width. You can use all methods of widget provider.

The widget uses the properties of its parent component.

Example:

TextBox textBox = new TextBox("Sed ut perspiciatis, unde omnis iste natus error "); 
textBox.setWidth(50); 
textBox.setHeight(50); 
page.addWidget(textBox);

BorderProps

BorderProps can be used to implement methods for creating and customizing borders.

The available methods are:

void setBorders(float borderTop, float borderRight, float borderBottom, float borderLeft); 
void setBorderTop(float borderTop); 
float getBorderTop(); 
void setBorderRight(float borderRight); 
float getBorderRight(); 
void setBorderBottom(float borderBottom); 
float getBorderBottom(); 
void setBorderLeft(float borderLeft); 
float getBorderLeft(); 
void setBorderWidth(float borderWidth); 
float getBorderWidth(); 
void borders(boolean borders); 
boolean isBordersAllow(); 
void setBordersAllow(Boolean borders);
void borderTop(boolean borderTop);
boolean isBorderTopAllow(); 
void borderRight(Boolean borderRight); 
boolean isBorderRightAllow(); 
void borderBottom(Boolean ,borderBottom); 
boolean isBorderBottomAllow(); 
void borderLeft( boolean borderLeft); 
boolean isBorderLeftAllow(); 
void setBorderColor(Color color); 
Color getBorderColor();

Example:

Div div = new Div();
div.setBorderTop(2f);

ColorPros

ColorPros can be used to implement methods to assign colors.

The available methods are:

void setBackgroundColor(Color color); 
Color getBackgroundColor(); 
void setFontColor(Color color); 
Color getFontColor();

Example:

Div div = new Div();
div.getBackgroundColor();

FontPros

FontPros can be used to implement methods to define a font style.

The available methods are:

void setFontType(PDType1Font fontType); 
PDType1Font getFontType(); 
void setFontSize(float fontSize); 
float getFontSize(); 
void setFontBold(boolean isBold); 
boolean isFontBold(); 
float getFontHeight();

Example:

Div div = new Div();
div.setFontSize(50f);

PageCounter

PageCounter is the wrapper to render a dynamic value of current page index or total pages count in PDF. You can use all methods of MBWidget provider.

The available methods and expressions are:

public static final String CURRENT_PAGE_INDEX = "#{currPage}"; 
public static final String TOTAL_PAGES = "#{totalPages}"; 
void setExpression(String expression); 
String getExpression();

Example:

Div div = new Div();
div.getExpression();

Header is the wrapper for an area at the top of a PDF Page. You can use all methods of the Div provider.

The available methods are:

void setRepeatOnEveryPage(boolean repeatOnEveryPage); 
boolean isRepeatOnEveryPage();

Example:

Div div = new Div();
div.isRepeatOnEveryPage();

Footer is the wrapper for an area at the bottom of a PDF Page. You can use all methods of the Div provider.

The available methods are:

void setRepeatOnEveryPage(boolean repeatOnEveryPage); 
boolean isRepeatOnEveryPage();

Example:

Div div = new Div();
div.isRepeatOnEveryPage();

Last updated

Was this helpful?