List of usage examples for com.itextpdf.text.pdf BaseFont TIMES_ROMAN
String TIMES_ROMAN
To view the source code for com.itextpdf.text.pdf BaseFont TIMES_ROMAN.
Click Source Link
From source file:Registration_Transient.java
private void saveToPdf() { try {/*w w w .java 2s .c o m*/ com.itextpdf.text.Document doc = new com.itextpdf.text.Document(); BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } FileOutputStream fos = new FileOutputStream(path + "\\transient\\" + lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim() + "TransientForm.pdf"); PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("TransientForm.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); //doc.open(); //doc.add(new Paragraph(contents.getText().trim() + "-markram")); float varPosition = 0; for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); //Text over the existing page BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); varPosition = 15; //last name content.showTextAligned(PdfContentByte.ALIGN_LEFT, lastNameTextField.getText().trim() + ", " + firstNameTextField.getText().trim(), 100, 661 + varPosition, 0); //first name content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MM/dd/yyyy").format(Calendar.getInstance().getTime()), 400, 661 + varPosition, 0); if (residentNameCheckBox.isSelected()) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentComboBox.getSelectedItem().toString(), 125, 633 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, residentComboBox.getSelectedItem().toString(), 470, 633 + varPosition, 0); } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 125, 633 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, "N / A", 470, 633 + varPosition, 0); } content.showTextAligned(PdfContentByte.ALIGN_LEFT, mobileNoTextField.getText(), 135, 590 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, emailTextField.getText(), 400, 590 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, addressTextField.getText(), 175, 577 + varPosition, 0); varPosition = 35; content.showTextAligned(PdfContentByte.ALIGN_LEFT, roomReservedTextField.getText(), 135, 507 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateArrivalChooserCombo.getText(), 135, 493 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, dateDepartureChooserCombo.getText(), 435, 493 + varPosition, 0); content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestSpinner.getValue().toString(), 180, 478 + varPosition, 0); for (int count = 0; count < guestTable.getRowCount(); count++) { float x = 50; if (count <= 3) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x, 435 + varPosition, 0); varPosition -= 13; if (count == 3) { varPosition = 35; } } else if (count >= 4 & count <= 7) { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x + 200, 435 + varPosition, 0); varPosition -= 13; if (count == 7) { varPosition = 35; } } else { content.showTextAligned(PdfContentByte.ALIGN_LEFT, guestTable.getValueAt(count, 0).toString(), x + 400, 435 + varPosition, 0); varPosition -= 13; } } content.endText(); } pdfStamper.close(); pdfReader.close(); } catch (DocumentException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (FileNotFoundException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } catch (IOException ex) { // Logger.getLogger(Registration_Transient.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); } }
From source file:Billing_v2.java
public boolean saveStatementOfAccountToPDF(ArrayList<String> info) { try {// w w w .ja v a 2 s.co m BufferedReader br = new BufferedReader(new FileReader("dir\\defaults.txt")); String path = ""; try { StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { sb.append(line); sb.append(System.lineSeparator()); line = br.readLine(); } path = sb.toString().trim(); } finally { br.close(); } com.itextpdf.text.Document doc = new com.itextpdf.text.Document(); FileOutputStream fos = new FileOutputStream( path + "\\residentStatementOfAccount\\" + info.get(0) + "statementOfAccounts.pdf"); PdfWriter pdfWriter = PdfWriter.getInstance(doc, fos); PdfReader pdfReader = new PdfReader("statementOfAccounts.pdf"); PdfStamper pdfStamper = new PdfStamper(pdfReader, fos); java.util.Date date = new SimpleDateFormat("yyyy-MM-dd").parse(info.get(6)); for (int i = 1; i <= pdfReader.getNumberOfPages(); i++) { PdfContentByte content = pdfStamper.getOverContent(i); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.WINANSI, BaseFont.EMBEDDED); content.beginText(); content.setFontAndSize(bf, 10); //month content.showTextAligned(PdfContentByte.ALIGN_LEFT, new SimpleDateFormat("MMMM").format(date), 205, 625, 0); //name content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(0), 125, 610, 0); //roomNumber content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(1), 130, 598, 0); //monthly rate content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(2), 205, 560, 0); //Shuttle rate content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(3), 205, 545, 0); //gadget rate content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(4), 205, 530, 0); //additional fee content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(5), 205, 518, 0); //total amount Double totalAmount = Double.parseDouble(info.get(2)) + Double.parseDouble(info.get(3)) + Double.parseDouble(info.get(4)); content.showTextAligned(PdfContentByte.ALIGN_LEFT, totalAmount + "", 205, 490, 0); //due date Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.add(Calendar.MONTH, Calendar.MONTH - 1); content.showTextAligned(PdfContentByte.ALIGN_LEFT, info.get(7), 130, 463, 0); content.endText(); } pdfStamper.close(); pdfReader.close(); fos.close(); pdfWriter.close(); return true; } catch (DocumentException | ParseException ex) { // Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } catch (FileNotFoundException ex) { // Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } catch (IOException ex) { // Logger.getLogger(Billing_v2.class.getName()).log(Level.SEVERE, null, ex); new MessageDialog().error(this, ex.getMessage()); return false; } }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report that has no data in it (only the image). * The length is the given number of pages. * //from ww w .j ava 2 s.com * @param numPages * @return True if the report was generated. */ public boolean generateBlank(Dao dao, Integer numPages) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 1; while (true) { drawBout(cb, bf, 35, midPage - 35, null); drawBout(cb, bf, midPage + 35, pageWidth - 35, null); if (++count > numPages) { break; } document.newPage(); } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.boutsheet.BoutSheetReport.java
License:Open Source License
/** * Generate a bout sheet report for the given list of bouts. * It is assumed that the list is in the desired order (no sorting is done here). * * @param list/*from w w w . j a va2s .c o m*/ * @return True if the report was generated. */ public boolean generateReport(Dao dao, List<Bout> list) { // step 1: creation of a document-object // rotate to make page landscape Document document = new Document(PageSize.A4.rotate()); try { // step 2: creation of the writer FileOutputStream fos = createOutputFile(); if (fos == null) { return false; } PdfWriter writer = PdfWriter.getInstance(document, fos); writer.setPageEvent(this); // step 3: we open the document document.open(); // step 4: we grab the ContentByte and do some stuff with it PdfContentByte cb = writer.getDirectContent(); BaseFont bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); float pageWidth = cb.getPdfDocument().getPageSize().getWidth(); float midPage = pageWidth / 2; setHeaderString(dao); int count = 0; for (Bout b : list) { boolean rightSide = false; if ((count++ % 2) == 0) { if (count > 2) { // We could put this after Bout 2 is added, but // that could leave a blank last page. document.newPage(); } // Bout 1 (Left side) drawBout(cb, bf, 35, midPage - 35, b); } else { // Bout 2 (Right side) drawBout(cb, bf, midPage + 35, pageWidth - 35, b); rightSide = true; } // Print the watermark, if necessary boolean doWatermark = false; String gClass = b.getGroup().getClassification(); String wmValues = dao.getBoutsheetWatermarkValues(); if ((wmValues != null) && !wmValues.isEmpty()) { String[] tokens = wmValues.split(","); for (String s : tokens) { if (s.trim().equalsIgnoreCase(gClass)) { doWatermark = true; break; } } } if (doWatermark) { int rotation = 45; PdfContentByte ucb = writer.getDirectContentUnder(); BaseFont helv = BaseFont.createFont("Helvetica", BaseFont.WINANSI, false); ucb.saveState(); ucb.setColorFill(BaseColor.LIGHT_GRAY); ucb.beginText(); ucb.setFontAndSize(helv, 86); float centerWidth = document.getPageSize().getWidth() / 4; if (rightSide) { centerWidth = centerWidth * 3; } ucb.showTextAligned(Element.ALIGN_CENTER, gClass, centerWidth, document.getPageSize().getHeight() / 2, rotation); ucb.endText(); ucb.restoreState(); } } } catch (DocumentException de) { logger.error("Document Exception", de); return false; } catch (IOException ioe) { logger.error("IO Exception", ioe); return false; } // step 5: we close the document document.close(); return true; }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }/*from w w w . java 2s . co m*/ cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.setTextMatrix(x, y); cb.showText(string); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float x, float y, float fontSize, String string, boolean strikethrough) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from www.ja v a2 s .c om drawString(cb, bf, x, y, fontSize, string); if (strikethrough) { float halfHeight = (bf.getAscentPoint(string, fontSize)) / 2; float width = bf.getWidthPointKerned(string, fontSize); drawHorizontalLine(cb, x, y + halfHeight, width, 1.5f, 0); } }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//w w w .ja va2 s.co m cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(PdfContentByte.ALIGN_LEFT, string, mid, y, rotation); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawString(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation, boolean strikethrough) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }// w w w . j a va 2s . c om drawString(cb, bf, mid, y, fontSize, string, rotation); if (strikethrough) { float halfHeight = (bf.getAscentPoint(string, fontSize)) / 2; float width = bf.getWidthPointKerned(string, fontSize); if (rotation == 0) { drawHorizontalLine(cb, mid, y + halfHeight, width, 1.5f, 0); } else if (rotation == 90) { drawVerticalLine(cb, mid - halfHeight, y, width, 1.5f, 0); } } }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawStringAligned(PdfContentByte cb, BaseFont bf, int alignment, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }//from www . j a va 2 s . c o m cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(alignment, string, mid, y, rotation); cb.endText(); cb.stroke(); }
From source file:bouttime.report.bracketsheet.BracketSheetUtil.java
License:Open Source License
public static void drawStringCentered(PdfContentByte cb, BaseFont bf, float mid, float y, float fontSize, String string, float rotation) throws DocumentException, IOException { if (bf == null) { bf = BaseFont.createFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.EMBEDDED); }/*from w w w .ja va2 s . com*/ cb.setFontAndSize(bf, fontSize); cb.beginText(); cb.showTextAligned(PdfContentByte.ALIGN_CENTER, (string != null) ? string : "", mid, y, rotation); cb.endText(); cb.stroke(); }