List of usage examples for com.lowagie.text Document setMargins
public boolean setMargins(float marginLeft, float marginRight, float marginTop, float marginBottom)
From source file:org.kuali.kfs.module.purap.pdf.PurapPdf.java
License:Open Source License
/** * Creates an instance of a new Document and set its margins according to * the given input parameters.//from w w w . ja v a 2s. co m * * @param f1 Left margin. * @param f2 Right margin. * @param f3 Top margin. * @param f4 Bottom margin. * @return The created Document object. */ public Document getDocument(float f1, float f2, float f3, float f4) { LOG.debug("getDocument() started"); Document document = new Document(PageSize.A4); // Margins: 36pt = 0.5 inch, 72pt = 1 inch. Left, right, top, bottom. document.setMargins(f1, f2, f3, f4); return document; }
From source file:org.kuali.kfs.module.purap.pdf.PurchaseOrderQuoteRequestsPdf.java
License:Open Source License
/** * Creates an instance of a new Document and set its margins. * /*from w w w. j a v a 2 s. c om*/ * @return The created Document object. */ private Document getDocument() throws DocumentException { LOG.debug("getDocument() started"); Document document = new Document(PageSize.A4); // Margins: 36pt = 0.5 inch, 72pt = 1 inch. Left, right, top, bottom. document.setMargins(9, 9, 25, 36); return document; }
From source file:org.kuali.ole.describe.controller.EditorController.java
License:Open Source License
public Document getDocument(float f1, float f2, float f3, float f4) { Document document = new Document(PageSize.A4); document.setMargins(f1, f2, f3, f4); return document; }
From source file:org.mapfish.print.config.layout.Page.java
License:Open Source License
public void render(PJsonObject params, RenderingContext context) throws DocumentException { final Document doc = context.getDocument(); doc.setPageSize(getPageSizeRect(context, params)); doc.setMargins(getMarginLeft(context, params), getMarginRight(context, params), getMarginTop(context, params) + (header != null ? header.getHeight() : 0), getMarginBottom(context, params) + (footer != null ? footer.getHeight() : 0)); context.getCustomBlocks().setBackgroundPdf(PDFUtils.evalString(context, params, backgroundPdf)); if (doc.isOpen()) { doc.newPage();/*from ww w . j a v a 2 s . co m*/ } else { doc.open(); } context.getCustomBlocks().setHeader(header, params); context.getCustomBlocks().setFooter(footer, params); for (int i = 0; i < items.size(); i++) { Block block = items.get(i); if (block.isVisible(context, params)) { block.render(params, new Block.PdfElement() { public void add(Element element) throws DocumentException { doc.add(element); } }, context); } } }
From source file:org.oscarehr.web.reports.ocan.IndividualNeedRatingOverTimeReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open();/*ww w. j a v a 2s .c o m*/ //header Paragraph p = new Paragraph("Individual Need Rating Over Time", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell(makeCell(createFieldNameAndValuePhrase("Consumer Name:", reportBean.getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell( createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(reportBean.getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", reportBean.getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); int height = 260; if (reportBean.isShowUnmetNeeds()) { d.add(Image.getInstance(reportBean.getUnmetNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowMetNeeds()) { d.add(Image.getInstance(reportBean.getMetNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowNoNeeds()) { d.add(Image.getInstance(reportBean.getNoNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } if (reportBean.isShowUnknownNeeds()) { d.add(Image.getInstance(reportBean.getUnknownNeedsChart() .createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, height), null)); } d.close(); }
From source file:org.oscarehr.web.reports.ocan.NeedRatingOverTimeReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open();/*from w w w. ja va2 s .c o m*/ //header Paragraph p = new Paragraph("Needs Over Time (Consumer and Staff)", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "The purpose of this report is to show change over time in a specific Need Rating for an individual Consumer. It adds up the number of needs across all Domains grouped by Need Rating (e.g. Unmet Needs, Met Needs, No Needs, Unknown) for all selected OCANs that were conducted with the Consumer and displays the results in an individual need rating line graph. Each line graph that is displayed compares the Consumer and the Staff's perspective. The staff may share this report with their Consumer as well.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell( makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); //loop here...groups of 3 int loopNo = 1; List<OcanNeedRatingOverTimeSummaryOfNeedsBean> summaryBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>(); summaryBeanList.addAll(this.summaryOfNeedsBeanList); while (true) { if (summaryBeanList.size() == 0) { break; } List<OcanNeedRatingOverTimeSummaryOfNeedsBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeSummaryOfNeedsBean>(); for (int x = 0; x < 3; x++) { if (summaryBeanList.size() == 0) { break; } currentBeanList.add(summaryBeanList.remove(0)); } //summary of needs PdfPTable summaryOfNeedsTable = null; if (currentBeanList.size() == 1) { summaryOfNeedsTable = new PdfPTable(3); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f }); } if (currentBeanList.size() == 2) { summaryOfNeedsTable = new PdfPTable(6); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } if (currentBeanList.size() == 3) { summaryOfNeedsTable = new PdfPTable(9); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable .setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT); summaryOfNeedsTable.setHeaderRows(3); addSummaryOfNeedsHeader(summaryOfNeedsTable, currentBeanList, loopNo); addSummaryOfNeedsRow(summaryOfNeedsTable, "Unmet Needs", "unmet", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "Met Needs", "met", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "No Needs", "no", currentBeanList); addSummaryOfNeedsRow(summaryOfNeedsTable, "Unknown Needs", "unknown", currentBeanList); d.add(summaryOfNeedsTable); d.add(Chunk.NEWLINE); if (summaryBeanList.size() == 0) { break; } loopNo++; } //BREAKDOWN OF SUMMARY OF NEEDS //loop here...groups of 3 loopNo = 1; List<OcanNeedRatingOverTimeNeedBreakdownBean> breakdownBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>(); breakdownBeanList.addAll(this.needBreakdownListByOCAN); OcanNeedRatingOverTimeNeedBreakdownBean lastBreakDownBean = null; while (true) { if (breakdownBeanList.size() == 0) { break; } List<OcanNeedRatingOverTimeNeedBreakdownBean> currentBeanList = new ArrayList<OcanNeedRatingOverTimeNeedBreakdownBean>(); for (int x = 0; x < 3; x++) { if (breakdownBeanList.size() == 0) { break; } currentBeanList.add(breakdownBeanList.remove(0)); } //summary of needs PdfPTable summaryOfNeedsTable = null; if (currentBeanList.size() == 1) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(3); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(4); summaryOfNeedsTable.setWidthPercentage(100f - 52.8f); summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f }); } } if (currentBeanList.size() == 2) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(6); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable.setWidths(new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(7); summaryOfNeedsTable.setWidthPercentage(100f - 26.4f); summaryOfNeedsTable .setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } } if (currentBeanList.size() == 3) { if (lastBreakDownBean == null) { summaryOfNeedsTable = new PdfPTable(9); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable.setWidths( new float[] { 0.26f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } else { summaryOfNeedsTable = new PdfPTable(10); summaryOfNeedsTable.setWidthPercentage(100f); summaryOfNeedsTable.setWidths(new float[] { 0.26f - 0.024f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f, 0.024f, 0.12f, 0.12f }); } } summaryOfNeedsTable.setHorizontalAlignment(Element.ALIGN_LEFT); addSummaryOfNeedsDomainHeader(summaryOfNeedsTable, currentBeanList, loopNo); for (int x = 0; x < domains.size(); x++) { addSummaryOfNeedsDomainRow(summaryOfNeedsTable, x, getDomains(), currentBeanList, lastBreakDownBean); } d.add(summaryOfNeedsTable); d.add(Chunk.NEWLINE); if (breakdownBeanList.size() == 0) { break; } if (currentBeanList.size() == 3) { lastBreakDownBean = currentBeanList.get(2); } loopNo++; } JFreeChart chart = generateNeedsOverTimeChart(); BufferedImage image = chart.createBufferedImage((int) PageSize.A4.rotate().getWidth() - 40, 350); Image image2 = Image.getInstance(image, null); d.add(image2); d.close(); }
From source file:org.oscarehr.web.reports.ocan.SummaryOfActionsAndCommentsReportGenerator.java
License:Open Source License
public void generateReport(OutputStream os) throws Exception { Document d = new Document(PageSize.A4.rotate()); d.setMargins(20, 20, 20, 20); PdfWriter writer = PdfWriter.getInstance(d, os); writer.setStrictImageSequence(true); d.open();/*w w w . j a v a 2 s . c om*/ //header Paragraph p = new Paragraph("Summary of Actions and Comments", titleFont); p.setAlignment(Element.ALIGN_CENTER); d.add(p); d.add(Chunk.NEWLINE); //purpose Paragraph purpose = new Paragraph(); purpose.add(new Chunk("Purpose of Report:", boldText)); purpose.add(new Phrase( "This report displays a summary of Actions and Comments (both for the Consumer and the Staff) that were recorded in the selected OCANs for an individual Consumer. The report lists all the Actions and Comments associated to OCANs and Domains that were chosen by the Staff to be displayed. The Actions also list who is responsible for the Action and the Review Date for the Action. The Domains are categorized by need rating within within the current OCAN as well as displaying the need ratings from the previous OCANs. In the case of different need ratings by the Consumer and the Mental Health Worker, the higher need rating determines the category. The need ratings from highest to lowest are Unmet Needs, Met Needs, No Needs, and Unknown. The need rating given by the Consumer and the Staff are also displayed next to the Comments for each OCAN. This information can be passed along to other organizations if requested.", normalText)); d.add(purpose); d.add(Chunk.NEWLINE); //report parameters PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); table.getDefaultCell().setBorder(0); table.addCell( makeCell(createFieldNameAndValuePhrase("Consumer Name:", getConsumerName()), Element.ALIGN_LEFT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Report Date:", dateFormatter.format(getReportDate())), Element.ALIGN_RIGHT)); table.addCell(makeCell(createFieldNameAndValuePhrase("Staff Name:", getStaffName()), Element.ALIGN_LEFT)); table.addCell(""); d.add(table); d.add(Chunk.NEWLINE); if (reportBean == null) { d.close(); return; } List<SummaryOfActionsAndCommentsDomainBean> unMetCategory = reportBean.getUnmetNeeds(); List<SummaryOfActionsAndCommentsDomainBean> metCategory = reportBean.getMetNeeds(); List<SummaryOfActionsAndCommentsDomainBean> noCategory = reportBean.getNoNeeds(); List<SummaryOfActionsAndCommentsDomainBean> unknownCategory = reportBean.getUnknown(); PdfPTable unmetTable = null; if (unMetCategory.size() > 0) { unmetTable = createNeedHeader("Unmet Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : unMetCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(unmetTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(unmetTable, ocanBean); } } } if (unmetTable != null) { d.add(unmetTable); d.add(Chunk.NEWLINE); } PdfPTable metTable = null; if (metCategory.size() > 0) { metTable = createNeedHeader("Met Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : metCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(metTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(metTable, ocanBean); } } } if (metTable != null) { d.add(metTable); d.add(Chunk.NEWLINE); } PdfPTable noTable = null; if (noCategory.size() > 0) { noTable = createNeedHeader("No Needs"); } for (SummaryOfActionsAndCommentsDomainBean domain : noCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(noTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(noTable, ocanBean); } } } if (noTable != null) { d.add(noTable); d.add(Chunk.NEWLINE); } PdfPTable unknownTable = null; if (unknownCategory.size() > 0) { unknownTable = createNeedHeader("Unknown"); } for (SummaryOfActionsAndCommentsDomainBean domain : unknownCategory) { if (domain.getOcanBeans().size() > 0) { createDomainHeader(unknownTable, domain.getDomainName()); for (SummaryOfActionsAndCommentsOCANBean ocanBean : domain.getOcanBeans()) { createOcanEntry(unknownTable, ocanBean); } } } if (unknownTable != null) { d.add(unknownTable); } d.close(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfDocumentWriter.java
License:Open Source License
public void processPhysicalPage(final PageGrid pageGrid, final LogicalPageBox logicalPage, final int row, final int col, final PhysicalPageKey pageKey) throws DocumentException { final PhysicalPageBox page = pageGrid.getPage(row, col); if (page == null) { return;/*from www .j a va2 s . co m*/ } final float width = (float) StrictGeomUtility.toExternalValue(page.getWidth()); final float height = (float) StrictGeomUtility.toExternalValue(page.getHeight()); final Rectangle pageSize = new Rectangle(width, height); final float marginLeft = (float) StrictGeomUtility.toExternalValue(page.getImageableX()); final float marginRight = (float) StrictGeomUtility .toExternalValue(page.getWidth() - page.getImageableWidth() - page.getImageableX()); final float marginTop = (float) StrictGeomUtility.toExternalValue(page.getImageableY()); final float marginBottom = (float) StrictGeomUtility .toExternalValue(page.getHeight() - page.getImageableHeight() - page.getImageableY()); final Document document = getDocument(); document.setPageSize(pageSize); document.setMargins(marginLeft, marginRight, marginTop, marginBottom); if (awaitOpenDocument) { document.open(); awaitOpenDocument = false; } final PdfContentByte directContent = writer.getDirectContent(); final Graphics2D graphics = new PdfGraphics2D(directContent, width, height, metaData); final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable(logicalPage, page); final PhysicalPageDrawable drawable = createPhysicalPageDrawable(logicalPageDrawable, page); drawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); graphics.dispose(); document.newPage(); }
From source file:org.pentaho.reporting.engine.classic.core.modules.output.pageable.pdf.internal.PdfDocumentWriter.java
License:Open Source License
public void processLogicalPage(final LogicalPageKey key, final LogicalPageBox logicalPage) throws DocumentException { final float width = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageWidth()); final float height = (float) StrictGeomUtility.toExternalValue(logicalPage.getPageHeight()); final Rectangle pageSize = new Rectangle(width, height); final Document document = getDocument(); document.setPageSize(pageSize);//from w w w. j ava2 s . c o m document.setMargins(0, 0, 0, 0); if (awaitOpenDocument) { document.open(); awaitOpenDocument = false; } final Graphics2D graphics = new PdfGraphics2D(writer.getDirectContent(), width, height, metaData); // and now process the box .. final PdfLogicalPageDrawable logicalPageDrawable = createLogicalPageDrawable(logicalPage, null); logicalPageDrawable.draw(graphics, new Rectangle2D.Double(0, 0, width, height)); graphics.dispose(); document.newPage(); }
From source file:org.unitime.timetable.export.solver.ExportTimetablePDF.java
License:Apache License
protected void printTables(FilterInterface filter, TimetableGridResponse response, ExportHelper helper) throws IOException { helper.setup("application/pdf", reference(), true); try {// w ww . jav a2 s . c om Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, helper.getOutputStream()); writer.setPageEvent(new PdfEventHandler()); int index = 0; int margin = 50; int width = 1000; for (TimetableGridModel model : response.getModels()) width = Math.max(width, pageWidth(filter, model, response.getWeekOffset())); int displayMode = Integer.valueOf(filter.getParameterValue("dispMode", "0")); int height = (displayMode == 2 ? (2 * margin + width) * 22 / 17 - 2 * margin : (2 * margin + width) * 17 / 22 - 2 * margin); for (TimetableGridModel model : response.getModels()) height = Math.max(height, pageHeight(filter, model, response.getWeekOffset(), true)); document.setPageSize(new Rectangle(width + 2 * margin, height + 2 * margin)); document.setMargins(margin, margin, margin, margin); document.open(); int used = 0; if (Integer.valueOf(filter.getParameterValue("dispMode", "0")) == 0) { boolean hasDay[] = { true, true, true, true, true, false, false }; String days = filter.getParameterValue("days"); if (days != null && days.length() == 7 && days.indexOf('1') >= 0) { for (int i = 0; i < 7; i++) hasDay[i] = (days.charAt(i) == '1'); } for (int i = 0; i < 7; i++) { if (!hasDay[i]) continue; String d = ""; for (int j = 0; j < 7; j++) d += (i == j ? "1" : "0"); filter.getParameter("days").setValue(d); boolean first = true; for (TimetableGridModel model : response.getModels()) { if (used > 0 && pageHeight(filter, model, response.getWeekOffset(), first) > height - used) { document.newPage(); used = 0; } TimetableGrid tg = new TimetableGrid(filter, model, index++, width, response.getWeekOffset(), used == 0 || first); PdfContentByte canvas = writer.getDirectContent(); tg.print(canvas, margin, margin + used, height + 2 * margin, null); used += tg.getHeight(); first = false; } used += 25; } } else { for (TimetableGridModel model : response.getModels()) { if (used > 0 && pageHeight(filter, model, response.getWeekOffset(), false) > height - used) { document.newPage(); used = 0; } TimetableGrid tg = new TimetableGrid(filter, model, index++, width, response.getWeekOffset(), used == 0); PdfContentByte canvas = writer.getDirectContent(); tg.print(canvas, margin, margin + used, height + 2 * margin, null); used += tg.getHeight() + 25; } } if (document != null) document.close(); } catch (DocumentException e) { throw new IOException(e.getMessage(), e); } }