List of usage examples for com.lowagie.text Phrase Phrase
public Phrase(float leading, String string)
Phrase
with a certain leading and a certain String
. From source file:com.conecta.sat.utils.BuildImportTokensPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. System.out.println("Into BuildImportTokensPDF"); hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=ImportTokens" + name.format(new Date()) + ".pdf"); ImportTokensPDF list = (ImportTokensPDF) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(3); table.setWidthPercentage(100);//from ww w . j a v a2 s.c o m table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Reporte de Tokens", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph(df.format(new Date()), font); fecha.setAlignment(Element.ALIGN_RIGHT); document.add(fecha); Paragraph pNombre = new Paragraph(nombreUsuario, font); pNombre.setAlignment(Element.ALIGN_RIGHT); document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Nmero de empleado que importo en token", font)); table.addCell(cell); cell.setPhrase(new Phrase("Fecha y Hora", font)); table.addCell(cell); cell.setPhrase(new Phrase("Tokens importados", font)); table.addCell(cell); // cell.setPhrase(new Phrase("Centro Financiero", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Tipo", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Cliente nico", font)); // table.addCell(cell); // // cell.setPhrase(new Phrase("Fecha de ultima modificacin", font)); // table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data // for (ImportTokensPDF pdf : list) { // ImportTokensPDF pdf; cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getUsuario(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(df.format(list.getFecha()), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(list.getTokens(), font2)); table.addCell(cell); // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCentro(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getTipo(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getCliente(),font2) ); // table.addCell(cell); // // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getLastUpdate(),font2) ); // table.addCell(cell); // } document.add(table); }
From source file:com.conecta.sat.utils.BuildPDF.java
@Override protected void buildPdfDocument(Map<String, Object> map, Document document, PdfWriter writer, HttpServletRequest hsr, HttpServletResponse hsr1) throws Exception { // throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. hsr1.setContentType("application/pdf"); DateFormat name = new SimpleDateFormat("ddMMyyyyhhmmss"); hsr1.setHeader("Content-disposition", "attachment; filename=Reporte" + name.format(new Date()) + ".pdf"); List<PdfDTO> list = (List<PdfDTO>) map.get("list"); String nombreUsuario = (String) map.get("nombreUsuario"); PdfPTable table = new PdfPTable(9); table.setWidthPercentage(100);/* www. ja v a 2 s .c o m*/ table.setSpacingBefore(10); Font font = FontFactory.getFont(FontFactory.HELVETICA); try { font.setFamily(fontName); } catch (Exception e) { font.setFamily("Verdana"); } try { ServletContext servletContext = hsr.getSession().getServletContext(); String relativeWebPath = logoPath; String absoluteDiskPath = servletContext.getRealPath(relativeWebPath); Image logo = Image.getInstance(absoluteDiskPath); // Image logo = Image.getInstance("logo.png"); System.out.println("La imagen se cargo correctamente"); logo.scaleToFit(widthLogo, heightLogo); document.add(logo); } catch (Exception e) { System.err.println("ERROR" + Excepciones.getStackTrace(e)); document.add(new Paragraph("Sin imagen " + logoPath)); } font.setSize(fontSize + 3); Paragraph titulo = new Paragraph("Reporte de Tokens", font); titulo.setAlignment(Element.ALIGN_RIGHT); document.add(titulo); Chunk CONNECT = new Chunk(new LineSeparator(0.5f, 100, java.awt.Color.BLACK, Element.ALIGN_CENTER, 3.5f)); document.add(CONNECT); DateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm a"); font.setSize(fontSize + 2); Paragraph fecha = new Paragraph(df.format(new Date()), font); fecha.setAlignment(Element.ALIGN_RIGHT); document.add(fecha); Paragraph pNombre = new Paragraph(nombreUsuario, font); pNombre.setAlignment(Element.ALIGN_RIGHT); document.add(pNombre); font.setSize(fontSize); font.setColor(java.awt.Color.white); // define table header cell PdfPCell cell = new PdfPCell(); java.awt.Color color = java.awt.Color.LIGHT_GRAY; cell.setBackgroundColor(color); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPadding(5); // write table header cell.setPhrase(new Phrase("Serial Token", font)); table.addCell(cell); // cell.setPhrase(new Phrase("Estatus Entrega", font)); cell.setPhrase(new Phrase("Estatus Entrega al Centro Financiero", font)); table.addCell(cell); cell.setPhrase(new Phrase("Estatus Entrega al Cliente", font)); table.addCell(cell); cell.setPhrase(new Phrase("Estatus Activacin", font)); table.addCell(cell); cell.setPhrase(new Phrase("Centro Financiero", font)); table.addCell(cell); cell.setPhrase(new Phrase("Tipo", font)); table.addCell(cell); cell.setPhrase(new Phrase("Cliente nico", font)); table.addCell(cell); cell.setPhrase(new Phrase("Folio Pivotal", font)); table.addCell(cell); // cell.setPhrase(new Phrase("ID nico", font)); // table.addCell(cell); cell.setPhrase(new Phrase("Fecha de ltima modificacin", font)); table.addCell(cell); Font font2 = FontFactory.getFont(FontFactory.HELVETICA); try { font2.setFamily(fontName); } catch (Exception e) { font2.setFamily("Verdana"); } font2.setSize(fontSize); font2.setColor(java.awt.Color.black); // write table row data for (PdfDTO pdf : list) { cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getSerial(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getEntrega(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getEntrega(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getActivacion(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getCentro(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getTipo(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getCliente(), font2)); table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getFolioPivotal(), font2)); table.addCell(cell); // cell = new PdfPCell(); // cell.setHorizontalAlignment( Element.ALIGN_CENTER ); // cell.addElement( new Phrase(pdf.getIdUnico(),font2) ); // table.addCell(cell); cell = new PdfPCell(); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.addElement(new Phrase(pdf.getLastUpdate(), font2)); table.addCell(cell); } document.add(table); }
From source file:com.efficio.fieldbook.service.LabelPrintingServiceImpl.java
License:Open Source License
/** * Gets the cell height.//from w ww. j ava 2 s .c om * * @param numberOfRowsPerPage the number of rows per page * @param pageSizeId the page size id * @return the cell height */ /* private float getCellHeight(int numberOfRowsPerPage, int pageSizeId){ if(pageSizeId == AppConstants.SIZE_OF_PAPER_A4){ if(numberOfRowsPerPage == 7){ return 108f; //ok }else if(numberOfRowsPerPage == 8){ return 97f;//ok }else if(numberOfRowsPerPage == 10){ return 72.5f; } }else{ if(numberOfRowsPerPage == 7){ return 108f; //ok }else if(numberOfRowsPerPage == 8){ return 98.1f;//ok }else if(numberOfRowsPerPage == 10){ return 72.5f;//ok } } return 0f; } */ /* (non-Javadoc) * @see com.efficio.fieldbook.service.api.LabelPrintingService#generateLabels(com.efficio.fieldbook.web.fieldmap.bean.UserFieldmap) */ @Override public String generatePDFLabels(List<StudyTrialInstanceInfo> trialInstances, UserLabelPrinting userLabelPrinting, ByteArrayOutputStream baos) throws MiddlewareQueryException { // setUserLabelPrinting(form.getUserLabelPrinting()); int pageSizeId = Integer.parseInt(userLabelPrinting.getSizeOfLabelSheet()); int numberOfLabelPerRow = Integer.parseInt(userLabelPrinting.getNumberOfLabelPerRow()); int numberofRowsPerPageOfLabel = Integer.parseInt(userLabelPrinting.getNumberOfRowsPerPageOfLabel()); int totalPerPage = numberOfLabelPerRow * numberofRowsPerPageOfLabel; String leftSelectedFields = userLabelPrinting.getLeftSelectedLabelFields(); String rightSelectedFields = userLabelPrinting.getRightSelectedLabelFields(); String barcodeNeeded = userLabelPrinting.getBarcodeNeeded(); String firstBarcodeField = userLabelPrinting.getFirstBarcodeField(); String secondBarcodeField = userLabelPrinting.getSecondBarcodeField(); String thirdBarcodeField = userLabelPrinting.getThirdBarcodeField(); String currentDate = DateUtil.getCurrentDate(); // String fileName = currentDate + ".pdf"; String fileName = userLabelPrinting.getFilenameDLLocation(); try { FileOutputStream fileOutputStream = new FileOutputStream(fileName); try { // Image image1 = Image.getInstance(imageLocation); // PageSize.A4 LabelPaper paper = LabelPaperFactory.generateLabelPaper(numberOfLabelPerRow, numberofRowsPerPageOfLabel, pageSizeId); Rectangle pageSize = PageSize.LETTER; if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4.getInt()) pageSize = PageSize.A4; Document document = new Document(pageSize); /* * 2, 2, 33.3f, 5 * 15, 0, 42, 5 * 10, 0, 17, 5 * 10, 0, 17, 5 * 5, 0, 0, 5 * 15, 0, 37, 5 * 10, 0, 17, 5 if (pageSizeId == AppConstants.SIZE_OF_PAPER_LETTER) { if (numberofRowsPerPageOfLabel == 7) document.setMargins(10, 0, 17, 5); else if (numberofRowsPerPageOfLabel == 8) document.setMargins(5, 0, 0, 5); else if (numberofRowsPerPageOfLabel == 10) document.setMargins(2, 2, 33.3f, 5); } else if (pageSizeId == AppConstants.SIZE_OF_PAPER_A4) { if (numberofRowsPerPageOfLabel == 7) document.setMargins(15, 0, 42, 5); else if (numberofRowsPerPageOfLabel == 8) document.setMargins(15, 0, 37, 5); else if (numberofRowsPerPageOfLabel == 10) document.setMargins(6, 2, 17.5f, 5); } */ //float marginLeft, float marginRight, float marginTop, float marginBottom document.setMargins(paper.getMarginLeft(), paper.getMarginRight(), paper.getMarginTop(), paper.getMarginBottom()); // PdfWriter writer = PdfWriter.getInstance(document, baos); PdfWriter writer = PdfWriter.getInstance(document, fileOutputStream); // step 3 document.open(); // step 4 PdfContentByte canvas = writer.getDirectContent(); int i = 0; int fixTableRowSize = numberOfLabelPerRow; PdfPTable table = new PdfPTable(fixTableRowSize); // table.writeSelectedRows(0, -1, 10, 12, canvas); float columnWidthSize = 265f;// 180f; float[] widthColumns = new float[fixTableRowSize]; for (int counter = 0; counter < widthColumns.length; counter++) { widthColumns[counter] = columnWidthSize; } table.setWidths(widthColumns); table.setWidthPercentage(100); int width = 600; int height = 75; List<File> filesToBeDeleted = new ArrayList<File>(); //float cellHeight = getCellHeight(numberofRowsPerPageOfLabel, pageSizeId); float cellHeight = paper.getCellHeight(); for (StudyTrialInstanceInfo trialInstance : trialInstances) { FieldMapTrialInstanceInfo fieldMapTrialInstanceInfo = trialInstance.getTrialInstance(); Map<String, String> moreFieldInfo = new HashMap<String, String>(); moreFieldInfo.put("locationName", fieldMapTrialInstanceInfo.getLocationName()); moreFieldInfo.put("blockName", fieldMapTrialInstanceInfo.getBlockName()); moreFieldInfo.put("selectedName", trialInstance.getFieldbookName()); moreFieldInfo.put("trialInstanceNumber", fieldMapTrialInstanceInfo.getTrialInstanceNo()); for (FieldMapLabel fieldMapLabel : fieldMapTrialInstanceInfo.getFieldMapLabels()) { i++; String barcodeLabel = generateBarcodeField(moreFieldInfo, fieldMapLabel, firstBarcodeField, secondBarcodeField, thirdBarcodeField, barcodeNeeded); if ("0".equalsIgnoreCase(barcodeNeeded)) { barcodeLabel = " "; } BitMatrix bitMatrix = new Code128Writer().encode(barcodeLabel, BarcodeFormat.CODE_128, width, height, null); String imageLocation = System.getProperty("user.home") + "/" + Math.random() + ".png"; File imageFile = new File(imageLocation); FileOutputStream fout = new FileOutputStream(imageFile); MatrixToImageWriter.writeToStream(bitMatrix, "png", fout); filesToBeDeleted.add(imageFile); Image mainImage = Image.getInstance(imageLocation); PdfPCell cell = new PdfPCell(); cell.setFixedHeight(cellHeight); cell.setNoWrap(false); cell.setPadding(5f); cell.setPaddingBottom(1f); PdfPTable innerImageTableInfo = new PdfPTable(1); innerImageTableInfo.setWidths(new float[] { 1 }); innerImageTableInfo.setWidthPercentage(82); PdfPCell cellImage = new PdfPCell(); if ("1".equalsIgnoreCase(barcodeNeeded)) { cellImage.addElement(mainImage); } else { cellImage.addElement(new Paragraph(" ")); } cellImage.setBorder(Rectangle.NO_BORDER); cellImage.setBackgroundColor(Color.white); cellImage.setPadding(1.5f); innerImageTableInfo.addCell(cellImage); //float fontSize = 6.8f; float fontSize = paper.getFontSize(); //if (numberofRowsPerPageOfLabel == 10) // fontSize = 4.8f; Font fontNormal = FontFactory.getFont("Arial", fontSize, Font.NORMAL); // cell.addElement(mainImage); cell.addElement(innerImageTableInfo); cell.addElement(new Paragraph()); for (int row = 0; row < 5; row++) { if (row == 0) { PdfPTable innerDataTableInfo = new PdfPTable(1); innerDataTableInfo.setWidths(new float[] { 1 }); innerDataTableInfo.setWidthPercentage(85); Font fontNormalData = FontFactory.getFont("Arial", 5.0f, Font.NORMAL); PdfPCell cellInnerData = new PdfPCell(new Phrase(barcodeLabel, fontNormalData)); cellInnerData.setBorder(Rectangle.NO_BORDER); cellInnerData.setBackgroundColor(Color.white); cellInnerData.setPaddingBottom(0.2f); cellInnerData.setPaddingTop(0.2f); cellInnerData.setHorizontalAlignment(Element.ALIGN_MIDDLE); innerDataTableInfo.addCell(cellInnerData); innerDataTableInfo.setHorizontalAlignment(Element.ALIGN_MIDDLE); cell.addElement(innerDataTableInfo); } PdfPTable innerTableInfo = new PdfPTable(2); innerTableInfo.setWidths(new float[] { 1, 1 }); innerTableInfo.setWidthPercentage(85); String leftText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel, leftSelectedFields, row); PdfPCell cellInnerLeft = new PdfPCell(new Paragraph(leftText, fontNormal)); cellInnerLeft.setBorder(Rectangle.NO_BORDER); cellInnerLeft.setBackgroundColor(Color.white); cellInnerLeft.setPaddingBottom(0.5f); cellInnerLeft.setPaddingTop(0.5f); innerTableInfo.addCell(cellInnerLeft); String rightText = generateBarcodeLabel(moreFieldInfo, fieldMapLabel, rightSelectedFields, row); PdfPCell cellInnerRight = new PdfPCell(new Paragraph(rightText, fontNormal)); cellInnerRight.setBorder(Rectangle.NO_BORDER); cellInnerRight.setBackgroundColor(Color.white); cellInnerRight.setPaddingBottom(0.5f); cellInnerRight.setPaddingTop(0.5f); innerTableInfo.addCell(cellInnerRight); cell.addElement(innerTableInfo); } cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(Color.white); //cell.setBorderColor(Color.BLUE); table.addCell(cell); if (i % numberOfLabelPerRow == 0) { // we go the next line int needed = fixTableRowSize - numberOfLabelPerRow; for (int neededCount = 0; neededCount < needed; neededCount++) { PdfPCell cellNeeded = new PdfPCell(); cellNeeded.setBorder(Rectangle.NO_BORDER); cellNeeded.setBackgroundColor(Color.white); table.addCell(cellNeeded); } table.completeRow(); if (numberofRowsPerPageOfLabel == 10) { //table.setSpacingAfter(9f); table.setSpacingAfter(paper.getSpacingAfter()); } document.add(table); table = new PdfPTable(fixTableRowSize); table.setWidths(widthColumns); table.setWidthPercentage(100); } if (i % totalPerPage == 0) { // we go the next page document.newPage(); } fout.flush(); fout.close(); } } // we need to add the last row if (i % numberOfLabelPerRow != 0) { // we go the next line int needed = fixTableRowSize - numberOfLabelPerRow; int remaining = numberOfLabelPerRow - (i % numberOfLabelPerRow); for (int neededCount = 0; neededCount < remaining; neededCount++) { PdfPCell cellNeeded = new PdfPCell(); cellNeeded.setBorder(Rectangle.NO_BORDER); cellNeeded.setBackgroundColor(Color.white); table.addCell(cellNeeded); } table.completeRow(); if (numberofRowsPerPageOfLabel == 10) { table.setSpacingAfter(paper.getSpacingAfter()); } document.add(table); table = new PdfPTable(fixTableRowSize); table.setWidths(widthColumns); table.setWidthPercentage(100); } document.close(); for (File file : filesToBeDeleted) { file.delete(); } fileOutputStream.close(); } catch (FileNotFoundException e) { LOG.error(e.getMessage(), e); } catch (IOException e) { LOG.error(e.getMessage(), e); } } catch (WriterException e) { LOG.error(e.getMessage(), e); } catch (Exception e) { LOG.error(e.getMessage(), e); } return fileName; }
From source file:com.geek.tutorial.itext.text.Paragraph_Example.java
License:Open Source License
public Paragraph_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("paragraph_example.pdf")); document.open();/*from w w w .jav a 2 s.c o m*/ Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); for (int i = 0; i < 10; i++) { phrase.add(chunk); } Paragraph paragraph = new Paragraph(); // 1 paragraph.add(phrase); // 2 document.add(paragraph); // 3 document.add(paragraph); // 4 document.close(); }
From source file:com.geek.tutorial.itext.text.Phrase_Example.java
License:Open Source License
public Phrase_Example() throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("phrase_example.pdf")); document.open();/*from w ww.java 2s . co m*/ Font font = new Font(Font.COURIER, 10, Font.BOLD); font.setColor(new Color(0x92, 0x90, 0x83)); Chunk chunk = new Chunk("testing text element ", font); chunk.setBackground(new Color(0xff, 0xe4, 0x00)); Phrase phrase = new Phrase(20, "This is initial text. "); // 1 for (int i = 0; i < 10; i++) { phrase.add(chunk); // 2 } document.add(phrase); // 3 document.close(); }
From source file:com.googlecode.openmpis.action.PersonAction.java
License:Open Source License
/** * Prints the person's poster in PDF file. * * @param mapping the ActionMapping used to select this instance * @param form the optional ActionForm bean for this request * @param request the HTTP Request we are processing * @param response the HTTP Response we are processing * @return the forwarding instance * @throws java.lang.Exception//w w w.ja va 2 s . c om */ public ActionForward printPoster(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { // Set the paper size and margins Document document = new Document(PageSize.LETTER, 50, 50, 50, 50); // Create the PDF writer ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); // Retrieve the person try { int id = Integer.parseInt(request.getParameter("id")); Person person = (Person) personService.getPersonById(id); // Process the photo String tokens[] = person.getPhoto().split("\\/"); String defaultPhotoBasename = ""; for (int i = 0; i < tokens.length - 1; i++) { defaultPhotoBasename += tokens[i] + File.separator; } defaultPhotoBasename += tokens[tokens.length - 1]; String absoluteDefaultPhotoFilename = getServlet().getServletContext().getRealPath("/") + defaultPhotoBasename; // Add some meta information to the document document.addTitle("Poster"); document.addAuthor("OpenMPIS"); document.addSubject("Poster for " + person.getNickname()); document.addKeywords("OpenMPIS, missing, found, unidentified"); document.addProducer(); document.addCreationDate(); document.addCreator("OpenMPIS version " + Constants.VERSION); // Open the document for writing document.open(); // Add the banner if (person.getType() > 4) { Paragraph foundParagraph = new Paragraph("F O U N D", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); foundParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(foundParagraph); } else { Paragraph missingParagraph = new Paragraph("M I S S I N G", FontFactory.getFont(FontFactory.HELVETICA_BOLD, 36, Font.BOLD, new Color(255, 0, 0))); missingParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(missingParagraph); } // Add date missing or found Paragraph blackParagraph = new Paragraph( getResources(request).getMessage("month." + person.getMonthMissingOrFound()) + " " + person.getDayMissingOrFound() + ", " + person.getYearMissingOrFound(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add missing from location if (person.getType() < 5) { blackParagraph = new Paragraph(person.getMissingFromCity() + ", " + person.getMissingFromProvince(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.BOLD, new Color(0, 0, 0))); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); } // Add name Paragraph redParagraph; if (!person.getNickname().isEmpty()) { redParagraph = new Paragraph( person.getFirstName() + " \"" + person.getNickname() + "\" " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } else { redParagraph = new Paragraph(person.getFirstName() + " " + person.getLastName(), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); } redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); // Add the photo Image image = Image.getInstance(absoluteDefaultPhotoFilename); image.scaleAbsolute(200, 300); image.setAlignment(Image.ALIGN_CENTER); document.add(image); // Add description redParagraph = new Paragraph("Description", FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); float[] widths = { 0.5f, 0.5f }; PdfPTable pdfptable = new PdfPTable(widths); pdfptable.setWidthPercentage(100); if (person.getType() < 5) { pdfptable .addCell( new Phrase( getResources(request).getMessage("label.date.birth") + ": " + getResources(request) .getMessage("month." + person.getBirthMonth()) + " " + person.getBirthDay() + ", " + person.getBirthYear(), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell( new Phrase(getResources(request).getMessage("label.address.city") + ": " + person.getCity(), FontFactory.getFont(FontFactory.HELVETICA, 12))); } pdfptable.addCell(new Phrase( getResources(request).getMessage("label.sex") + ": " + getResources(request).getMessage("sex." + person.getSex()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable .addCell( new Phrase( getResources(request).getMessage("label.color.hair") + ": " + getResources(request) .getMessage("color.hair." + person.getHairColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase(getResources(request).getMessage("label.height") + ": " + person.getFeet() + "' " + person.getInches() + "\"", FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.color.eye") + ": " + getResources(request).getMessage("color.eye." + person.getEyeColor()), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.weight") + ": " + person.getWeight() + " " + getResources(request).getMessage("label.weight.lbs"), FontFactory.getFont(FontFactory.HELVETICA, 12))); pdfptable.addCell(new Phrase( getResources(request).getMessage("label.race") + ": " + getResources(request).getMessage("race." + person.getRace()), FontFactory.getFont(FontFactory.HELVETICA, 12))); document.add(pdfptable); // Add circumstance redParagraph = new Paragraph(getResources(request).getMessage("label.circumstance"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.BOLD, new Color(255, 0, 0))); redParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(redParagraph); blackParagraph = new Paragraph(person.getCircumstance(), FontFactory.getFont(FontFactory.HELVETICA, 10, Font.NORMAL)); blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED); document.add(blackParagraph); // Add line blackParagraph = new Paragraph( "------------------------------------------------------------------------------"); blackParagraph.setAlignment(Paragraph.ALIGN_CENTER); document.add(blackParagraph); // Add contact blackParagraph = new Paragraph(getResources(request).getMessage("global.contact"), FontFactory.getFont(FontFactory.HELVETICA, 12, Font.NORMAL)); blackParagraph.setAlignment(Paragraph.ALIGN_JUSTIFIED); document.add(blackParagraph); document.close(); // Set the response to return the poster (PDF file) response.setContentType("application/pdf"); response.setContentLength(baos.size()); response.setHeader("Content-disposition", "attachment; filename=Poster.pdf"); // Close the output stream baos.writeTo(response.getOutputStream()); response.getOutputStream().flush(); return null; } catch (NumberFormatException nfe) { return mapping.findForward(Constants.LIST_PERSON); } catch (NullPointerException npe) { return mapping.findForward(Constants.LIST_PERSON); } }
From source file:com.gp.cong.logisoft.lcl.report.FreightInvoiceLclPdfCreator.java
public void init(String outputFileName, String fileId) throws FileNotFoundException, DocumentException, Exception { document = new Document(PageSize.A4); document.setMargins(10, 10, 10, 10); pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(outputFileName)); pdfWriter.setPageEvent(new FreightInvoiceLclPdfCreator(realPath, fileId)); company = new SystemRulesDAO().getCompanyDetails(); this.setBrand(fileId); HeaderFooter footer = new HeaderFooter( new Phrase(companyName, new Font(Font.HELVETICA, 10, Font.ITALIC, Color.BLACK)), false); footer.setBorder(Rectangle.NO_BORDER); footer.setAlignment(Element.ALIGN_CENTER); document.setFooter(footer);/*from w w w.j a v a2s. com*/ document.open(); }
From source file:com.gp.cong.logisoft.reports.BookingCoverSheetPdfCreater.java
public void createBody(SearchBookingReportDTO searchBookingReportDTO, String simpleRequest, MessageResources messageResources, String printFromBl, String documentName) throws DocumentException, MalformedURLException, IOException, Exception { NumberFormat numformat = new DecimalFormat("##,###,##0.00"); PdfPCell cell = new PdfPCell(); Paragraph paragraph;//from w w w. j av a2 s.c o m PdfPTable table; Phrase phrase; PdfPTable mainTable = makeTable(2); mainTable.setWidthPercentage(100); BookingFcl bookingFcl = searchBookingReportDTO.getBookingflFcl(); FclBl fclBl = null; if (CommonUtils.isNotEmpty(printFromBl)) { fclBl = new FclBlDAO().getFileNoObject(bookingFcl.getFileNo()); } String company = null; String contactName = ""; String email = null; String phone = null; String fax = null; String address = null; QuotationDAO quotationDAO = new QuotationDAO(); CustAddressBC custAddressBC = new CustAddressBC(); Quotation quotation = quotationDAO.getFileNoObject(bookingFcl.getFileNo()); if (null != quotation) { contactName = quotation.getContactname(); } if (bookingFcl.getShippercheck() != null && bookingFcl.getShippercheck().equals("on")) { //from=bookingFcl.getShipper(); company = bookingFcl.getShipper(); email = bookingFcl.getShipperEmail(); phone = bookingFcl.getShipperPhone(); fax = bookingFcl.getShipperFax(); address = bookingFcl.getAddressforShipper(); } else if (bookingFcl.getForwardercheck() != null && bookingFcl.getForwardercheck().equals("on")) { company = bookingFcl.getForward(); email = bookingFcl.getForwarderEmail(); phone = bookingFcl.getForwarderPhone(); fax = bookingFcl.getForwarderFax(); address = bookingFcl.getAddressforForwarder(); } else if (bookingFcl.getConsigneecheck() != null && bookingFcl.getConsigneecheck().equals("on")) { company = bookingFcl.getConsignee(); email = bookingFcl.getConsingeeEmail(); phone = bookingFcl.getConsingeePhone(); fax = bookingFcl.getConsigneeFax(); address = bookingFcl.getAddressforConsingee(); } else { if (null != quotation) { company = quotation.getClientname(); email = quotation.getEmail1(); phone = quotation.getPhone(); fax = quotation.getFax(); CustAddress custAddress = custAddressBC.getClientAddress(quotation.getClientnumber()); if (null != custAddress) { address = custAddress.getAddress1(); } } } PdfPTable headerTable = makeTable(3); headerTable.setWidths(new float[] { 20, 50, 30 }); headerTable.setWidthPercentage(100); PdfPTable headerTable1 = makeTable(1); headerTable1.setWidths(new float[] { 100 }); headerTable1.setWidthPercentage(100); PdfPCell headingCell1 = makeCell( new Phrase(messageResources.getMessage("fileNumberPrefix") + String.valueOf(bookingFcl.getFileNo()), headingFont1), Element.ALIGN_CENTER); headingCell1.setBackgroundColor(Color.LIGHT_GRAY); headingCell1.setVerticalAlignment(Element.ALIGN_MIDDLE); headerTable1.addCell(headingCell1); cell = makeCellleftNoBorder(""); cell.addElement(headerTable1); headerTable.addCell(headerTable1); PdfPTable headerTable2 = makeTable(2); headerTable2.setWidths(new float[] { 38, 62 }); headerTable2.setWidthPercentage(100); SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy HH:mm a"); SimpleDateFormat sdfForddMMyyyy = new SimpleDateFormat("dd-MMM-yyyy"); String colon = ": "; String docCut = ""; String carrierDocCut = ""; String etd = ""; String eta = ""; if (bookingFcl.getDocCutOff() != null) { docCut = sdf.format(bookingFcl.getDocCutOff()); } if (bookingFcl.getCarrierDocCut() != null) { carrierDocCut = sdf.format(bookingFcl.getCarrierDocCut()); } if (bookingFcl.getEtd() != null) { etd = sdfForddMMyyyy.format(bookingFcl.getEtd()); } if (bookingFcl.getEta() != null) { eta = sdfForddMMyyyy.format(bookingFcl.getEta()); } headerTable2.addCell(makeCell(new Phrase("Doc Cutoff", headingFont2), Element.ALIGN_LEFT)); headerTable2.addCell(makeCell(new Phrase(colon + docCut, redBoldFont), Element.ALIGN_LEFT)); headerTable2.addCell(makeCell(new Phrase("Carrier Doc Cut", headingFont2), Element.ALIGN_LEFT)); headerTable2.addCell(makeCell(new Phrase(colon + carrierDocCut, redBoldFont), Element.ALIGN_LEFT)); cell = makeCellleftNoBorder(""); cell.addElement(headerTable2); headerTable.addCell(headerTable2); PdfPTable headerTable3 = makeTable(2); headerTable3.setWidths(new float[] { 20, 80 }); headerTable3.setWidthPercentage(100); headerTable3.addCell(makeCell(new Phrase("ETD", headingFont2), Element.ALIGN_LEFT)); headerTable3.addCell(makeCell(new Phrase(colon + etd, headingFont2), Element.ALIGN_LEFT)); headerTable3.addCell(makeCell(new Phrase("ETA", headingFont2), Element.ALIGN_LEFT)); headerTable3.addCell(makeCell(new Phrase(colon + eta, headingFont2), Element.ALIGN_LEFT)); cell = makeCellleftNoBorder(""); cell.addElement(headerTable3); headerTable.addCell(headerTable3); document.add(headerTable); PdfPTable pTable = new PdfPTable(2); pTable.setWidthPercentage(100); PdfPTable clientTable = makeTable(2); clientTable.setWidths(new float[] { 27, 73 }); clientTable.setWidthPercentage(100); clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Name")); clientTable.addCell(makeCellLeftNoBorderValue(company)); clientTable.addCell(makeCellleftNoBorderWithBoldFont("Client Address")); clientTable.addCell(makeCellLeftNoBorderValue(address)); clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Name")); clientTable.addCell(makeCellLeftNoBorderValue(contactName)); cell = makeCellleftNoBorderWithBoldFont("Contact Number"); cell.setNoWrap(true); clientTable.addCell(cell); clientTable.addCell(makeCellLeftNoBorderValue(phone)); clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Fax")); clientTable.addCell(makeCellLeftNoBorderValue(fax)); clientTable.addCell(makeCellleftNoBorderWithBoldFont("Contact Email")); clientTable.addCell(makeCellLeftNoBorderValue(email)); cell = makeCellleftNoBorder(""); cell.setBorderWidthRight(0.6f); cell.setBorderWidthBottom(0.6f); cell.setBorderWidthLeft(0.6f); cell.setBorderWidthTop(0.6f); cell.addElement(clientTable); pTable.addCell(cell); PdfPTable carrierTable = makeTable(2); carrierTable.setWidths(new float[] { 26, 74 }); carrierTable.setWidthPercentage(100); String sslName[] = bookingFcl.getSslname().split("//"); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Carrier")); carrierTable.addCell(makeCellLeftNoBorderValue(sslName.length > 1 ? sslName[0] : "")); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Vessel")); carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVessel())); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Voyage")); carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getVoyageCarrier())); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("SSL Booking#")); carrierTable.addCell(makeCellLeftNoBorderValue(bookingFcl.getSSBookingNo())); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POO")); carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getOriginTerminal()))); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POL")); carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofOrgin()))); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("POD")); carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getDestination()))); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("FD")); carrierTable.addCell(makeCellLeftNoBorderValue(getCityStateName(bookingFcl.getPortofDischarge()))); carrierTable.addCell(makeCellleftNoBorderWithBoldFont("Containers")); carrierTable.addCell(makeCellLeftNoBorderValue( this.getContainers(simpleRequest, searchBookingReportDTO, messageResources).getContent())); // PdfPCell cell1 = makeCell(this.getContainers(simpleRequest, searchBookingReportDTO, messageResources), 1); // cell1.setColspan(2); // cell1.setBorderWidthLeft(0.0F); // carrierTable.addCell(cell1); cell = makeCellleftNoBorder(""); cell.setBorderWidthRight(0.6f); cell.setBorderWidthBottom(0.6f); cell.setBorderWidthTop(0.6f); cell.addElement(carrierTable); pTable.addCell(cell); document.add(pTable); PdfPTable hazardsMainTable = makeTable(1); hazardsMainTable.setWidths(new float[] { 100 }); hazardsMainTable.setWidthPercentage(100); PdfPTable hazardsTable = makeTable(3); hazardsTable.setWidths(new float[] { 70, 15, 15 }); hazardsTable.setWidthPercentage(100); Image yes = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/y.png"); yes.scalePercent(60); yes.scaleAbsoluteWidth(18); PdfPCell yesCell = new PdfPCell(); yesCell.setBorder(0); yesCell.addElement(new Chunk(yes, 32, -0)); Image no = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/n.png"); no.scalePercent(60); no.scaleAbsoluteWidth(18); PdfPCell noCell = new PdfPCell(); noCell.setBorder(0); noCell.addElement(new Chunk(no, 32, -0)); hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("HAZARDOUS")); if (bookingFcl.getHazmat() != null && "Y".equalsIgnoreCase(bookingFcl.getHazmat())) { hazardsTable.addCell(yesCell); hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1)); } else { hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1)); hazardsTable.addCell(noCell); } hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AES")); hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER)); hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER)); hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("DIRECT CONSIGMENT")); if (bookingFcl.getDirectConsignmntCheck() != null && "on".equalsIgnoreCase(bookingFcl.getDirectConsignmntCheck())) { hazardsTable.addCell(yesCell); hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), 1)); } else { hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), 1)); hazardsTable.addCell(noCell); } hazardsTable.addCell(makeCellleftNoBorderWithBoldFont("AFR")); hazardsTable.addCell(makeCell(new Phrase("Y", fontforYandN), Element.ALIGN_CENTER)); hazardsTable.addCell(makeCell(new Phrase("N", fontforYandN), Element.ALIGN_CENTER)); cell = makeCellleftNoBorder(""); cell.setBorderWidthRight(0.6f); cell.setBorderWidthBottom(0.6f); cell.setBorderWidthLeft(0.6f); cell.addElement(hazardsTable); hazardsMainTable.addCell(cell); document.add(hazardsMainTable); PdfPTable docsMainTable = makeTable(2); docsMainTable.setWidths(new float[] { 30, 70 }); docsMainTable.setWidthPercentage(100); PdfPTable docsTable = makeTable(2); docsTable.setWidths(new float[] { 50, 50 }); docsTable.setWidthPercentage(100); Image img = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/uncheckedBox.png"); img.scalePercent(50); img.scaleAbsoluteWidth(18); PdfPCell pCell = new PdfPCell(); pCell.setBorder(0); pCell.addElement(new Chunk(img, 25, -0)); // Image checkedimg = Image.getInstance(searchBookingReportDTO.getContextPath() + "/images/icons/check.png"); // checkedimg.scalePercent(60); // checkedimg.scaleAbsoluteWidth(18); // PdfPCell checkedCell = new PdfPCell(); // checkedCell.setBorder(0); // checkedCell.addElement(new Chunk(checkedimg, 25, -0)); docsTable.addCell(makeCellleftNoBorderWithBoldFont("Docs")); docsTable.addCell(pCell); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellleftNoBorderWithBoldFont("COB")); docsTable.addCell(pCell); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellleftNoBorderWithBoldFont("MBL")); docsTable.addCell(pCell); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellNoBorders(" ")); docsTable.addCell(makeCellleftNoBorderWithBoldFont("Manifisted")); docsTable.addCell(pCell); cell = makeCellleftNoBorder(""); cell.setBorderWidthBottom(0.6f); cell.setBorderWidthLeft(0.6f); cell.addElement(docsTable); docsMainTable.addCell(cell); PdfPTable noteTable = makeTable(1); noteTable.setWidths(new float[] { 100 }); noteTable.setWidthPercentage(100); noteTable.addCell(makeCellCenterNoBorder("Notes")); noteTable.addCell(makeCellNoBorders(" ")); noteTable.addCell(makeCellleftwithUnderLine(" ")); noteTable.addCell(makeCellNoBorders(" ")); noteTable.addCell(makeCellleftwithUnderLine(" ")); noteTable.addCell(makeCellNoBorders(" ")); noteTable.addCell(makeCellleftwithUnderLine(" ")); noteTable.addCell(makeCellNoBorders(" ")); noteTable.addCell(makeCellleftwithUnderLine(" ")); noteTable.addCell(makeCellNoBorders(" ")); cell = makeCellleftNoBorder(""); cell.setBorderWidthBottom(0.6f); cell.setBorderWidthRight(0.6f); cell.addElement(noteTable); docsMainTable.addCell(cell); document.add(docsMainTable); }
From source file:com.hotaviano.tableexporter.pdf.PDFExporter.java
License:Open Source License
private List<PdfPCell> getHeaders(Document document) { List<PdfPCell> result = new ArrayList<>(); Element tr = document.getRootElement().getChild("thead").getChildren().get(0); for (Element th : tr.getChildren()) { PdfPCell cell = new PdfPCell(new Phrase(th.getText(), new Font(Font.BOLD))); result.add(cell);/*from www . j a v a2 s . c om*/ } return result; }
From source file:com.jk.framework.desktop.swing.dao.TableModelPdfBuilder.java
License:Apache License
/** * Creates the pdf footer.// w w w . j a v a 2 s . com * * @param pdfPTable * the pdf P table * @param font * the font * @throws DocumentException * the document exception * @throws IOException * Signals that an I/O exception has occurred. */ public void createPdfFooter(final PdfPTable pdfPTable, Font font) throws DocumentException, IOException { final float width = pdfPTable.getWidthPercentage(); final int headerWidth = (int) width; font = getFont(); final PdfPCell footerCell = new PdfPCell(new Phrase(getFooter(), font)); footerCell.setHorizontalAlignment(Element.ALIGN_CENTER); footerCell.setVerticalAlignment(Element.ALIGN_MIDDLE); footerCell.setColspan(headerWidth); footerCell.setBorder(0); footerCell.setUseDescender(true); pdfPTable.addCell(footerCell); pdfPTable.setFooterRows(1); }