List of usage examples for com.lowagie.text Document newPage
public boolean newPage()
From source file:org.jivesoftware.openfire.reporting.graph.GraphServlet.java
License:Open Source License
private void writePDFContent(HttpServletRequest request, HttpServletResponse response, JFreeChart charts[], Statistic[] stats, long starttime, long endtime, int width, int height) throws IOException { try {//w ww .ja va 2s .c o m Document document = new Document(PageSize.A4, 50, 50, 50, 50); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new PDFEventListener(request)); document.open(); int index = 0; int chapIndex = 0; for (Statistic stat : stats) { String serverName = XMPPServer.getInstance().getServerInfo().getXMPPDomain(); String dateName = JiveGlobals.formatDate(new Date(starttime)) + " - " + JiveGlobals.formatDate(new Date(endtime)); Paragraph paragraph = new Paragraph(serverName, FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD)); document.add(paragraph); paragraph = new Paragraph(dateName, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.PLAIN)); document.add(paragraph); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); Paragraph chapterTitle = new Paragraph(++chapIndex + ". " + stat.getName(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD)); document.add(chapterTitle); // total hack: no idea what tags people are going to use in the description // possibly recommend that we only use a <p> tag? String[] paragraphs = stat.getDescription().split("<p>"); for (String s : paragraphs) { Paragraph p = new Paragraph(s); document.add(p); } document.add(Chunk.NEWLINE); PdfContentByte contentByte = writer.getDirectContent(); PdfTemplate template = contentByte.createTemplate(width, height); Graphics2D graphs2D = template.createGraphics(width, height, new DefaultFontMapper()); Rectangle2D rectangle2D = new Rectangle2D.Double(0, 0, width, height); charts[index++].draw(graphs2D, rectangle2D); graphs2D.dispose(); float x = (document.getPageSize().width() / 2) - (width / 2); contentByte.addTemplate(template, x, writer.getVerticalPosition(true) - height); document.newPage(); } document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the contentlength is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (DocumentException e) { Log.error("error creating PDF document: " + e.getMessage()); } }
From source file:org.jpedal.examples.simpleviewer.utils.ItextFunctions.java
License:Open Source License
public void nup(int pageCount, PdfPageData currentPageData, ExtractPDFPagesNup extractPage) { try {/*w ww . j av a2 s . c om*/ int[] pgsToEdit = extractPage.getPages(); if (pgsToEdit == null) return; //get user choice final String output_dir = extractPage.getRootDir() + separator + fileName + separator + "PDFs" + separator; File testDirExists = new File(output_dir); if (!testDirExists.exists()) testDirExists.mkdirs(); List pagesToEdit = new ArrayList(); for (int i = 0; i < pgsToEdit.length; i++) pagesToEdit.add(new Integer(pgsToEdit[i])); PdfReader reader = new PdfReader(selectedFile); File fileToSave = new File(output_dir + "export_" + fileName + ".pdf"); if (fileToSave.exists()) { int n = currentGUI.showOverwriteDialog(fileToSave.getAbsolutePath(), false); if (n == 0) { // clicked yes so just carry on } else { // clicked no, so exit return; } } int rows = extractPage.getLayoutRows(); int coloumns = extractPage.getLayoutColumns(); int paperWidth = extractPage.getPaperWidth(); int paperHeight = extractPage.getPaperHeight(); Rectangle pageSize = new Rectangle(paperWidth, paperHeight); String orientation = extractPage.getPaperOrientation(); Rectangle newSize = null; if (orientation.equals(Messages.getMessage("PdfViewerNUPOption.Auto"))) { if (coloumns > rows) newSize = new Rectangle(pageSize.height(), pageSize.width()); else newSize = new Rectangle(pageSize.width(), pageSize.height()); } else if (orientation.equals("Portrait")) { newSize = new Rectangle(pageSize.width(), pageSize.height()); } else if (orientation.equals("Landscape")) { newSize = new Rectangle(pageSize.height(), pageSize.width()); } String scale = extractPage.getScale(); float leftRightMargin = extractPage.getLeftRightMargin(); float topBottomMargin = extractPage.getTopBottomMargin(); float horizontalSpacing = extractPage.getHorizontalSpacing(); float verticalSpacing = extractPage.getVerticalSpacing(); Rectangle unitSize = null; if (scale.equals("Auto")) { float totalHorizontalSpacing = (coloumns - 1) * horizontalSpacing; int totalWidth = (int) (newSize.width() - leftRightMargin * 2 - totalHorizontalSpacing); int unitWidth = totalWidth / coloumns; float totalVerticalSpacing = (rows - 1) * verticalSpacing; int totalHeight = (int) (newSize.height() - topBottomMargin * 2 - totalVerticalSpacing); int unitHeight = totalHeight / rows; unitSize = new Rectangle(unitWidth, unitHeight); } else if (scale.equals("Use Original Size")) { unitSize = null; } else if (scale.equals("Specified")) { unitSize = new Rectangle(extractPage.getScaleWidth(), extractPage.getScaleHeight()); } int order = extractPage.getPageOrdering(); int pagesPerPage = rows * coloumns; int repeats = 1; if (extractPage.getRepeat() == REPEAT_AUTO) repeats = coloumns * rows; else if (extractPage.getRepeat() == REPEAT_SPECIFIED) repeats = extractPage.getCopies(); Document document = new Document(newSize, 0, 0, 0, 0); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(fileToSave)); document.open(); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage importedPage; float offsetX = 0, offsetY = 0, factor; int actualPage = 0, page = 0; Rectangle currentSize; boolean isProportional = extractPage.isScaleProportional(); for (int i = 1; i <= pageCount; i++) { if (pagesToEdit.contains(new Integer(i))) { for (int j = 0; j < repeats; j++) { int currentUnit = page % pagesPerPage; if (currentUnit == 0) { document.newPage(); actualPage++; } currentSize = reader.getPageSizeWithRotation(i); if (unitSize == null) unitSize = currentSize; int currentColoumn = 0, currentRow = 0; if (order == ORDER_DOWN) { currentColoumn = currentUnit / rows; currentRow = currentUnit % rows; offsetX = unitSize.width() * currentColoumn; offsetY = newSize.height() - (unitSize.height() * (currentRow + 1)); } else if (order == ORDER_ACCROS) { currentColoumn = currentUnit % coloumns; currentRow = currentUnit / coloumns; offsetX = unitSize.width() * currentColoumn; offsetY = newSize.height() - (unitSize.height() * ((currentUnit / coloumns) + 1)); } factor = Math.min(unitSize.width() / currentSize.width(), unitSize.height() / currentSize.height()); float widthFactor = factor, heightFactor = factor; if (!isProportional) { widthFactor = unitSize.width() / currentSize.width(); heightFactor = unitSize.height() / currentSize.height(); } else { offsetX += ((unitSize.width() - (currentSize.width() * factor)) / 2f); offsetY += ((unitSize.height() - (currentSize.height() * factor)) / 2f); } offsetX += (horizontalSpacing * currentColoumn) + leftRightMargin; offsetY -= ((verticalSpacing * currentRow) + topBottomMargin); importedPage = writer.getImportedPage(reader, i); double rotation = currentSize.getRotation() * Math.PI / 180; /** * see * http://itextdocs.lowagie.com/tutorial/directcontent/coordinates/index.html * for information about transformation matrices, and the coordinate system */ int mediaBoxX = -currentPageData.getMediaBoxX(i); int mediaBoxY = -currentPageData.getMediaBoxY(i); float a, b, c, d, e, f; switch (currentSize.getRotation()) { case 0: a = widthFactor; b = 0; c = 0; d = heightFactor; e = offsetX + (mediaBoxX * widthFactor); f = offsetY + (mediaBoxY * heightFactor); cb.addTemplate(importedPage, a, b, c, d, e, f); break; case 90: a = 0; b = (float) (Math.sin(rotation) * -heightFactor); c = (float) (Math.sin(rotation) * widthFactor); d = 0; e = offsetX + (mediaBoxY * widthFactor); f = ((currentSize.height() * heightFactor) + offsetY) - (mediaBoxX * heightFactor); cb.addTemplate(importedPage, a, b, c, d, e, f); break; case 180: a = (float) (Math.cos(rotation) * widthFactor); b = 0; c = 0; d = (float) (Math.cos(rotation) * heightFactor); e = (offsetX + (currentSize.width() * widthFactor)) - (mediaBoxX * widthFactor); f = ((currentSize.height() * heightFactor) + offsetY) - (mediaBoxY * heightFactor); cb.addTemplate(importedPage, a, b, c, d, e, f); break; case 270: a = 0; b = (float) (Math.sin(rotation) * -heightFactor); c = (float) (Math.sin(rotation) * widthFactor); d = 0; e = (offsetX + (currentSize.width() * widthFactor)) - (mediaBoxY * widthFactor); f = offsetY + (mediaBoxX * heightFactor); cb.addTemplate(importedPage, a, b, c, d, e, f); break; } page++; } } } document.close(); currentGUI.showMessageDialog( Messages.getMessage("PdfViewerMessage.PagesSavedAsPdfTo") + " " + output_dir); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jpedal.examples.simpleviewer.utils.ItextFunctions.java
License:Open Source License
public void handouts(String file) { try {/*from w w w . java 2s. co m*/ File src = new File(selectedFile); File dest = new File(file); int pages = 4; float x1 = 30f; float x2 = 280f; float x3 = 320f; float x4 = 565f; float[] y1 = new float[pages]; float[] y2 = new float[pages]; float height = (778f - (20f * (pages - 1))) / pages; y1[0] = 812f; y2[0] = 812f - height; for (int i = 1; i < pages; i++) { y1[i] = y2[i - 1] - 20f; y2[i] = y1[i] - height; } // we create a reader for a certain document PdfReader reader = new PdfReader(src.getAbsolutePath()); // we retrieve the total number of pages int n = reader.getNumberOfPages(); // step 1: creation of a document-object Document document = new Document(PageSize.A4); // step 2: we create a writer that listens to the document PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); // step 3: we open the document document.open(); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage page; int rotation; int i = 0; int p = 0; // step 4: we add content while (i < n) { i++; Rectangle rect = reader.getPageSizeWithRotation(i); float factorx = (x2 - x1) / rect.width(); float factory = (y1[p] - y2[p]) / rect.height(); float factor = (factorx < factory ? factorx : factory); float dx = (factorx == factor ? 0f : ((x2 - x1) - rect.width() * factor) / 2f); float dy = (factory == factor ? 0f : ((y1[p] - y2[p]) - rect.height() * factor) / 2f); page = writer.getImportedPage(reader, i); rotation = reader.getPageRotation(i); if (rotation == 90 || rotation == 270) { cb.addTemplate(page, 0, -factor, factor, 0, x1 + dx, y2[p] + dy + rect.height() * factor); } else { cb.addTemplate(page, factor, 0, 0, factor, x1 + dx, y2[p] + dy); } cb.setRGBColorStroke(0xC0, 0xC0, 0xC0); cb.rectangle(x3 - 5f, y2[p] - 5f, x4 - x3 + 10f, y1[p] - y2[p] + 10f); for (float l = y1[p] - 19; l > y2[p]; l -= 16) { cb.moveTo(x3, l); cb.lineTo(x4, l); } cb.rectangle(x1 + dx, y2[p] + dy, rect.width() * factor, rect.height() * factor); cb.stroke(); p++; if (p == pages) { p = 0; document.newPage(); } } // step 5: we close the document document.close(); } catch (Exception e) { System.err.println(e.getMessage()); } }
From source file:org.kuali.coeus.common.committee.impl.web.struts.action.CommitteeActionsActionBase.java
License:Open Source License
/** * This method merged the pdf bytes without creating page numbers and dates. * //from w ww . j a va 2 s . com * (This is a slimed down version of MergePdfBytes() in PrintingServiceImpl.java) * * @param pdfBytesList * List containing the PDF data bytes * @param bookmarksList * List of bookmarks corresponding to the PDF bytes. * @return * @throws PrintingException */ private byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList) throws PrintingException { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); for (int count = 0; count < pdfBytesList.size(); count++) { PdfReader reader; try { reader = new PdfReader(pdfBytesList.get(count)); } catch (IOException e) { LOG.error(e.getMessage(), e); break; // throw new PrintingException(e.getMessage(), e); } int nop; if (reader == null) { LOG.debug("Empty PDF bytes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new com.lowagie.text.Document(reader.getPageSizeWithRotation(1)) : new com.lowagie.text.Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new PrintingException(e.getMessage(), e); } document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { document.close(); return mergedPdfReport.toByteArray(); } return null; }
From source file:org.kuali.coeus.common.impl.print.PrintingServiceImpl.java
License:Open Source License
/** * @param pdfBytesList List containing the PDF data bytes * @param bookmarksList List of bookmarks corresponding to the PDF bytes. * @return//w w w .j a v a 2s .co m * @throws PrintingException */ protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList, boolean headerFooterRequired) throws PrintingException { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); int totalNumOfPages = 0; PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()]; int pdfReaderCount = 0; for (byte[] fileBytes : pdfBytesList) { LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount)); PdfReader reader = null; try { reader = new PdfReader(fileBytes); pdfReaderArr[pdfReaderCount] = reader; pdfReaderCount = pdfReaderCount + 1; totalNumOfPages += reader.getNumberOfPages(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } HeaderFooter footer = null; if (headerFooterRequired) { Calendar calendar = dateTimeService.getCurrentCalendar(); String dateString = formateCalendar(calendar); StringBuilder footerPhStr = new StringBuilder(); footerPhStr.append(" of "); footerPhStr.append(totalNumOfPages); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60)); footerPhStr.append(dateString); Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK); Phrase beforePhrase = new Phrase("Page ", font); Phrase afterPhrase = new Phrase(footerPhStr.toString(), font); footer = new HeaderFooter(beforePhrase, afterPhrase); footer.setAlignment(Element.ALIGN_BASELINE); footer.setBorderWidth(0f); } for (int count = 0; count < pdfReaderArr.length; count++) { PdfReader reader = pdfReaderArr[count]; int nop; if (reader == null) { LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new com.lowagie.text.Document(reader.getPageSizeWithRotation(1)) : new com.lowagie.text.Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new PrintingException(e.getMessage(), e); } if (footer != null) { document.setFooter(footer); } // writer.setPageEvent(new Watermark()); // add watermark object here document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); if (footer != null) { document.setFooter(footer); } PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { try { document.close(); return mergedPdfReport.toByteArray(); } catch (Exception e) { LOG.error("Exception occured because the generated PDF document has no pages", e); } } return null; }
From source file:org.kuali.coeus.common.impl.print.watermark.WatermarkServiceImpl.java
License:Open Source License
/** * This method is for setting the page properties of the document. *//*from w ww.ja va 2s . com*/ private void watermarkPageDocument(Document document, PdfWriter writer, PdfReader reader) { document.open(); int totalPages; totalPages = reader.getNumberOfPages(); for (int pageCount = 1; pageCount <= totalPages; pageCount++) { PdfContentByte contents = writer.getDirectContent(); document.setPageSize(reader.getPageSize(pageCount)); document.newPage(); PdfImportedPage page = writer.getImportedPage(reader, pageCount); contents.addTemplate(page, 1, 0, 0, 1, 0, 0); } document.close(); }
From source file:org.kuali.coeus.s2sgen.impl.print.S2SPrintingServiceImpl.java
License:Educational Community License
/** * @param pdfBytesList List containing the PDF data bytes * @param bookmarksList List of bookmarks corresponding to the PDF bytes. */// w ww . j av a 2s . com protected byte[] mergePdfBytes(List<byte[]> pdfBytesList, List<String> bookmarksList, boolean headerFooterRequired) { Document document = null; PdfWriter writer = null; ByteArrayOutputStream mergedPdfReport = new ByteArrayOutputStream(); int totalNumOfPages = 0; PdfReader[] pdfReaderArr = new PdfReader[pdfBytesList.size()]; int pdfReaderCount = 0; for (byte[] fileBytes : pdfBytesList) { LOG.debug("File Size " + fileBytes.length + " For " + bookmarksList.get(pdfReaderCount)); PdfReader reader = null; try { reader = new PdfReader(fileBytes); pdfReaderArr[pdfReaderCount] = reader; pdfReaderCount = pdfReaderCount + 1; totalNumOfPages += reader.getNumberOfPages(); } catch (IOException e) { LOG.error(e.getMessage(), e); } } HeaderFooter footer = null; if (headerFooterRequired) { Calendar calendar = Calendar.getInstance(); String dateString = formateCalendar(calendar); StringBuilder footerPhStr = new StringBuilder(); footerPhStr.append(" of "); footerPhStr.append(totalNumOfPages); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_76)); footerPhStr.append(getWhitespaceString(WHITESPACE_LENGTH_60)); footerPhStr.append(dateString); Font font = FontFactory.getFont(FontFactory.TIMES, 8, Font.NORMAL, Color.BLACK); Phrase beforePhrase = new Phrase("Page ", font); Phrase afterPhrase = new Phrase(footerPhStr.toString(), font); footer = new HeaderFooter(beforePhrase, afterPhrase); footer.setAlignment(Element.ALIGN_BASELINE); footer.setBorderWidth(0f); } for (int count = 0; count < pdfReaderArr.length; count++) { PdfReader reader = pdfReaderArr[count]; int nop; if (reader == null) { LOG.debug("Empty PDF byetes found for " + bookmarksList.get(count)); continue; } else { nop = reader.getNumberOfPages(); } if (count == 0) { document = nop > 0 ? new Document(reader.getPageSizeWithRotation(1)) : new Document(); try { writer = PdfWriter.getInstance(document, mergedPdfReport); } catch (DocumentException e) { LOG.error(e.getMessage(), e); throw new S2SException(e.getMessage(), e); } if (footer != null) { document.setFooter(footer); } document.open(); } PdfContentByte cb = writer.getDirectContent(); int pageCount = 0; while (pageCount < nop) { document.setPageSize(reader.getPageSize(++pageCount)); document.newPage(); if (footer != null) { document.setFooter(footer); } PdfImportedPage page = writer.getImportedPage(reader, pageCount); cb.addTemplate(page, 1, 0, 0, 1, 0, 0); PdfOutline root = cb.getRootOutline(); if (pageCount == 1) { String pageName = bookmarksList.get(count); cb.addOutline(new PdfOutline(root, new PdfDestination(PdfDestination.FITH), pageName), pageName); } } } if (document != null) { try { document.close(); return mergedPdfReport.toByteArray(); } catch (Exception e) { LOG.error("Exception occured because the generated PDF document has no pages", e); } } return null; }
From source file:org.kuali.kfs.fp.document.service.impl.CashReceiptCoverSheetServiceImpl.java
License:Open Source License
/** * Responsible for creating a new PDF page and workspace through <code>{@link PdfContentByte}</code> for direct writing to the * PDF./*from w w w. j a va 2 s. c o m*/ * * @param writer The PDF writer used to write to the new page with. * @param reader The PDF reader used to read information from the PDF file. * @param pageNumber The current number of pages in the PDF file, which will be incremented by one inside this method. * * @return The PDFContentByte used to access the new PDF page. * @exception DocumentException * @exception IOException */ protected PdfContentByte startNewPage(PdfWriter writer, PdfReader reader, ModifiableInteger pageNumber) throws DocumentException, IOException { PdfContentByte retval; PdfContentByte under; Rectangle pageSize; Document pdfDoc; PdfImportedPage newPage; pageNumber.increment(); pageSize = reader.getPageSize(FRONT_PAGE); retval = writer.getDirectContent(); // under = writer.getDirectContentUnder(); if (pageNumber.getInt() > FRONT_PAGE) { newPage = writer.getImportedPage(reader, CHECK_PAGE_NORMAL); setCurrentRenderingYPosition(pageSize.top(TOP_MARGIN + CHECK_DETAIL_HEADING_HEIGHT)); } else { newPage = writer.getImportedPage(reader, FRONT_PAGE); setCurrentRenderingYPosition(pageSize.top(TOP_FIRST_PAGE)); } pdfDoc = retval.getPdfDocument(); pdfDoc.newPage(); retval.addTemplate(newPage, 0, 0); retval.setFontAndSize(getTextFont(), 8); return retval; }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * Generates the pdf file for printing the envelopes. * * @param list// w ww . j a v a 2 s . c o m * @param outputStream * @throws DocumentException * @throws IOException */ protected void generateCombinedPdfForEnvelopes(Collection<ContractsGrantsInvoiceDocument> list, OutputStream outputStream) throws DocumentException, IOException { Document document = new Document( new Rectangle(ArConstants.InvoiceEnvelopePdf.LENGTH, ArConstants.InvoiceEnvelopePdf.WIDTH)); PdfWriter.getInstance(document, outputStream); boolean pageAdded = false; for (ContractsGrantsInvoiceDocument invoice : list) { // add a document for (InvoiceAddressDetail invoiceAddressDetail : invoice.getInvoiceAddressDetails()) { if (ArConstants.InvoiceTransmissionMethod.MAIL .equals(invoiceAddressDetail.getInvoiceTransmissionMethodCode())) { CustomerAddress address = invoiceAddressDetail.getCustomerAddress(); Integer numberOfEnvelopesToPrint = address.getCustomerEnvelopesToPrintQuantity(); if (ObjectUtils.isNull(numberOfEnvelopesToPrint)) { numberOfEnvelopesToPrint = 1; } for (int i = 0; i < numberOfEnvelopesToPrint; i++) { // if a page has not already been added then open the document. if (!pageAdded) { document.open(); } pageAdded = true; document.newPage(); // adding the sent From address Organization org = invoice.getInvoiceGeneralDetail().getAward() .getPrimaryAwardOrganization().getOrganization(); Paragraph sentBy = generateAddressParagraph(org.getOrganizationName(), org.getOrganizationLine1Address(), org.getOrganizationLine2Address(), org.getOrganizationCityName(), org.getOrganizationStateCode(), org.getOrganizationZipCode(), ArConstants.PdfReportFonts.ENVELOPE_SMALL_FONT); sentBy.setIndentationLeft(ArConstants.InvoiceEnvelopePdf.INDENTATION_LEFT); sentBy.setAlignment(Element.ALIGN_LEFT); // adding the send To address String string; Paragraph sendTo = generateAddressParagraph(address.getCustomerAddressName(), address.getCustomerLine1StreetAddress(), address.getCustomerLine2StreetAddress(), address.getCustomerCityName(), address.getCustomerStateCode(), address.getCustomerZipCode(), ArConstants.PdfReportFonts.ENVELOPE_TITLE_FONT); sendTo.setAlignment(Element.ALIGN_CENTER); sendTo.add(new Paragraph(KFSConstants.BLANK_SPACE)); document.add(sentBy); document.add(sendTo); } } } } if (pageAdded) { document.close(); } }
From source file:org.kuali.kfs.module.endow.report.util.AssetStatementReportPrint.java
License:Educational Community License
/** * Sets the page break//from ww w . j a v a2 s. c o m * * @param document */ protected void setNewPage(Document document) { try { document.newPage(); } catch (Exception e) { LOG.error("New Page Error: " + e.getMessage()); return; } }