List of usage examples for java.awt Graphics2D clipRect
public abstract void clipRect(int x, int y, int width, int height);
From source file:JTable2Pdf.java
private void print() { Document document = new Document(PageSize.A4.rotate()); try {//from w w w. j a v a 2s .c om PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("jTable.pdf")); document.open(); PdfContentByte cb = writer.getDirectContent(); cb.saveState(); Graphics2D g2 = cb.createGraphicsShapes(500, 500); Shape oldClip = g2.getClip(); g2.clipRect(0, 0, 500, 500); table.print(g2); g2.setClip(oldClip); g2.dispose(); cb.restoreState(); } catch (Exception e) { System.err.println(e.getMessage()); } document.close(); }
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 {//w ww . ja v a 2 s .co 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(); }