List of usage examples for com.itextpdf.text Chunk Chunk
private Chunk(final Float tabInterval, final boolean isWhitespace)
From source file:watermark.java
public static void main(String[] args) { try {/*from w w w.j a va2s . com*/ PdfReader reader = new PdfReader(args[0]); PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(args[1])); stamp.getWriter().setCompressionLevel(9); // without this code it'll 3 times bigger int bottom_margin = Integer.parseInt(args[2]); String lic = String.format(LIC, args[3]); BaseFont bf = BaseFont.createFont(FONTFILE, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); Chunk c = new Chunk(lic, new Font(bf, 7, Font.NORMAL, TCOLOR)); c.setTextRenderMode(PdfContentByte.TEXT_RENDER_MODE_FILL_STROKE, 1 / 800f, null); Phrase phrase = new Phrase(c); int pages = reader.getNumberOfPages(); int xpos = 90; for (int i = 1; i <= pages; i++) { if (i % 2 == 0) xpos = 160; else xpos = 90; PdfContentByte under = stamp.getUnderContent(i); ColumnText.showTextAligned(under, Element.ALIGN_LEFT, phrase, xpos, bottom_margin, -0); } stamp.setFullCompression(); // without this code it'll 3 times bigger stamp.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:app.App.java
private void setLink(int pageId, PdfStamper stamper) throws ClassNotFoundException, IOException { // load the sqlite-JDBC driver using the current class loader Class.forName("org.sqlite.JDBC"); Connection connection = null; try {/* ww w .j a v a2 s. c o m*/ // create a database connection connection = DriverManager.getConnection("jdbc:sqlite:" + DATABASE); Statement statement = connection.createStatement(); statement.setQueryTimeout(30); // set timeout to 30 sec. ResultSet rs = statement.executeQuery( "select * from page_annotations " + "where annotation_type = 'goto' and page_id = " + pageId); float spendX = 0; float spendY = 0; float coordX = 0; float coordY = 0; int pageDest = 0; Rectangle rect; PdfAnnotation annotation; while (rs.next()) { spendX = rs.getFloat("pdf_width"); spendY = rs.getFloat("pdf_height"); coordX = rs.getFloat("pdf_x");// + rs.getFloat("pdf_width"); coordY = rs.getFloat("pdf_y"); pageDest = rs.getInt("annotation_target"); Font font = FontFactory.getFont(FontFactory.COURIER, 10, Font.UNDERLINE); // Blue font.setColor(0, 0, 255); Chunk chunk = new Chunk("GOTO", font); Anchor anchor = new Anchor(chunk); ColumnText.showTextAligned(stamper.getUnderContent(pageId), Element.ALIGN_LEFT, anchor, coordX + spendX, coordY, 0); rect = new Rectangle(coordX, coordY, spendX, spendY); annotation = PdfAnnotation.createLink(stamper.getWriter(), rect, PdfAnnotation.HIGHLIGHT_INVERT, new PdfAction("#" + pageDest)); stamper.addAnnotation(annotation, pageId); } } catch (SQLException e) { // if the error message is "out of memory", // it probably means no database file is found System.err.println(e.getMessage()); } finally { try { if (connection != null) connection.close(); } catch (SQLException e) { // connection close failed. System.err.println(e); } } }
From source file:AppPackage.printPDF.java
public void printNow(String id, String name, String dateRange, String underLate, String workedHours, String totalHours, String dateNow, String fDate, String lDate, String type, String empTypeRate, int lastRId, double salary) { this.id = id; this.name = name; this.dateRange = dateRange; this.underLate = underLate; this.workedHours = workedHours; this.totalHours = totalHours; this.dateNow = dateNow; this.fDate = fDate; this.lDate = lDate; this.type = type; this.empTypeRate = empTypeRate; this.lastRId = lastRId; this.salary = salary; try {/*from w w w . ja v a 2 s . co m*/ Document document = new Document(); Connection conn = null; Statement st = null; conn = dbC.getConnection(); st = conn.createStatement(); String query = "SELECT * FROM schedule WHERE empId ='" + id + "'"; ResultSet rs = st.executeQuery(query); PdfWriter.getInstance(document, new FileOutputStream("reports/Report-" + reportCount + "." + lastRId + "-" + id + ".pdf")); document.open(); document.setPageSize(PageSize.LETTER); document.setMargins(0f, 0f, 0f, 0f); Image image = Image.getInstance("Resources/DTRHeaderTwo.png"); document.add(image); PdfPTable ICTable = new PdfPTable(5); ICTable.setWidthPercentage(100); ICTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell ICTableCell; Phrase ICBlank = new Phrase(); Phrase ICharge = new Phrase(); Phrase ICBlanko = new Phrase(); Phrase ICBlankx = new Phrase(); Phrase IChargex = new Phrase(); ICBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlank); ICharge.add(new Chunk("_____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(ICharge); ICBlanko.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlanko); ICBlankx.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); ICTable.addCell(ICBlankx); IChargex.add(new Chunk("____________________", new Font(Font.FontFamily.HELVETICA, 8, Font.ITALIC))); ICTable.addCell(IChargex); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); ICTableCell = new PdfPCell( new Phrase("In - Charge", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); ICTableCell.setBorder(PdfPCell.NO_BORDER); ICTable.addCell(ICTableCell); PdfPTable dateRecTable = new PdfPTable(5); dateRecTable.setWidthPercentage(100); dateRecTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell dateRecTableCell; Phrase dRDate = new Phrase(); Phrase dRNo = new Phrase(); Phrase dRBlank = new Phrase(); Phrase dRDatex = new Phrase(); Phrase dRNox = new Phrase(); dRDate.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDate); dRNo.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNo); dRBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRBlank); dRDatex.add( new Chunk("Released #: " + lastRId + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRDatex); dRNox.add(new Chunk("" + dateNow + "", new Font(Font.FontFamily.HELVETICA, 7, Font.ITALIC))); dateRecTable.addCell(dRNox); PdfPTable InfoTable = new PdfPTable(5); InfoTable.setWidthPercentage(100); InfoTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell InfoTableCell; Phrase infoId = new Phrase(); Phrase infoType = new Phrase(); Phrase infoBlank = new Phrase(); Phrase infoIdx = new Phrase(); Phrase infoTypex = new Phrase(); infoId.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoId); infoType.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoType); infoBlank.add(new Chunk("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoBlank); infoIdx.add(new Chunk("ID: " + id + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoIdx); infoTypex.add(new Chunk("Type: " + type + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTable.addCell(infoTypex); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Fullname: " + name + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Hourly Rate: " + empTypeRate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Date Range: \n" + dateRange + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Total Hours: " + totalHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Late & Under Time: " + underLate + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("Worked Hours: " + workedHours + "", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell( new Phrase("Salary: " + salary + " PHP", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); InfoTableCell = new PdfPCell(new Phrase("", new Font(Font.FontFamily.HELVETICA, 7, Font.NORMAL))); InfoTableCell.setBorder(PdfPCell.NO_BORDER); InfoTable.addCell(InfoTableCell); PdfPTable SchedTable = new PdfPTable(17); SchedTable.setWidthPercentage(100); SchedTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell SchedTableCell; Phrase phraseDayS = new Phrase(); Phrase phraseAMTotal = new Phrase(); Phrase phraseAMStart = new Phrase(); Phrase phraseAMEnd = new Phrase(); Phrase phrasePMTotal = new Phrase(); Phrase phrasePMStart = new Phrase(); Phrase phrasePMEnd = new Phrase(); Phrase phraseTotalTime = new Phrase(); Phrase phraseBlankS = new Phrase(); Phrase phraseDaySx = new Phrase(); Phrase phraseAMTotalx = new Phrase(); Phrase phraseAMStartx = new Phrase(); Phrase phraseAMEndx = new Phrase(); Phrase phrasePMTotalx = new Phrase(); Phrase phrasePMStartx = new Phrase(); Phrase phrasePMEndx = new Phrase(); Phrase phraseTotalTimex = new Phrase(); phraseDayS.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDayS); phraseAMStart.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStart); phraseAMEnd.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEnd); phraseAMTotal.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotal); phrasePMStart.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStart); phrasePMEnd.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEnd); phrasePMTotal.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotal); phraseTotalTime.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTime); phraseBlankS.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseBlankS); phraseDaySx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseDaySx); phraseAMStartx.add(new Chunk("AM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMStartx); phraseAMEndx.add(new Chunk("AM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMEndx); phraseAMTotalx.add(new Chunk("AM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseAMTotalx); phrasePMStartx.add(new Chunk("PM Start", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMStartx); phrasePMEndx.add(new Chunk("PM End", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMEndx); phrasePMTotalx.add(new Chunk("PM Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phrasePMTotalx); phraseTotalTimex.add(new Chunk("Total", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); SchedTable.addCell(phraseTotalTimex); while (rs.next()) { SimpleDateFormat readingFormat = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat outputFormat = new SimpleDateFormat("hh:mm a"); String dayxxx = rs.getString("day"); String amStartxx = rs.getString("amStart"); String amEndxx = rs.getString("amEnd"); String pmStartxx = rs.getString("pmStart"); String pmEndxx = rs.getString("pmEnd"); String amTotalxx = rs.getString("amTotal"); String pmTotalxx = rs.getString("pmTotal"); String totalHoursxx = rs.getString("totalTime"); String blank = " "; String amStart = null; String amEnd = null; String amTotal = null; String pmStart = null; String pmEnd = null; String pmTotal = null; String totalHoursx = null; Date dayx = new SimpleDateFormat("EEEE").parse(dayxxx); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String day = sdfxxx.format(dayx); System.out.println(day + " day"); try { Date amStartTxx = readingFormat.parse(amStartxx); amStart = outputFormat.format(amStartTxx); if (amStart.equals("12:00 AM")) { amStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amEndTx = readingFormat.parse(amEndxx); amEnd = outputFormat.format(amEndTx); if (amEnd.equals("12:00 AM")) { amEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date amTotalTx = readingFormat.parse(amTotalxx); amTotal = outputFormat.format(amTotalTx); if (amTotal.equals("12:00 AM")) { amTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmStartTxx = readingFormat.parse(pmStartxx); pmStart = outputFormat.format(pmStartTxx); if (pmStart.equals("12:00 AM")) { pmStart = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmEndTxx = readingFormat.parse(pmEndxx); pmEnd = outputFormat.format(pmEndTxx); if (pmEnd.equals("12:00 AM")) { pmEnd = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date pmTotalTxx = readingFormat.parse(pmTotalxx); pmTotal = outputFormat.format(pmTotalTxx); if (pmTotal.equals("12:00 AM")) { pmTotal = "00:00"; } } catch (Exception e) { e.printStackTrace(); } try { Date totalHoursxT = readingFormat.parse(totalHoursxx); totalHoursx = outputFormat.format(totalHoursxT); if (totalHoursx.equals("12:00 AM")) { totalHoursx = "00:00"; } } catch (Exception e) { e.printStackTrace(); } System.out.println(day); System.out.println(amStart); System.out.println(amEnd); System.out.println(amTotal); System.out.println(pmStart); System.out.println(pmEnd); System.out.println(pmTotal); System.out.println(totalHoursx); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(blank)); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell(new Phrase(day, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(amTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmStart, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmEnd, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(pmTotal, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); SchedTableCell = new PdfPCell( new Phrase(totalHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); SchedTableCell.setBorder(PdfPCell.NO_BORDER); SchedTable.addCell(SchedTableCell); } PdfPTable DTRTable = new PdfPTable(17); DTRTable.setWidthPercentage(100); DTRTable.getDefaultCell().setBorder(0); //create a cell object PdfPCell DTRTableCell; Phrase phraseDay = new Phrase(); Phrase phraseDate = new Phrase(); Phrase phraseAMIn = new Phrase(); Phrase phraseAMOut = new Phrase(); Phrase phrasePMIn = new Phrase(); Phrase phrasePMOut = new Phrase(); Phrase phraseHours = new Phrase(); Phrase phraseUTL = new Phrase(); Phrase phraseBlank = new Phrase(); Phrase phraseDayx = new Phrase(); Phrase phraseDatex = new Phrase(); Phrase phraseAMInx = new Phrase(); Phrase phraseAMOutx = new Phrase(); Phrase phrasePMInx = new Phrase(); Phrase phrasePMOutx = new Phrase(); Phrase phraseHoursx = new Phrase(); Phrase phraseUTLx = new Phrase(); phraseDay.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDay); phraseDate.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDate); phraseAMIn.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMIn); phraseAMOut.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOut); phrasePMIn.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMIn); phrasePMOut.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOut); phraseHours.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHours); phraseUTL.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTL); phraseBlank.add(new Chunk(" ", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseBlank); phraseDayx.add(new Chunk("Day", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDayx); phraseDatex.add(new Chunk("Date", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseDatex); phraseAMInx.add(new Chunk("AM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMInx); phraseAMOutx.add(new Chunk("AM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseAMOutx); phrasePMInx.add(new Chunk("PM IN", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMInx); phrasePMOutx.add(new Chunk("PM OUT", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phrasePMOutx); phraseHoursx.add(new Chunk("Hours", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseHoursx); phraseUTLx.add(new Chunk("Late/U.T", new Font(Font.FontFamily.HELVETICA, 6, Font.BOLD))); DTRTable.addCell(phraseUTLx); try { Connection connx = null; Statement stx = null; connx = dbC.getConnection(); stx = connx.createStatement(); String queryx = "SELECT timeinout.day, timeinout.date, schedule.totalTime, schedule.amTotal, " + "schedule.amStart, timeinout.amTimeIn, schedule.amEnd, timeinout.amTimeOut, " + "schedule.pmTotal, schedule.pmStart, timeinout.pmTimeIn, schedule.pmEnd, " + "timeinout.pmTimeOut FROM timeinout LEFT JOIN " + "(schedule) ON (schedule.empId = timeinout.empId AND timeinout.day = schedule.day) WHERE " + "timeinout.empId ='" + id + "' AND schedule.empId = '" + id + "' AND date(`Date`) >= '" + fDate + "' " + "AND date(`Date`) <= '" + lDate + "'"; ResultSet rsx = stx.executeQuery(queryx); while (rsx.next()) { String day = rsx.getString("timeinout.day"); String date = rsx.getString("timeinout.date"); String amStartDB = rsx.getString("schedule.amStart"); String amIn = rsx.getString("timeinout.amTimeIn"); String amEndDB = rsx.getString("schedule.amEnd"); String amOut = rsx.getString("timeinout.amTimeOut"); String pmStartDB = rsx.getString("schedule.pmStart"); String pmIn = rsx.getString("timeinout.pmTimeIn"); String pmEndDB = rsx.getString("schedule.pmEnd"); String pmOut = rsx.getString("timeinout.pmTimeOut"); String totTime = rsx.getString("schedule.totalTime"); String wHours; String blank = " "; String dayx = rsx.getString("timeinout.day"); String datex = rsx.getString("timeinout.date"); // String amStartDBx = rsx.getString("schedule.amStart"); // String amInx = rsx.getString("timeinout.amTimeIn"); // String amEndDBx = rsx.getString("schedule.amEnd"); // String amOutx = rsx.getString("timeinout.amTimeOut"); // String pmStartDBx = rsx.getString("schedule.pmStart"); // String pmInx = rsx.getString("timeinout.pmTimeIn"); // String pmEndDBx = rsx.getString("schedule.pmEnd"); String pmOutx = rsx.getString("timeinout.pmTimeOut"); String totalAM = rsx.getString("schedule.amTotal"); String totalPM = rsx.getString("schedule.pmTotal"); String totTimex = rsx.getString("schedule.totalTime"); String wHoursx; parser.setTimeZone(TimeZone.getTimeZone("UTC")); if (!amEndDB.equals("00:00:00") && !amOut.equals("00:00:00")) { Start = parser.parse(amEndDB); In = parser.parse(amOut); if (Start.after(In)) { amOutDiff = tDiff.timeDiff(amOut, amEndDB); amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } else { amOutDiff = "00:00:00"; } } else { amOutDiff = totalAM; amOutDiffT = parser.parse(amOutDiff); amOutDiffTotal += amOutDiffT.getTime(); } Start = parser.parse(amStartDB); In = parser.parse(amIn); if (Start.after(In)) { amInDiff = "00:00:00"; } else if (amOutDiff.equals(totalAM)) { amInDiff = "00:00:00"; } else { amInDiff = tDiff.timeDiff(amStartDB, amIn); amInDiffT = parser.parse(amInDiff); amInDiffTotal += amInDiffT.getTime(); } if (!pmEndDB.equals("00:00:00") && !pmOut.equals("00:00:00")) { Start = parser.parse(pmEndDB); In = parser.parse(pmOut); if (Start.after(In)) { pmOutDiff = tDiff.timeDiff(pmOut, pmEndDB); pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } else { pmOutDiff = "00:00:00"; } } else { pmOutDiff = totalPM; pmOutDiffT = parser.parse(pmOutDiff); pmOutDiffTotal += pmOutDiffT.getTime(); } Start = parser.parse(pmStartDB); In = parser.parse(pmIn); if (Start.after(In)) { pmInDiff = "00:00:00"; } else if (pmOutDiff.equals(totalPM)) { pmInDiff = "00:00:00"; } else { pmInDiff = tDiff.timeDiff(pmStartDB, pmIn); pmInDiffT = parser.parse(pmInDiff); pmInDiffTotal += pmInDiffT.getTime(); } Date totH = parser.parse(totTimex); long totHTotal = 0; totHTotal += totH.getTime(); Date amInDiffx = parser.parse(amInDiff); Date amOutDiffx = parser.parse(amOutDiff); Date pmInDiffx = parser.parse(pmInDiff); Date pmOutDiffx = parser.parse(pmOutDiff); long workedHoursxxx = amInDiffx.getTime() + amOutDiffx.getTime() + pmInDiffx.getTime() + pmOutDiffx.getTime(); long hoursx = workedHoursxxx / 3600000; long minutesx = (workedHoursxxx % 3600000) / 60000; wHours = String.format("%02d:%02d", hoursx, minutesx); wHoursx = String.format("%02d:%02d", hoursx, minutesx); Date dayxxx = new SimpleDateFormat("EEEE").parse(day); SimpleDateFormat sdfxxx = new SimpleDateFormat("EEE"); String newDayxx = sdfxxx.format(dayxxx); System.out.println(newDayxx); DTRTableCell = new PdfPCell( new Phrase(newDayxx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexx = new SimpleDateFormat("yyyy-MM-dd").parse(date); SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy"); String newDate = sdf.format(datexx); System.out.println(newDate); DTRTableCell = new PdfPCell( new Phrase(newDate, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOut); DTRTableCell = new PdfPCell( new Phrase(pmOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTime); DTRTableCell = new PdfPCell( new Phrase(totTime, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHours); DTRTableCell = new PdfPCell( new Phrase(wHours, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(blank); DTRTableCell = new PdfPCell(new Phrase(blank)); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date dayxx = new SimpleDateFormat("EEEE").parse(dayx); SimpleDateFormat sdfxx = new SimpleDateFormat("EEE"); String newDayx = sdfxx.format(dayxx); System.out.println(newDayx); DTRTableCell = new PdfPCell( new Phrase(newDayx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); Date datexxx = new SimpleDateFormat("yyyy-MM-dd").parse(datex); SimpleDateFormat sdfx = new SimpleDateFormat("dd-MM-yy"); String newDatex = sdfx.format(datexxx); System.out.println(newDatex); DTRTableCell = new PdfPCell( new Phrase(newDatex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amIn); DTRTableCell = new PdfPCell( new Phrase(amIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(amOut); DTRTableCell = new PdfPCell( new Phrase(amOut, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmIn); DTRTableCell = new PdfPCell( new Phrase(pmIn, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(pmOutx); DTRTableCell = new PdfPCell( new Phrase(pmOutx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(totTimex); DTRTableCell = new PdfPCell( new Phrase(totTimex, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); System.out.println(wHoursx); DTRTableCell = new PdfPCell( new Phrase(wHoursx, new Font(Font.FontFamily.HELVETICA, 6, Font.NORMAL))); DTRTableCell.setBorder(PdfPCell.NO_BORDER); DTRTable.addCell(DTRTableCell); } } catch (Exception e) { JOptionPane.showMessageDialog(null, e); } document.add(dateRecTable); document.add(InfoTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Schedule Schedule\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(SchedTable); document.add(new Paragraph( "----------------------------------------------------------------------- ----------------------------------------------------------------------", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, BaseColor.BLACK))); document.add(new Paragraph( " Dailty Time Record Dailty Time Record\n", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL, BaseColor.BLACK))); document.add(DTRTable); document.add(ICTable); try { conn = dbC.getConnection(); PreparedStatement stmtx = conn.prepareStatement("INSERT INTO released" + "(empId, firstDate, lastDate, totalHours, lateUnderTime, workedHours, fileName, salary) VALUES (?,?,?,?,?,?,?,?)"); stmtx.setString(1, id); stmtx.setString(2, fDate); stmtx.setString(3, lDate); stmtx.setString(4, totalHours); stmtx.setString(5, workedHours); stmtx.setString(6, totalHours); stmtx.setString(7, "Report-" + reportCount + "." + lastRId + "-" + id + ".pdf"); stmtx.setString(8, salary + ""); stmtx.executeUpdate(); } catch (SQLException se) { //Handle errors for JDBC se.printStackTrace(); } catch (Exception e) { //Handle errors for Class.forName e.printStackTrace(); } finally { //finally block used to close resources try { if (stmt != null) conn.close(); } catch (SQLException se) { } // do nothing try { if (conn != null) conn.close(); } catch (SQLException se) { se.printStackTrace(); } //end finally try } //end try document.close(); } catch (DocumentException | IOException | SQLException e) { JOptionPane.showMessageDialog(null, e); } catch (ParseException ex) { Logger.getLogger(printPDF.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:at.jps.sanction.core.io.file.PDFFileOutputWorker.java
License:Open Source License
@Override public void handleMessage(final AnalysisResult message) { super.handleMessage(message); try {//from w w w. j a v a2s. co m logger.info("write Message: " + message.getMessage().getId()); final Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(getFilename())); document.open(); final Font chapterFont = FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD); final Font paragraphFont = FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL); Chunk chunk = new Chunk("Message", chapterFont); Chapter chapter = new Chapter(new Paragraph(chunk), 1); chapter.setNumberDepth(0); chapter.add(new Paragraph(message.getMessage().toString(), paragraphFont)); document.add(chapter); getWriter().write(message.getMessage().toString()); if (message.getHitList() != null) { chapter.add(new Paragraph("Hits", paragraphFont)); for (final HitResult hit : message.getHitList()) { final PdfPTable table = new PdfPTable(2); table.addCell("Description"); table.addCell(hit.getHitDescripton()); table.addCell("Field"); table.addCell(hit.getHitDescripton()); table.addCell("Absolute Value"); table.addCell(hit.getAbsolutHit() + ""); table.addCell("Relative Value"); table.addCell(hit.getRelativeHit() + ""); table.addCell("Phrase Value"); table.addCell(hit.getPhraseHit() + ""); table.addCell("HitType"); table.addCell(hit.getHitType()); document.add(table); } } else { final String exception = message.getException(); if (exception != null) { chunk = new Chunk("Error:", chapterFont); chapter = new Chapter(new Paragraph(chunk), 1); chapter.add(new Paragraph(message.getException().toString(), paragraphFont)); document.add(chapter); } } document.close(); } catch (final Exception e) { logger.error("Error writing to file:" + getFilename()); logger.debug("Exception: ", e); } }
From source file:avalonscrollmaker20.AnothakScribe.java
License:Open Source License
public void writeToDoc(ArrayList<AnothakScroll> spellList, boolean simpleMode) { // Format content for inserting into a PDF for (int i = 0; i < spellList.size(); i++) { Paragraph spellCode = new Paragraph(spellList.get(i).spellCode, f_code); spellCode.setAlignment(ElementTags.ALIGN_RIGHT); spellCode.setMultipliedLeading(0.5f); spellCode.setIndentationRight(15f); Paragraph spellTitle = new Paragraph(spellList.get(i).spellTitle + "\n", f_title); spellTitle.setAlignment(ElementTags.ALIGN_CENTER); spellTitle.setMultipliedLeading(0.5f); spellTitle.setSpacingAfter(36f); Paragraph spellCircleSchool;//from w w w. ja v a 2s . c om if (spellList.get(i).isPure()) spellCircleSchool = new Paragraph(spellList.get(i).spellCircle.toString() + " Circle\n of " + spellList.get(i).spellOldSchool.toString(), f_schoolPure); else // !spellList.get( i ).isPure() spellCircleSchool = new Paragraph(spellList.get(i).spellCircle.toString() + " Circle\n of " + spellList.get(i).spellOldSchool.toString(), f_school); spellCircleSchool.setAlignment(ElementTags.ALIGN_LEFT); spellCircleSchool.setIndentationLeft(18f); spellCircleSchool.setMultipliedLeading(1.75f); Paragraph sourceKeu = new Paragraph(spellList.get(i).sourceKeu.toString() + "|~", f_keu); sourceKeu.setAlignment(ElementTags.ALIGN_RIGHT); sourceKeu.setIndentationRight(36f); sourceKeu.setMultipliedLeading(1f); Paragraph directionKeu = new Paragraph("", f_keu); directionKeu.setAlignment(ElementTags.ALIGN_RIGHT); directionKeu.setIndentationRight(90f); directionKeu.setMultipliedLeading(0.875f); Paragraph destinationKeu = new Paragraph(spellList.get(i).destinationKeu.toString() + "|~", f_keu); destinationKeu.setAlignment(ElementTags.ALIGN_RIGHT); destinationKeu.setIndentationRight(36f); destinationKeu.setMultipliedLeading(0.625f); Paragraph phraseCommon; Paragraph phraseSymbol; if (spellList.get(i).spellCircle != Circle.SEVENTH && spellList.get(i).spellCircle != Circle.PURE_SEVENTH) { phraseCommon = new Paragraph("", f_phraseCommon); phraseCommon.setSpacingAfter(27f); phraseSymbol = new Paragraph("", f_phraseSymbol); if ((i % 2) <= 0) phraseSymbol.setSpacingAfter(90f); else // ( (i % 2) > 0 ) phraseSymbol.setSpacingAfter(0f); } else { phraseCommon = new Paragraph("", f_phraseCommonBreath); phraseCommon.setSpacingAfter(36f); phraseSymbol = new Paragraph("", f_phraseSymbolBreath); if ((i % 2) <= 0) phraseSymbol.setSpacingAfter(103.5f); else // ( (i % 2) > 0 ) phraseSymbol.setSpacingAfter(0f); } phraseCommon.setAlignment(ElementTags.ALIGN_CENTER); phraseCommon.setMultipliedLeading(1.5f); for (AnothakScroll.Word w : spellList.get(i).liersethPhrase_Common) phraseCommon.add(w.toString() + " "); if (simpleMode) { phraseSymbol.setAlignment(ElementTags.ALIGN_CENTER); phraseSymbol.setSpacingBefore(36f); phraseSymbol.setSpacingAfter(0f); phraseSymbol.setMultipliedLeading(0.75f); } else // not simpleMode { phraseSymbol.setAlignment(ElementTags.ALIGN_CENTER); phraseSymbol.setMultipliedLeading(0.5f); } for (AnothakScroll.Symbol s : spellList.get(i).liersethPhrase_Symbol) { phraseSymbol.add(s.toString()); } // Add content to the document try { if (simpleMode) doc_scrolls.add(phraseSymbol); else { Image tmpImage = null; tmpImage = spellList.get(i).backgroundImageFull; if (tmpImage != null) { if ((i % 2) <= 0) tmpImage.setAbsolutePosition(9f, 405f); else // (i % 2) >= 0 tmpImage.setAbsolutePosition(9f, 9f); doc_scrolls.add(tmpImage); } //doc_scrolls.add( Chunk.NEWLINE ); doc_scrolls.add(spellCode); doc_scrolls.add(spellTitle); // Crap, I hate formatting MultiColumnText mct = new MultiColumnText(108f); mct.addRegularColumns(doc_scrolls.left(), doc_scrolls.right(), 54f, 2); mct.addElement(spellCircleSchool); mct.addElement(sourceKeu); mct.addElement(directionKeu); mct.addElement(destinationKeu); doc_scrolls.add(mct); doc_scrolls.add(new Chunk("\n", new Font(Font.FontFamily.COURIER, 18f, Font.NORMAL))); doc_scrolls.add(phraseCommon); doc_scrolls.add(phraseSymbol); if ((i % 2) > 0) doc_scrolls.newPage(); } } catch (Exception ex) { System.err.println(ex + "\nProgram closing."); System.exit(4); } } // Close the Document doc_scrolls.close(); JOptionPane.showMessageDialog(null, doc_name + " was printed successfully!", "Print Status", JOptionPane.INFORMATION_MESSAGE); }
From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private Chunk generateFittedChunk(String text, int style) { float size = 9 - (text.length() - 10f) / 5f; return new Chunk(text, new Font(Font.FontFamily.HELVETICA, size, style)); }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
protected void printKeyData(SessionContainerWO sessionContainerWO) { try {//from ww w . ja v a2s . c om doc.add(new Paragraph(" ")); table = new PdfPTable(15); table.setWidthPercentage(100); // kernel-data cell = new PdfPCell(new Paragraph(getTran("Web.Occup", "medwan.common.kernel-data").toUpperCase(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.ITALIC))); cell.setColspan(15); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); table.addCell(cell); // row 1 : last-periodical-examination Paragraph par = new Paragraph( getTran("Web.Occup", "medwan.common.last-periodical-examination").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); TransactionVO tran = sessionContainerWO.getLastTransaction(IConstants_PREFIX + "TRANSACTION_TYPE_MER"); ItemVO item; if (tran != null) { item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_MER_EXAMINATION_DATE"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD))); } } cell = new PdfPCell(par); cell.setColspan(5); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 1 : next-periodical-examination par = new Paragraph( getTran("Web.Occup", "medwan.common.next-periodical-examination").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); if (sessionContainerWO.getFlags().getLastExaminationReport() != null && sessionContainerWO.getFlags() .getLastExaminationReport().getNewExaminationDueDate() != null) { par.add(new Chunk( dateFormat.format(sessionContainerWO.getFlags().getLastExaminationReport() .getNewExaminationDueDate()), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD))); } cell = new PdfPCell(par); cell.setColspan(5); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 1 : next-driver-examination / Volgend onderzoek medische schifting par = new Paragraph(getTran("Web.Occup", "medwan.common.next-driver-examination").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); if (sessionContainerWO.getFlags().getLastDrivingCertificate() != null) { // CBMT only : only display newExaminationDueDate if patient has riskcode "070" (drivinglicense) boolean riskCode070Found = false; if (riskCode070Found) { String newExamDueDateMinus = ScreenHelper.checkString(sessionContainerWO.getFlags() .getLastDrivingCertificate().getNewExaminationDueDateMinus()); if (newExamDueDateMinus.length() > 0) { par.add(new Chunk(newExamDueDateMinus.replaceAll("-", "/"), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD))); } } } else { // no data available par.add(new Chunk(getTran("Web.Occup", "medwan.common.no-data"), FontFactory.getFont( FontFactory.HELVETICA, Math.round((double) 8 * fontSizePercentage / 100.0), Font.BOLD))); } cell = new PdfPCell(par); cell.setColspan(5); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 2 : Biometrie par = new Paragraph(getTran("Web.Occup", "medwan.common.biometry").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); tran = sessionContainerWO.getLastTransactionTypeBiometry(); if (tran != null) { // height item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_BIOMETRY_HEIGHT"); String sHeight = "", sWeight = ""; if (item != null) { sHeight = item.getValue(); par.add(new Chunk(getTran("Web.Occup", "medwan.common.length") + ": " + sHeight + " cm\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } // weight item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_BIOMETRY_WEIGHT"); if (item != null) { sWeight = item.getValue(); par.add(new Chunk(getTran("Web.Occup", "medwan.common.weight") + ": " + sWeight + " kg\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } // BMI if (sWeight.length() > 0 && sHeight.length() > 0) { try { DecimalFormat deci = new DecimalFormat("0.0"); Float bmi = new Float(Float.parseFloat(sWeight.replaceAll(",", ".")) * 10000 / (Float.parseFloat(sHeight.replaceAll(",", ".")) * Float.parseFloat(sHeight.replaceAll(",", ".")))); par.add(new Chunk("BMI: " + deci.format(bmi), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } catch (Exception e) { e.printStackTrace(); } } } cell = new PdfPCell(par); cell.setColspan(3); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 2 : Urineonderzoek par = new Paragraph("URINE\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); tran = sessionContainerWO.getLastTransactionTypeUrineExamination(); if (tran != null) { item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_ALBUMINE"); if (item != null) { par.add(new Chunk("Albumine: " + getTran("Web.Occup", item.getValue()) + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_GLUCOSE"); if (item != null) { par.add(new Chunk("Glucose: " + getTran("Web.Occup", item.getValue()) + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_URINE_BLOOD"); if (item != null) { par.add(new Chunk( getTran("Web.Occup", "medwan.common.blood") + ": " + getTran("Web.Occup", item.getValue()), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } } cell = new PdfPCell(par); cell.setColspan(3); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 2 : Audiometrie par = new Paragraph(getTran("Web.Occup", "medwan.common.audiometry").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); tran = sessionContainerWO.getLastTransactionTypeAudiometry(); if (tran != null) { par.add(new Chunk(getTran("Web.Occup", "medwan.common.mean-hearing-loss").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 6 * fontSizePercentage / 100.0), Font.ITALIC))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_AUDIOMETRY_RIGHT_LOSS"); if (item != null) { par.add(new Chunk( getTran("Web.Occup", "medwan.common.right") + ": -" + item.getValue() + " dB\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_AUDIOMETRY_LEFT_LOSS"); if (item != null) { par.add(new Chunk( getTran("Web.Occup", "medwan.common.left") + ": -" + item.getValue() + " dB\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } } cell = new PdfPCell(par); cell.setColspan(3); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 2 : Visus par = new Paragraph( getTran("Web.Occup", "medwan.common.vision").toUpperCase() + " - " + getTran("Web.Occup", IConstants_PREFIX + "item_type_opthalmology_screen_visiotest_vision_far") .toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); tran = sessionContainerWO.getLastTransactionTypeOphtalmology(); if (tran != null) { par.add(new Chunk(getTran("Web.Occup", "medwan.common.right-left-binocular").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 6 * fontSizePercentage / 100.0), Font.ITALIC))); par.add(new Chunk(getTran("Web.Occup", "medwan.common.without-correction") + ": ", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OD_WITHOUT_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OG_WITHOUT_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_BONI_WITHOUT_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("\n" + getTran("Web.Occup", "medwan.common.with-correction") + ": ", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OD_WITH_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_OG_WITH_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); item = tran.getItem(IConstants_PREFIX + "ITEM_TYPE_OPTHALMOLOGY_VISION_BONI_WITH_GLASSES"); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } } cell = new PdfPCell(par); cell.setColspan(3); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); // row 2 : Bloeddruk par = new Paragraph(getTran("Web.Occup", "medwan.common.blood-pressure").toUpperCase() + "\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.ITALIC)); tran = sessionContainerWO.getLastTransactionTypeGeneralClinicalExamination(); if (tran != null) { // right ItemVO item1 = tran.getItem( IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_SYSTOLIC_PRESSURE_RIGHT"); item = tran.getItem( IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_DIASTOLIC_PRESSURE_RIGHT"); if (item1 != null || item != null) { par.add(new Chunk(getTran("Web.Occup", "medwan.common.right") + ": ", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); if (item1 != null) { par.add(new Chunk(item1.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk(" mmHg\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } // left item = tran.getItem( IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_SYSTOLIC_PRESSURE_LEFT"); item1 = tran.getItem( IConstants_PREFIX + "ITEM_TYPE_CARDIAL_CLINICAL_EXAMINATION_DIASTOLIC_PRESSURE_LEFT"); if (item != null || item1 != null) { par.add(new Chunk(getTran("Web.Occup", "medwan.common.left") + ": ", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); if (item != null) { par.add(new Chunk(item.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk("/", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.NORMAL))); if (item1 != null) { par.add(new Chunk(item1.getValue(), FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } par.add(new Chunk(" mmHg\n", FontFactory.getFont(FontFactory.HELVETICA, Math.round((double) 7 * fontSizePercentage / 100.0), Font.BOLD))); } } cell = new PdfPCell(par); cell.setColspan(3); cell.setBorder(PdfPCell.BOX); cell.setBorderColor(BaseColor.LIGHT_GRAY); cell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER); table.addCell(cell); doc.add(table); } catch (Exception e) { e.printStackTrace(); } }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private Phrase processHtmlCodes(String name, Font baseFont, Font symbol) { final Font italicFont = new Font(baseFont); italicFont.setStyle(Font.FontStyle.ITALIC.getValue()); final Font normalFont = new Font(baseFont); Font usedFont = normalFont;/*from w ww . j a va2 s. c o m*/ final Phrase phrase = new Phrase(); if (!StringUtils.isEmpty(name)) { for (String[] alphabet : GreekAlphabet.getAlphabet()) { name = name.replaceAll(alphabet[0], DELIMETER + alphabet[0] + DELIMETER); } name = name.replaceAll("<sup>|<SUP>", DELIMETER + "<sup>"); name = name.replaceAll("</sup>|</SUP>", DELIMETER); name = name.replaceAll("<i>|<I>|<em>|<EM>", DELIMETER + "<i>"); name = name.replaceAll("</i>|</I>|</em>|</EM>", DELIMETER + "</i>"); final String[] tokens = name.split(DELIMETER); for (String token : tokens) { String text = token; if (text.startsWith("<i>")) { usedFont = italicFont; text = text.substring(3); } else if (text.startsWith("</i>")) { usedFont = normalFont; text = text.substring(4); } usedFont.setSize(baseFont.getSize()); if (text.startsWith("&")) { final char replacement = GreekAlphabet.getReplacement(text); if (!Character.isWhitespace(replacement)) { phrase.add(SpecialSymbol.get(replacement, symbol)); } else { phrase.add(new Chunk(text, usedFont)); } } else if (text.startsWith("<sup>")) { final Font superScriptFont = new Font(usedFont); superScriptFont.setSize(baseFont.getSize() - 1.5f); final Chunk superScript = new Chunk(text.substring(5), superScriptFont); superScript.setTextRise(4f); phrase.add(superScript); } else { phrase.add(new Chunk(text, usedFont)); } } } return phrase; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable buildModelPricingTables(Contact contact, Model model) { final PdfPTable table = new PdfPTable(1); final List<Pricing> validPricings = model.validPricings(contact); if (CollectionUtils.isEmpty(validPricings)) { final Chunk chunk = new Chunk("Contact us for pricing on this model", iTextUtil.getFontContactUs()); chunk.setAction(new PdfAction(contactUsUrl)); table.addCell(cell(new Phrase(chunk))); } else {//from ww w . j a v a2 s. c o m for (Pricing pricing : validPricings) { table.addCell(cell(buildModelPricingTable(pricing))); } } return table; }
From source file:be.roots.taconic.pricingguide.service.PDFServiceImpl.java
License:Open Source License
private PdfPTable createOrderButton(Model model) throws IOException, BadElementException { final Chunk chunk = new Chunk("Order on taconic.com", iTextUtil.getFontButton()); chunk.setAction(//from w w w . j av a 2 s. c o m new PdfAction("http://www.taconic.com/start-an-order?modelNumber=" + model.getModelNumber())); final PdfPCell cell = cell(new Phrase(chunk)); cell.setBackgroundColor(iTextUtil.getTaconicRed()); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); cell.setPaddingTop(5); cell.setPaddingBottom(8); final PdfPTable button = new PdfPTable(new float[] { 80f, 20f }); button.addCell(cell(new Phrase(" "), 2)); button.addCell(cell); button.addCell(cell(new Phrase(" "))); button.addCell(cell(new Phrase(" "), 2)); return button; }