List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(Rectangle rect)
Rectangle
-object. From source file:com.estate.pdf.Page.java
protected Rectangle drawSection(Rectangle rct, String heading, String lines[], int bullet, float headingSize, float textSize) { Rectangle r;//from www.j a v a 2 s . com Rectangle secRect = new Rectangle(rct); PageSection psc = new PageSection(writer); float hs = psc.getHeadingSize(); float ts = psc.getTextSize(); psc.setHeadingSize(headingSize); psc.setTextSize(textSize); r = psc.displaySection(secRect, heading, lines, bullet); psc.setHeadingSize(hs); psc.setTextSize(ts); return r; }
From source file:com.estate.pdf.Page.java
protected Rectangle toPage(float orgX, float orgY, Rectangle orgRect) { Rectangle rct = new Rectangle(orgRect); rct.setLeft(rct.getLeft() + orgX);/*w w w. j a va2 s. c om*/ rct.setRight(rct.getRight() + orgX); rct.setTop(rct.getTop() + orgY); rct.setBottom(rct.getBottom() + orgY); return rct; }
From source file:com.estate.pdf.Page.java
protected Rectangle translateRect(Rectangle rct) { Rectangle rctPage = new Rectangle(document.getPageSize()); rct = new Rectangle(rct.getLeft(), rctPage.getTop() - rct.getBottom(), rct.getRight(), rctPage.getTop() - rct.getTop()); return (rct); }
From source file:com.estate.pdf.PageBorder.java
public void draw(Document doc, int iconNum, String pageNum, String toolName) { try {/* ww w. j a va2s . c om*/ PdfContentByte cb = writer.getDirectContentUnder(); BaseFont fontBold = BaseFont.createFont(Locations.getFontLocation() + "timesbd.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); BaseFont font = BaseFont.createFont(Locations.getFontLocation() + "times.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); Rectangle rct = new Rectangle(doc.getPageSize()); float iconBase = (1.25f * 72); // This is the base of the icons on // the page Image icon = Image.getInstance(Locations.getImageLocation() + icons[iconNum]); // Image box = Image.getInstance(Locations.ImageLocation() + // "blueBOX.png"); icon.scalePercent(23); float scale = .23f; float iconLeft = (icon.getWidth() / 2) * scale; float boxSize = (.1875f * 72); // Adjust the top rct.setTop(rct.getTop() - (.5f * 72)); // Place the Icon icon.setAbsolutePosition((1.25f * 72) - iconLeft, rct.getTop() - iconBase); doc.add(icon); // Set our line color cb.setRGBColorStroke(0, 72, 117); cb.setLineWidth(.75f); // do the bottom line cb.moveTo(1.25f * 72, (.5f * 72)); cb.lineTo(rct.getRight() - (.5f * 72), (.5f * 72)); cb.moveTo(1.25f * 72, (.5f * 72)); cb.lineTo(1.25f * 72, rct.getTop()); // stroke the lines cb.stroke(); // Do the lower left box cb.rectangle((1.25f - 0.09375f) * 72, (.5f - 0.09375f) * 72, boxSize, boxSize); cb.setRGBColorFill(0, 72, 117); cb.closePathFillStroke(); // Do the lower right box Rectangle pnRect = new Rectangle(0, 0); pnRect.setLeft(rct.getRight() - ((.5f + 0.09375f) * 72)); pnRect.setTop((.5f - 0.09375f) * 72); pnRect.setRight(pnRect.getLeft() + boxSize); pnRect.setBottom(pnRect.getTop() - boxSize); // cb.rectangle(rct.getRight() - ((.5f + 0.09375f) * 72), (.5f - // 0.09375f) * 72, (.1875f * 72), (.1875f * 72)); cb.rectangle(pnRect.getLeft(), pnRect.getTop(), boxSize, boxSize); cb.setRGBColorFill(0, 72, 117); cb.closePathFillStroke(); // Now we do the page number if one is supplied. if (pageNum.length() > 0) { float pnHeight = fontBold.getAscentPoint(pageNum, 9) - fontBold.getDescentPoint(pageNum, 9); float pnWidth = fontBold.getWidthPoint(pageNum, 9); float l = pnRect.getLeft() + ((boxSize - pnWidth) / 2); float b = pnRect.getTop() + ((boxSize - pnHeight) / 2); cb.beginText(); cb.setFontAndSize(fontBold, 9); cb.setRGBColorFill(255, 255, 255); cb.setTextMatrix(l, b); cb.showText(pageNum); cb.endText(); } // Display the copyright SimpleDateFormat df = new SimpleDateFormat("yyyy"); char cs = 0x00a9; // Unicode for the copyright symbol String copyRight = com.estate.constants.StringConstants.copyRight + cs + " " + df.format(new Date()); float crWidth; float crLeft; crWidth = font.getWidthPoint(copyRight, 8); cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); crLeft = (doc.getPageSize().getRight() - crWidth) / 2; cb.setTextMatrix(crLeft, .375f * 72); // Place the base of the // copyright at 3/8" up from // the bottom cb.showText(copyRight); cb.endText(); if (toolName.length() > 0) { cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); cb.setTextMatrix((1.25f * 72) + boxSize, .375f * 72); cb.showText(toolName); cb.endText(); } // Fix a licensee at left cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, " Licensee: " + getLicense(), (10.2f * 72), .375f * 72, 0); cb.endText(); } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:com.estate.pdf.PageBorder.java
public void drawNoBorder(Document doc, String pageNum) { try {/*from w w w . j av a 2 s .c om*/ PdfContentByte cb = writer.getDirectContentUnder(); BaseFont fontBold = BaseFont.createFont(Locations.getFontLocation() + "timesbd.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); BaseFont font = BaseFont.createFont(Locations.getFontLocation() + "times.ttf", BaseFont.CP1252, BaseFont.EMBEDDED); Rectangle rct = new Rectangle(doc.getPageSize()); float boxSize = (.1875f * 72); // Adjust the top rct.setTop(rct.getTop() - (.5f * 72)); // Do the lower right box Rectangle pnRect = new Rectangle(0, 0); pnRect.setLeft(rct.getRight() - ((.5f + 0.09375f) * 72)); pnRect.setTop(((.5f - 0.09375f) * 72) - 9); pnRect.setRight(pnRect.getLeft() + boxSize); pnRect.setBottom(pnRect.getTop() - boxSize); cb.rectangle(pnRect.getLeft(), pnRect.getTop(), boxSize, boxSize); cb.setRGBColorFill(0, 72, 117); cb.closePathFillStroke(); // Now we do the page number if one is supplied. if (pageNum.length() > 0) { float pnHeight = fontBold.getAscentPoint(pageNum, 9) - fontBold.getDescentPoint(pageNum, 9) - 4.5f; float pnWidth = fontBold.getWidthPoint(pageNum, 9); float l = pnRect.getLeft() + ((boxSize - pnWidth) / 2); float b = pnRect.getTop() + ((boxSize - pnHeight) / 2) - 4.5f; cb.beginText(); cb.setFontAndSize(fontBold, 9); cb.setRGBColorFill(255, 255, 255); cb.setTextMatrix(l, b); cb.showText(pageNum); cb.endText(); } // Display the copyright SimpleDateFormat df = new SimpleDateFormat("yyyy"); char cs = 0x00a9; // Unicode for the copyright symbol String copyRight = "Advanced Practice Network " + cs + " " + df.format(new Date()); float crWidth; float crLeft; crWidth = font.getWidthPoint(copyRight, 8); cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); crLeft = (doc.getPageSize().getRight() - crWidth) / 2; cb.setTextMatrix(crLeft, .375f * 72); // Place the base of the // copyright at 3/8" up from // the bottom cb.showText(copyRight); cb.endText(); if (license != null) { // Fix a licensee at left cb.beginText(); cb.setFontAndSize(font, 8); cb.setRGBColorFill(0, 0, 0); cb.showTextAligned(PdfContentByte.ALIGN_RIGHT, " Licensee: " + getLicense(), (10.2f * 72), .375f * 72, 0); cb.endText(); } } catch (Exception e) { System.out.println(e.getMessage()); } }
From source file:com.estate.report.Scenario.java
public Rectangle placeHeading() { Rectangle rect = new Rectangle(document.getPageSize()); BaseFont font = PageUtils.LoadFont("GARA.TTF"); rect.setBottom(rect.getTop() - (72 * .6f)); HeadingText ht = new HeadingText(this.writer); rect.setBottom(rect.getBottom() - (72 * .33f)); ht.setColor(57, 57, 57);/* w ww . ja v a 2 s . c o m*/ ht.setCapsColor(98, 98, 98); if (sc1) ht.display(rect, 12f, font, 3f, heading, HeadingText.DHT_CENTER); else ht.display(rect, 12f, font, 3f, heading2, HeadingText.DHT_CENTER); rect.setTop(rect.getBottom() - _1_8TH); rect.setBottom(prctFull.getBottom()); rect.setLeft(_1_2TH); rect.setRight(rect.getLeft() + (11.f * 72)); PageBorder pb = new PageBorder(writer); pb.setLicense(userInfo.getPlannerFirstName() + " " + userInfo.getPlannerLastName()); pb.drawNoBorder(document, Integer.toString(pageNum)); try { Rectangle rct = new Rectangle(document.getPageSize()); float iconBase = (.75f * 72); // This is the base of the icons on // the page Image icon = Image.getInstance(Locations.getImageLocation() + "pawn.png"); // Image box = Image.getInstance(Locations.ImageLocation() + // "blueBOX.png"); icon.scalePercent(23); float scale = .23f; float iconLeft = (icon.getWidth() / 2) * scale; // Adjust the top rct.setTop(rct.getTop()); // Place the Icon icon.setAbsolutePosition((.5f * 72) - iconLeft, rct.getTop() - iconBase); document.add(icon); } catch (Exception e) { System.err.println(e.getMessage()); } drawLifeExp(); return rect; }
From source file:com.estate.report.Scenario.java
public void page1() { float tallest = 0; int colCount = MAX_COLS; CFRow continueRow = null;//www. ja v a2s . c om float baseWidths[] = initWidths(colCount - 1); float widths[] = calcWidths(baseWidths, 11f * 72); drawHeader(userInfo.getClientHeading(), ""); Rectangle agt = placeHeading(); Rectangle rct = new Rectangle(prctFull); rct.setLeft(_1_4TH); rct.setRight(rct.getLeft() + 756); Rectangle r = doRow(leList(), widths, agt, 17); rct.setTop(r.getBottom()); r = doRow(agesList(), widths, rct, 17); rct.setTop(r.getBottom()); r = doRow(fiscalYearList(), widths, rct, 17); rct.setTop(r.getBottom()); tallest = tallest < r.getHeight() ? r.getHeight() : tallest; for (CFRow row : rowList) { boolean flag = false; if (row.getColNumber() == 0 && row.getIndentLevel() == 0) { continueRow = row; } do { flag = false; String pdfRow[] = buildRow(row, colCount); if (row.isNewPage()) { newPage(); drawHeader(userInfo.getClientHeading(), ""); agt = placeHeading(); //rct = new Rectangle(prctFull); rct.setLeft(_1_4TH); rct.setRight(rct.getLeft() + 756); r = doRow(leList(), widths, agt, 17); rct.setTop(r.getBottom()); r = doRow(agesList(), widths, rct, 17); rct.setTop(r.getBottom()); r = doRow(fiscalYearList(), widths, rct, 17); rct.setTop(r.getBottom()); tallest = tallest < r.getHeight() ? r.getHeight() : tallest; if (continueRow != null) { if (!row.equals(continueRow)) { row = continueRow; row.setHeader(row.getHeader() + " (cont.)"); flag = true; } } } r = doRow(pdfRow, widths, rct, colCount - 1); rct.setTop(r.getBottom()); tallest = tallest < r.getHeight() ? r.getHeight() : tallest; } while (flag == true); } }
From source file:com.estate.report.Scenario.java
public Rectangle nextPage(float[] widths) { newPage();//from w w w. j a v a 2s . co m String user = userInfo.getClientHeading(); drawHeader(user, ""); Rectangle agt = placeHeading(); Rectangle rct = new Rectangle(prctFull); rct.setLeft(_1_4TH); rct.setRight(rct.getLeft() + 756); Rectangle r = null; r = doRow(leList(), widths, agt, 17); rct.setTop(r.getBottom()); r = doRow(agesList(), widths, rct, 17); rct.setTop(r.getBottom()); rct.setTop(r.getBottom()); r = doRow(fiscalYearList(), widths, rct, 17); rct.setTop(r.getBottom()); return rct; }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private ByteArrayOutputStream getPdfData(JSONArray colHeader, JSONArray fieldList, JSONArray store, HttpServletRequest request) throws ServiceException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from w w w. ja v a 2s . c o m config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config")); String colHeaderArrStr[] = new String[colHeader.length()]; for (int i = 0; i < colHeader.length(); i++) colHeaderArrStr[i] = colHeader.get(i).toString(); String dataIndexArrStr[] = new String[fieldList.length()]; for (int i = 0; i < fieldList.length(); i++) dataIndexArrStr[i] = fieldList.get(i).toString(); Document document = null; if (config.getBoolean("landscape")) { Rectangle recPage = new Rectangle(PageSize.A4.rotate()); recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16))); document = new Document(recPage, 15, 15, 30, 30); } else { Rectangle recPage = new Rectangle(PageSize.A4); recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16))); document = new Document(recPage, 15, 15, 30, 30); } PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new EndPage()); document.open(); if (config.getBoolean("showLogo")) { getCompanyDetails(request); addComponyLogo(document, request); } // int tC = Integer.parseInt(config.getString("textColor"), 16); // JSONArray myStore=(JSONArray)config.get("store"); addTitleSubtitle(document); com.krawler.utils.json.base.JSONObject colWidth = config.getJSONObject("colWidth"); JSONArray widths = colWidth.getJSONArray("data"); ArrayList arr = new ArrayList(); float[] f = new float[widths.length()]; float totalwid = 0; int counter = 0; if (widths.length() != 0) { for (int i = 0; i < widths.length(); i++) { JSONObject temp = widths.getJSONObject(i); arr.add(temp.getInt("width")); } f[0] = 30; for (int k = 1; k < f.length; k++) { if (!config.getBoolean("landscape") && (Integer) arr.get(k - 1) > 550) { f[k] = 550; } else { f[k] = (Integer) arr.get(k - 1); } } int docwidth; if (config.getBoolean("landscape")) docwidth = 800; else docwidth = 600; while (totalwid < docwidth && counter < f.length) { totalwid += f[counter]; counter++; } if (totalwid > docwidth) { counter--; counter--; } showColumns = counter; } addTable(0, showColumns, 0, store.length(), store, dataIndexArrStr, colHeaderArrStr, document); document.close(); writer.close(); baos.close(); } catch (ConfigurationException ex) { throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex); } catch (DocumentException ex) { throw ServiceException.FAILURE("ExportProjectReport.getPdfData", ex); } catch (JSONException e) { throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e); } catch (IOException e) { throw ServiceException.FAILURE("ExportProjectReport.getPdfData", e); } return baos; }
From source file:com.krawler.esp.servlets.ExportProjectReportServlet.java
License:Open Source License
private ByteArrayOutputStream exportToPdfTimeline(HttpServletRequest request, String as) throws ServiceException { JSONObject s = null;//from www . ja v a2 s . co m ByteArrayOutputStream os = new ByteArrayOutputStream(); try { config = new com.krawler.utils.json.base.JSONObject(request.getParameter("config")); s = new JSONObject(as); JSONArray head = s.getJSONArray("columnheader"); JSONArray store = s.getJSONArray("data"); String[] colwidth2 = new String[head.length() + 3]; String[] colnm = { "info", "level", "flag" }; for (int i = 0; i < colwidth2.length; i++) { if (i < 3) colwidth2[i] = colnm[i]; else { if (head.getJSONObject(i - 3).has("0")) colwidth2[i] = head.getJSONObject(i - 3).getString("0"); else colwidth2[i] = head.getJSONObject(i - 3).getString("1"); } } int maxlevel = 0; for (int k = 0; k < store.length(); k++) { for (int j = 0; j < colwidth2.length; j++) { if (!store.getJSONObject(k).has(colwidth2[j])) store.getJSONObject(k).put(colwidth2[j], ""); } if (store.getJSONObject(k).getInt("level") > maxlevel) maxlevel = store.getJSONObject(k).getInt("level"); } int len = colwidth2.length - 3; int p = 0; if (len <= 5) p = colwidth2.length; else p = 8; Rectangle recPage = new Rectangle(PageSize.A4); recPage.setBackgroundColor(new java.awt.Color(Integer.parseInt(config.getString("bgColor"), 16))); Document document = null; if (config.getBoolean("landscape")) document = new Document(recPage.rotate(), 15, 15, 30, 30); else document = new Document(recPage, 15, 15, 30, 30); PdfWriter writer = PdfWriter.getInstance(document, os); writer.setPageEvent(new EndPage()); document.open(); if (config.getBoolean("showLogo")) { getCompanyDetails(request); addComponyLogo(document, request); } addTitleSubtitle(document); document.add(new Paragraph("\u00a0")); addTableTimeLine(3, p, 0, store.length(), store, colwidth2, maxlevel, document); document.close(); writer.close(); os.close(); } catch (ConfigurationException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (IOException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (DocumentException ex) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", ex); } catch (JSONException e) { throw ServiceException.FAILURE("ExportProjectReport.exportToPdfTimeline", e); } return os; }