Example usage for com.lowagie.text.pdf PdfPTable spacingBefore

List of usage examples for com.lowagie.text.pdf PdfPTable spacingBefore

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfPTable spacingBefore.

Prototype

float spacingBefore

To view the source code for com.lowagie.text.pdf PdfPTable spacingBefore.

Click Source Link

Document

The spacing before the table.

Usage

From source file:userInterface.HospitalAdminRole.ManagePatientsJPanel.java

private void saveAsPdfBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveAsPdfBtnActionPerformed
    Document document = new Document(PageSize.A4.rotate());
    String[] headers = new String[] { "Name", "TimeStamp", "Resp Rate", "Heart Rate", "Blood Pressure",
            "Temperature", "Status" };
    String filename = fileNameTxt.getText();
    try {/*from   www .j a v  a2s . c  o  m*/
        if (!filename.equals("")) {
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename + ".pdf"));

            document.open();
            PdfContentByte cb = writer.getDirectContent();

            cb.saveState();
            PdfPTable table = new PdfPTable(headers.length);
            for (int i = 0; i < headers.length; i++) {
                String header = headers[i];
                PdfPCell cell = new PdfPCell();
                cell.setGrayFill(0.9f);
                cell.setPhrase(new Phrase(header.toUpperCase(), new Font(Font.HELVETICA, 8, Font.BOLD)));
                table.addCell(cell);

            }
            table.completeRow();

            table.spacingBefore();
            table.spacingAfter();
            document.add(table);
            Graphics2D g2 = cb.createGraphicsShapes(500, 500);
            //cb.showTextAligned(PdfContentByte.ALIGN_CENTER, g2, 200, 300, 0);

            Shape oldClip = g2.getClip();
            g2.clipRect(0, 0, 700, 500);

            vitalSignjTable.print(g2);
            g2.setClip(oldClip);

            g2.dispose();
            cb.restoreState();
            JOptionPane.showMessageDialog(null, "file saved", "Saved", JOptionPane.INFORMATION_MESSAGE);
        } else {
            JOptionPane.showMessageDialog(null, "enter the filename", "FileName", JOptionPane.ERROR_MESSAGE);
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}