Example usage for com.lowagie.text.pdf PdfContentByte restoreState

List of usage examples for com.lowagie.text.pdf PdfContentByte restoreState

Introduction

In this page you can find the example usage for com.lowagie.text.pdf PdfContentByte restoreState.

Prototype

public void restoreState() 

Source Link

Document

Restores the graphic state.

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 w  w w .  j av  a 2s .  c  om
        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();
}

From source file:views.HacerPedido.java

private void print() {
    Document document = new Document(PageSize.A4.rotate());
    String username = System.getProperty("user.name");

    //String filepath = "/Users/alejandro/NetBeansProjects/QRGenerator/qrCode.png";
    String filepath = "/Users/" + username + "/Desktop/jajasaludosss.pdf";
    try {/* w  w w . j av a 2s  .com*/
        PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filepath));

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

        cb.saveState();
        Graphics2D g2 = cb.createGraphicsShapes(500, 500);

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

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

        g2.dispose();
        cb.restoreState();
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    document.close();
}