List of usage examples for com.lowagie.text Rectangle Rectangle
public Rectangle(float urx, float ury)
Rectangle
-object starting from the origin (0, 0). From source file:org.heinz.eda.schem.SchemApplication.java
private void exportSheet(final Document document) { Exporter exporter = new Exporter() { @Override//from www . j a v a 2s. co m @SuppressWarnings("CallToPrintStackTrace") public void export(ExportFormat exportFormat, File outputFile) { SchemTabbook schemTabbook = (SchemTabbook) document.getDocumentPane(); Sheet sheet = schemTabbook.getCurrentEditor().getSheet(); if (exportFormat instanceof SchemExportFormat) { SchemExportFormat sef = (SchemExportFormat) exportFormat; try { sef.exportSheet(sheet, outputFile); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException(e.getMessage()); } return; } SheetSize ss = sheet.getSize(); Rectangle size = new Rectangle((float) ss.width / ITEXT_UNIT, (float) ss.height / ITEXT_UNIT); ExportHelper.exportSimpleImageDocument(SchemConstants.PROGRAM_DESCRIPTION, outputFile, exportFormat, sheet.getImage(), size); } @Override public ExportFormat[] getSupportedFormats() { return SchemExportFormat.getDefaultSheetExportFormats(); } }; export(document, exporter, SchemOptions.PROPERTY_LAST_SHEET_EXPORT_EXTENSION); }
From source file:org.heinz.eda.schem.SchemApplication.java
private void exportSchematics(final Document document) { Exporter exporter = new Exporter() { @Override/*ww w . j av a 2s.com*/ @SuppressWarnings("CallToPrintStackTrace") public void export(ExportFormat exportFormat, File outputFile) { SchemTabbook schemTabbook = (SchemTabbook) document.getDocumentPane(); if (exportFormat instanceof SchemExportFormat) { SchemExportFormat sef = (SchemExportFormat) exportFormat; try { sef.exportSchematic(schemTabbook.getSchematics(), outputFile); } catch (IOException e) { e.printStackTrace(); throw new IllegalArgumentException(e.getMessage()); } return; } Sheet sheet = schemTabbook.getCurrentEditor().getSheet(); SheetSize ss = sheet.getSize(); Rectangle size = new Rectangle((float) ss.width / ITEXT_UNIT, (float) ss.height / ITEXT_UNIT); ExportHelper.exportMultiImageDocument(SchemConstants.PROGRAM_DESCRIPTION, outputFile, exportFormat, schemTabbook, size); } @Override public ExportFormat[] getSupportedFormats() { return SchemExportFormat.getDefaultSchematicsExportFormats(); } }; export(document, exporter, SchemOptions.PROPERTY_LAST_SCHEMATICS_EXPORT_EXTENSION); }
From source file:org.jaffa.modules.printing.services.PdfHelper.java
License:Open Source License
/** * Scale the pages of the input pdfOutput document to the given pageSize. * @param pdfOutput The PDF document to rescale, in the form of a ByteArrayOutputStream. * @param pageSize The new page size to which to scale to PDF document, e.g. "A4". * @param noEnlarge If true, center pages instead of enlarging them. * Use noEnlarge if the new page size is larger than the old one * and the pages should be centered instead of enlarged. * @param preserveAspectRatio If true, the aspect ratio will be preserved. * @return The PDF document with its pages scaled to the input pageSize. *///from ww w .j a va2 s . c o m public static byte[] scalePdfPages(byte[] pdfOutput, String pageSize, boolean noEnlarge, boolean preserveAspectRatio) throws FormPrintException { if (pageSize == null || pdfOutput == null) { return pdfOutput; } // Get the dimensions of the given pageSize in PostScript points. // A PostScript point is a 72th of an inch. float dimX; float dimY; Rectangle rectangle; try { rectangle = PageSize.getRectangle(pageSize); } catch (Exception ex) { FormPrintException e = new PdfProcessingException( "scalePdfPages - Invalid page size = " + pageSize + " "); log.error(" scalePdfPages - Invalid page size: " + pageSize + ". " + ex.getMessage() + ". "); throw e; } if (rectangle != null) { dimX = rectangle.getWidth(); dimY = rectangle.getHeight(); } else { FormPrintException e = new PdfProcessingException("scalePdfPages - Invalid page size: " + pageSize); log.error(" scalePdfPages - Invalid page size: " + pageSize); throw e; } //Create portrait and landscape rectangles for the given page size. Rectangle portraitPageSize; Rectangle landscapePageSize; if (dimY > dimX) { portraitPageSize = new Rectangle(dimX, dimY); landscapePageSize = new Rectangle(dimY, dimX); } else { portraitPageSize = new Rectangle(dimY, dimX); landscapePageSize = new Rectangle(dimX, dimY); } // Remove the document rotation before resizing the document. byte[] output = removeRotation(pdfOutput); PdfReader currentReader = null; try { currentReader = new PdfReader(output); } catch (IOException ex) { FormPrintException e = new PdfProcessingException("scalePdfPages - Failed to create a PDF Reader"); log.error(" scalePdfPages - Failed to create a PDF Reader "); throw e; } OutputStream baos = new ByteArrayOutputStream(); Rectangle newSize = new Rectangle(dimX, dimY); Document document = new Document(newSize, 0, 0, 0, 0); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, baos); } catch (DocumentException ex) { FormPrintException e = new PdfProcessingException("scalePdfPages - Failed to create a PDF Writer"); log.error(" scalePdfPages - Failed to create a PDF Writer "); throw e; } document.open(); PdfContentByte cb = writer.getDirectContent(); PdfImportedPage page; float offsetX, offsetY; for (int i = 1; i <= currentReader.getNumberOfPages(); i++) { Rectangle currentSize = currentReader.getPageSizeWithRotation(i); if (currentReader.getPageRotation(i) != 0) { FormPrintException e = new PdfProcessingException("Page Rotation, " + currentReader.getPageRotation(i) + ", must be removed to re-scale the form."); log.error(" Page Rotation, " + currentReader.getPageRotation(i) + ", must be removed to re-scale the form. "); throw e; } //Reset the page size for each page because there may be a mix of sizes in the document. float currentWidth = currentSize.getWidth(); float currentHeight = currentSize.getHeight(); if (currentWidth > currentHeight) { newSize = landscapePageSize; } else { newSize = portraitPageSize; } document.setPageSize(newSize); document.newPage(); float factorX = newSize.getWidth() / currentSize.getWidth(); float factorY = newSize.getHeight() / currentSize.getHeight(); // Use noEnlarge if the new page size is larger than the old one // and the pages should be centered instead of enlarged. if (noEnlarge) { if (factorX > 1) { factorX = 1; } if (factorY > 1) { factorY = 1; } } if (preserveAspectRatio) { factorX = Math.min(factorX, factorY); factorY = factorX; } offsetX = (newSize.getWidth() - (currentSize.getWidth() * factorX)) / 2f; offsetY = (newSize.getHeight() - (currentSize.getHeight() * factorY)) / 2f; page = writer.getImportedPage(currentReader, i); cb.addTemplate(page, factorX, 0, 0, factorY, offsetX, offsetY); } document.close(); return ((ByteArrayOutputStream) baos).toByteArray(); }
From source file:org.jaffa.modules.printing.services.PdfHelper.java
License:Open Source License
/** * Remove the rotation from the pdfOutput document pages. *//*from w w w . j a v a2s.com*/ private static byte[] removeRotation(byte[] pdfOutput) throws FormPrintException { PdfReader currentReader = null; try { currentReader = new PdfReader(pdfOutput); } catch (IOException ex) { FormPrintException e = new PdfProcessingException( "Remove PDF Page Rotation - Failed to create a PDF Reader"); log.error(" Remove PDF Page Rotation - Failed to create a PDF Reader "); throw e; } boolean needed = false; for (int i = 1; i <= currentReader.getNumberOfPages(); i++) { if (currentReader.getPageRotation(i) != 0) { needed = true; } } if (!needed) { return pdfOutput; } OutputStream baos = new ByteArrayOutputStream(); Document document = new Document(); PdfWriter writer = null; try { writer = PdfWriter.getInstance(document, baos); } catch (DocumentException ex) { FormPrintException e = new PdfProcessingException( "Remove PDF Page Rotation - Failed to create a PDF Writer"); log.error(" Remove PDF Page Rotation - Failed to create a PDF Writer "); throw e; } PdfContentByte cb = null; PdfImportedPage page; for (int i = 1; i <= currentReader.getNumberOfPages(); i++) { Rectangle currentSize = currentReader.getPageSizeWithRotation(i); currentSize = new Rectangle(currentSize.getWidth(), currentSize.getHeight()); // strip rotation document.setPageSize(currentSize); if (cb == null) { document.open(); cb = writer.getDirectContent(); } else { document.newPage(); } int rotation = currentReader.getPageRotation(i); page = writer.getImportedPage(currentReader, i); float a, b, c, d, e, f; if (rotation == 0) { a = 1; b = 0; c = 0; d = 1; e = 0; f = 0; } else if (rotation == 90) { a = 0; b = -1; c = 1; d = 0; e = 0; f = currentSize.getHeight(); } else if (rotation == 180) { a = -1; b = 0; c = 0; d = -1; e = currentSize.getWidth(); f = currentSize.getHeight(); } else if (rotation == 270) { a = 0; b = 1; c = -1; d = 0; e = currentSize.getWidth(); f = 0; } else { FormPrintException ex = new PdfProcessingException( "Remove PDF Page Rotation - Unparsable rotation value: " + rotation); log.error(" Remove PDF Page Rotation - Unparsable form rotation value: " + rotation); throw ex; } cb.addTemplate(page, a, b, c, d, e, f); } document.close(); return ((ByteArrayOutputStream) baos).toByteArray(); }
From source file:org.jpedal.examples.simpleviewer.utils.ItextFunctions.java
License:Open Source License
public void nup(int pageCount, PdfPageData currentPageData, ExtractPDFPagesNup extractPage) { try {/*from w w w. j a v a2 s . c o m*/ 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.jplot2d.renderer.PdfExporter.java
License:Open Source License
@Override public void render(ComponentEx comp, List<CacheableBlock> cacheBlockList) { Dimension size = getDeviceBounds(comp).getSize(); Document document = new Document(new Rectangle(size.width, size.height), 0, 0, 0, 0); PdfWriter writer;/*from www . j a v a 2s.c o m*/ try { writer = PdfWriter.getInstance(document, os); } catch (DocumentException e) { /* * should not happen but if it happens it should be notified to the integration instead of leaving it * half-done and tell nothing. */ throw new RuntimeException("Error creating PDF document", e); } document.open(); if (title != null) { document.addTitle(title); } PdfContentByte cb = writer.getDirectContent(); Graphics2D g = cb.createGraphics(size.width, size.height); for (CacheableBlock cblock : cacheBlockList) { List<ComponentEx> sublist = cblock.getSubcomps(); for (ComponentEx subcomp : sublist) { subcomp.draw(g); } } g.dispose(); document.close(); }
From source file:org.kitodo.production.services.data.ProcessService.java
License:Open Source License
/** * Generate result as PDF.//from www.j a va 2 s . com * * @param filter * for generating search results */ public void generateResultAsPdf(String filter) throws DocumentException, IOException { FacesContext facesContext = FacesContext.getCurrentInstance(); if (!facesContext.getResponseComplete()) { ExternalContext response = prepareHeaderInformation(facesContext, "search.pdf"); try (OutputStream out = response.getResponseOutputStream()) { SearchResultGeneration sr = new SearchResultGeneration(filter, this.showClosedProcesses, this.showInactiveProjects); HSSFWorkbook wb = sr.getResult(); List<List<HSSFCell>> rowList = new ArrayList<>(); HSSFSheet mySheet = wb.getSheetAt(0); Iterator<Row> rowIter = mySheet.rowIterator(); while (rowIter.hasNext()) { HSSFRow myRow = (HSSFRow) rowIter.next(); Iterator<Cell> cellIter = myRow.cellIterator(); List<HSSFCell> row = new ArrayList<>(); while (cellIter.hasNext()) { HSSFCell myCell = (HSSFCell) cellIter.next(); row.add(myCell); } rowList.add(row); } Document document = new Document(); Rectangle rectangle = new Rectangle(PageSize.A3.getHeight(), PageSize.A3.getWidth()); PdfWriter.getInstance(document, out); document.setPageSize(rectangle); document.open(); if (!rowList.isEmpty()) { Paragraph paragraph = new Paragraph(rowList.get(0).get(0).toString()); document.add(paragraph); document.add(getPdfTable(rowList)); } document.close(); out.flush(); facesContext.responseComplete(); } } }
From source file:org.kuali.kfs.module.ar.report.service.impl.ContractsGrantsInvoiceReportServiceImpl.java
License:Open Source License
/** * this method generated the actual pdf for the Contracts & Grants LOC Review Document. * * @param os/* w ww . j a va 2 s .c o m*/ * @param LOCDocument */ protected void generateLOCReviewInPdf(OutputStream os, ContractsGrantsLetterOfCreditReviewDocument locDocument) { try { Document document = new Document( new Rectangle(ArConstants.LOCReviewPdf.LENGTH, ArConstants.LOCReviewPdf.WIDTH)); PdfWriter.getInstance(document, os); document.open(); Paragraph header = new Paragraph(); Paragraph text = new Paragraph(); Paragraph title = new Paragraph(); // Lets write the header header.add(new Paragraph(configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_TITLE), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundGroupCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_GROUP_CODE) + locDocument.getLetterOfCreditFundGroupCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } if (StringUtils.isNotEmpty(locDocument.getLetterOfCreditFundCode())) { header.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_FUND_CODE) + locDocument.getLetterOfCreditFundCode(), ArConstants.PdfReportFonts.LOC_REVIEW_TITLE_FONT)); } header.add(new Paragraph(KFSConstants.BLANK_SPACE)); header.setAlignment(Element.ALIGN_CENTER); title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_NUMBER) + locDocument.getDocumentNumber(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); Person person = getPersonService() .getPerson(locDocument.getFinancialSystemDocumentHeader().getInitiatorPrincipalId()); // writing the Document details title.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_APP_DOC_STATUS) + locDocument.getFinancialSystemDocumentHeader().getApplicationDocumentStatus(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add( new Paragraph( configService.getPropertyValueAsString( ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_INITIATOR) + person.getName(), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph( configService .getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_HEADER_DOCUMENT_CREATE_DATE) + getDateTimeService().toDateString( locDocument.getFinancialSystemDocumentHeader().getWorkflowCreateDate()), ArConstants.PdfReportFonts.LOC_REVIEW_HEADER_FONT)); title.add(new Paragraph(KFSConstants.BLANK_SPACE)); title.setAlignment(Element.ALIGN_RIGHT); text.add(new Paragraph( configService.getPropertyValueAsString(ArKeyConstants.LOC_REVIEW_PDF_SUBHEADER_AWARDS), ArConstants.PdfReportFonts.LOC_REVIEW_SMALL_BOLD)); text.add(new Paragraph(KFSConstants.BLANK_SPACE)); document.add(header); document.add(title); document.add(text); PdfPTable table = new PdfPTable(11); table.setTotalWidth(ArConstants.LOCReviewPdf.RESULTS_TABLE_WIDTH); // fix the absolute width of the table table.setLockedWidth(true); // relative col widths in proportions - 1/11 float[] widths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; table.setWidths(widths); table.setHorizontalAlignment(0); addAwardHeaders(table); if (CollectionUtils.isNotEmpty(locDocument.getHeaderReviewDetails()) && CollectionUtils.isNotEmpty(locDocument.getAccountReviewDetails())) { for (ContractsGrantsLetterOfCreditReviewDetail item : locDocument.getHeaderReviewDetails()) { table.addCell(Long.toString(item.getProposalNumber())); table.addCell(item.getAwardDocumentNumber()); table.addCell(item.getAgencyNumber()); table.addCell(item.getCustomerNumber()); table.addCell(getDateTimeService().toDateString(item.getAwardBeginningDate())); table.addCell(getDateTimeService().toDateString(item.getAwardEndingDate())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getAwardBudgetAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getLetterOfCreditAmount())); table.addCell( contractsGrantsBillingUtilityService.formatForCurrency(item.getClaimOnCashBalance())); table.addCell(contractsGrantsBillingUtilityService.formatForCurrency(item.getAmountToDraw())); table.addCell(contractsGrantsBillingUtilityService .formatForCurrency(item.getAmountAvailableToDraw())); PdfPCell cell = new PdfPCell(); cell.setPadding(ArConstants.LOCReviewPdf.RESULTS_TABLE_CELL_PADDING); cell.setColspan(ArConstants.LOCReviewPdf.RESULTS_TABLE_COLSPAN); PdfPTable newTable = new PdfPTable(ArConstants.LOCReviewPdf.INNER_TABLE_COLUMNS); newTable.setTotalWidth(ArConstants.LOCReviewPdf.INNER_TABLE_WIDTH); // fix the absolute width of the newTable newTable.setLockedWidth(true); // relative col widths in proportions - 1/8 float[] newWidths = new float[] { 1f, 1f, 1f, 1f, 1f, 1f, 1f, 1f }; newTable.setWidths(newWidths); newTable.setHorizontalAlignment(0); addAccountsHeaders(newTable); for (ContractsGrantsLetterOfCreditReviewDetail newItem : locDocument .getAccountReviewDetails()) { if (item.getProposalNumber().equals(newItem.getProposalNumber())) { newTable.addCell(newItem.getAccountDescription()); newTable.addCell(newItem.getChartOfAccountsCode()); newTable.addCell(newItem.getAccountNumber()); String accountExpirationDate = KFSConstants.EMPTY_STRING; if (!ObjectUtils.isNull(newItem.getAccountExpirationDate())) { accountExpirationDate = getDateTimeService() .toDateString(newItem.getAccountExpirationDate()); } newTable.addCell(accountExpirationDate); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAwardBudgetAmount())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getClaimOnCashBalance())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getAmountToDraw())); newTable.addCell(contractsGrantsBillingUtilityService .formatForCurrency(newItem.getFundsNotDrawn())); } } cell.addElement(newTable); table.addCell(cell); } document.add(table); } document.close(); } catch (DocumentException e) { LOG.error("problem during ContractsGrantsInvoiceReportServiceImpl.generateInvoiceInPdf()", e); } }
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//from w w w . jav 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.locationtech.udig.printing.ui.pdf.ExportPDFWizard.java
License:Open Source License
protected Rectangle rotatePageIfNecessary(Rectangle suggestedPageSize) { //rotate the page if dimensions are given as portrait, but template prefers landscape if (suggestedPageSize.getHeight() > suggestedPageSize.getWidth() && page1.isLandscape()) { float temp = suggestedPageSize.getWidth(); float newWidth = suggestedPageSize.getHeight(); float newHeight = temp; return new Rectangle(suggestedPageSize.getHeight(), suggestedPageSize.getWidth()); }/* w ww. j a v a 2 s . c o m*/ return suggestedPageSize; }