List of usage examples for com.itextpdf.text Element ALIGN_CENTER
int ALIGN_CENTER
To view the source code for com.itextpdf.text Element ALIGN_CENTER.
Click Source Link
From source file:com.mobicage.rogerthat.enterprise.samples.hr.bizz.GenerateExpenseNote.java
License:Open Source License
private void addHeader(PdfPTable table, String title) { PdfPCell c1 = new PdfPCell(new Phrase(title)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);//from w ww. ja v a 2 s .c om }
From source file:com.mx.ipn.clases.PDF.java
public void crearpdf(String nombre, String appat, String apmat) throws FileNotFoundException, DocumentException { // Creacion del documento con los margenes // Creacion del documento con los margenes Document document = new Document(PageSize.A4, 35, 30, 50, 50); try {//www . j a va 2s . co m // El archivo pdf que vamos a generar FileOutputStream fileOutputStream = new FileOutputStream("AvisoPrivacidad.pdf"); // Obtener la instancia del PdfWriter PdfWriter.getInstance(document, fileOutputStream); // Abrir el documento document.open(); // Crear las fuentes para el contenido y los titulos Font fontContenido = FontFactory.getFont(FontFactory.TIMES_ROMAN.toString(), 9, Font.NORMAL, BaseColor.DARK_GRAY); Font fontTitulos = FontFactory.getFont(FontFactory.TIMES_BOLD, 11, Font.UNDERLINE, BaseColor.DARK_GRAY); Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY); // Creacion del parrafo Paragraph paragraph = new Paragraph(); // Agregar un titulo con su respectiva fuente paragraph.add(new Phrase("Aviso de Privacidad", fontTitulos)); paragraph.setAlignment(Element.ALIGN_CENTER); // Agregar saltos de linea paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); // Agregar contenido con su respectiva fuente paragraph.add(new Phrase( "Con fundamento en los artculos 15, 16 y de acuerdo a lo Previsto en la Ley Federal de Proteccin de Datos" + "Personales, hacemos de su conocimiento que ZERCHERS, S.A. de C.V., es una empresa legalmente" + "constituido de conformidad con las leyes mexicanas, con domicilio en Av. Juan de Dios Btiz s/n, Gustavo" + "A. Madero, Nueva Industrial Vallejo, 07700 Ciudad de Mxico; y como responsable del tratamiento de sus" + "datos personales, del uso que se le d a los mismos y de su proteccin. Hace de su conocimiento que la" + "informacin de nuestros clientes es tratada de forma estrictamente confidencial por lo que, al proporcionar" + "sus datos personales. Estos sern utilizados nica y exclusivamente para los siguientes fines: " + "Proveer los servicios y productos que ha solicitado; notificarle sobre nuevos servicios o productos que" + "tengan relacin con los ya contratados o adquiridos; comunicarle sobre cambios en los mismos; evaluar la" + "calidad de los servicios que brindamos; mantener actualizada nuestra base de datos con sus datos" + "recientes y en general, para dar cumplimiento a las obligaciones que hemos contrado con usted.", fontContenido)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase( " Para las finalidades antes mencionadas, requerimos obtener los siguientes datos personales:", fontContenido)); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); // Agregar el parrafo al documento document.add(paragraph); document.add(Tabla_Simple()); paragraph = new Paragraph(); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase( "Para prevenir el acceso no autorizado a sus datos personales y con el fin de asegurar que la informacin sea " + "utilizada para los fines establecidos en este aviso de privacidad, hemos establecido diversos procedimientos" + " con la finalidad de evitar el uso o divulgacin no autorizados de sus datos, permitindonos tratarlos debidamente." + " As mismo, le informamos que sus datos personales pueden ser Transmitidos para ser tratados por personas " + "distintas a esta empresa. Todos sus datos personales son tratados de acuerdo a la legislacin aplicable y " + "vigente en el pas, por ello le informamos que usted tiene en todo momento los derechos (ARCO) de acceder, " + "rectificar, cancelar u oponerse al tratamiento que le damos a sus datos personales; derecho que podr " + "hacer valer a travs del ?rea de Privacidad encargada de la seguridad de datos personales en el " + "Telfono 5729 6000.", fontContenido)); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase( " A travs de estos canales usted podr actualizar sus datos y especificar el medio por el cual desea recibir " + "informacin, ya que en caso de no contar con esta especificacin de su parte, ZERCHERS, S.A. de C.V., " + "establecer libremente el canal que considere pertinente para enviarle informacin. Este aviso de" + " privacidad podr ser modificado por ZERCHERS, S.A. de C.V., dichas modificaciones sern oportunamente " + "informadas a travs de correo electrnico, telfono, pgina web o cualquier otro medio de comunicacin" + " que ZERCHERS, S.A. de C.V., determine para tal efecto.", fontContenido)); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(" ATENTAMENTE", nomb)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(" Direccin General TT/SisPLD", nomb)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(" Consiento que mis datos personales sensibles sean tratados conforme a" + "los trminos y condiciones del presente aviso de privacidad.", fontContenido)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase("Nombre: " + nombre + " " + appat + " " + apmat, nomb)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase("____________________________________", fontContenido)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(Chunk.NEWLINE)); paragraph.add(new Phrase(" ltima Fecha de Emisin: Mayo 13, 2016", fontContenido)); document.add(paragraph); // Cerrar el documento document.close(); // Abrir el archivo File file = new File("AvisoPrivacidad.pdf"); Desktop.getDesktop().open(file); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.mx.ipn.clases.PDF.java
public PdfPTable Tabla_Simple() throws BadElementException, IOException { Paragraph paragraph1 = new Paragraph(); Font nomb = FontFactory.getFont(FontFactory.TIMES_BOLD, 9, Font.NORMAL, BaseColor.DARK_GRAY); Image image;//from w w w . ja v a2 s. com // Obtenemos el logo de datojava image = Image.getInstance(getClass().getResource("/com/ipn/mx/imagenes/logo.png")); image.scaleAbsolute(70f, 60f); //creamos la tabla con 3 columnas PdfPTable mitablasimple = new PdfPTable(2); PdfPCell cellimage = new PdfPCell(image); // Propiedades de la celda cellimage.setBorderColor(BaseColor.WHITE); cellimage.setHorizontalAlignment(Element.ALIGN_CENTER); paragraph1.add(new Phrase("1. Nombre completo Y/O Razn Social.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("2. Direccin.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("3. Registro Federal de Contribuyentes Y/O CURP.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("4. Telfonos de Oficina y mviles.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("5. Actividad econmica e ingreso promedio.", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); paragraph1.add(new Phrase("6. Correo Electrnico. ", nomb)); paragraph1.add(new Phrase(Chunk.NEWLINE)); PdfPCell cell = new PdfPCell(paragraph1); // Propiedades de la celda cell.setBorderColor(BaseColor.WHITE); cell.setHorizontalAlignment(Element.ALIGN_JUSTIFIED); mitablasimple.addCell(cell); mitablasimple.addCell(cellimage); //retornamos la tabla return mitablasimple; }
From source file:com.myapp.struts.transaction.transactionAction.java
public ActionForward generatememberreport(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws SQLException, Exception { if (Constants.isSessionActive(request)) { transactionForm transactionForm = (transactionForm) form; try {//from w w w . j av a 2 s . c o m Date utilDate = new Date(); java.sql.Date date = new java.sql.Date(utilDate.getTime()); Font bigFont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD, BaseColor.BLACK); Font bigFont_Uderline = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 12, Font.BOLD | Font.UNDERLINE, BaseColor.BLACK); Font boldfont = FontFactory.getFont(FontFactory.HELVETICA, "Windows-1254", 9, Font.BOLD); Document document = new Document(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(document, baos); document.open(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); //Or whatever format fits best your needs. Paragraph para1 = new Paragraph("PALKE JEWELLERS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph("MEMBER ACCOUNT DETAILS", bigFont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); para1 = new Paragraph(transactionForm.getSelectedmember(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph( transactionForm.getMemberaddress() + "\n" + transactionForm.getMembercontactno(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); Groups obj = (Groups) hmGroups.get(transactionForm.getGroupid() + ""); if (obj != null) { para1 = new Paragraph("Group : " + obj.getGroupname(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Paid Amount : " + transactionForm.getTotalpaidamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Prize Amount : " + transactionForm.getDrawamount(), font); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Total Amount : " + transactionForm.getTotalamount(), boldfont); para1.setAlignment(Element.ALIGN_LEFT); document.add(para1); para1 = new Paragraph("Status : " + transactionForm.getStatus(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); if (transactionForm.getStatus().equalsIgnoreCase("Settled")) { para1 = new Paragraph(transactionForm.getSettlementcomment(), boldfont); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); } String dateStr = sdf.format(date); para1 = new Paragraph("DATED:" + dateStr, font); para1.setAlignment(Element.ALIGN_RIGHT); document.add(para1); // add a couple of blank lines document.add(Chunk.NEWLINE); if (transactionForm.getLstPayment() != null && transactionForm.getLstPayment().size() > 0) { PdfPTable table2 = new PdfPTable(7); float[] columnWidths = { 1.5f, 1.5f, 3f, 4f, 4f, 7f, 2f }; table2.setWidthPercentage(100); table2.setWidths(columnWidths); para1 = new Paragraph("Sl No.", font); para1.setAlignment(Element.ALIGN_CENTER); PdfPCell cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Term", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt No.", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Receipt Date", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Payment Mode", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Remarks", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph("Paid Amount", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); int x = 1; double total = 0; //Iterator it = hmPayments.entrySet().iterator(); //while (it.hasNext()) { if (hmPayments.size() > 0) { for (int i = 1; i <= obj.getNoofinstallment(); i++) { //float f = columnWidths[i]; Payment f1 = (Payment) hmPayments.get(i + ""); //} //Map.Entry pairs = (Map.Entry) it.next(); //Payment f1 = (Payment) pairs.getValue(); String term = i + ""; para1 = new Paragraph(Integer.toString(x), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); x++; para1 = new Paragraph(term, font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentid() + "", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(sdf.format(f1.getPaiddate()), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getPaymentmode() == 1 ? "Cash" : "Cheque/NEFT", font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); para1 = new Paragraph(f1.getRemarks(), font); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); //para1 = new Paragraph(f1.getPaidamount() + "", boldfont); para1 = new Paragraph((int) obj.getInstallmentamount() + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); table2.addCell(cell); total = total + obj.getInstallmentamount(); if (hmPayments.size() == i) { break; } } para1 = new Paragraph("Total", boldfont); para1.setAlignment(Element.ALIGN_LEFT); cell = new PdfPCell(para1); cell.setColspan(6); table2.addCell(cell); //String numberStr = String.format("%.2f", total + ""); para1 = new Paragraph(total + "", boldfont); para1.setAlignment(Element.ALIGN_CENTER); cell = new PdfPCell(para1); //cell.setColspan(7); table2.addCell(cell); table2.setHorizontalAlignment(Element.ALIGN_LEFT); document.add(table2); } else { para1 = new Paragraph("NO PAYMENTS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); } document.add(Chunk.NEWLINE); //document.close(); //fileInputStream = new FileInputStream(new File("C:\\reports\\PaymentReports.pdf")); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } else { para1 = new Paragraph("NO RECORDS FOUND", boldfont); para1.setAlignment(Element.ALIGN_CENTER); document.add(para1); document.close(); ServletOutputStream outputStream = response.getOutputStream(); baos.writeTo(outputStream); response.setHeader("Content-Disposition", "attachment; filename=\"PaymentStatusReport.pdf\""); response.setContentType("application/pdf"); outputStream.flush(); outputStream.close(); return mapping.findForward("display"); } } catch (DocumentException i) { System.out.println(i); return mapping.findForward("fail"); } catch (IOException i) { System.out.println(i); return mapping.findForward("fail"); } } else { return mapping.findForward("exp"); } }
From source file:com.mycom.products.mywebsite.backend.util.DownloadHandler.java
License:Open Source License
private void setTableHeader(String value, PdfPTable table) { PdfPCell cell = new PdfPCell(new Paragraph(value)); cell.setBorderColor(BaseColor.GRAY); cell.setFixedHeight(25);//from w ww . jav a2 s . c om BaseColor myColor = WebColors.getRGBColor("#F7F7F7"); cell.setBackgroundColor(myColor); cell.setPaddingLeft(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); }
From source file:com.mycompany.mavenproject2.VirtualkeyController.java
private static void createTable(/*Section subCatPart*/String tableName, Paragraph preface) throws BadElementException { try {/*from w w w. j ava 2 s .c o m*/ ArrayList<String> list = new ArrayList<String>(); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); int length = 0; java.sql.Connection conn = Connection.getConnect(); Statement st = conn.createStatement(); st = conn.createStatement(); ResultSet rs = st.executeQuery("SELECT * FROM " + tableName); ResultSetMetaData rsMetaData = rs.getMetaData(); int numberOfColumns = rsMetaData.getColumnCount(); System.out.println("resultSet MetaData column Count=" + numberOfColumns); for (int i = 1; i <= numberOfColumns; i++) { length = i; } MongoClient client = new MongoClient(); MongoDatabase db = client.getDatabase("FinalDemo"); PdfPTable table = new PdfPTable(length); for (int i = 1; i <= numberOfColumns; i++) { // System.out.println("column MetaData "); //System.out.println("column number " + i); // get the column's name. System.out.println(rsMetaData.getColumnName(i)); PdfPCell c1 = new PdfPCell(new Phrase(rsMetaData.getColumnName(i))); c1.setHorizontalAlignment(Element.ALIGN_CENTER); list.add(rsMetaData.getColumnName(i)); table.addCell(c1); } while (rs.next()) { for (String col : list) { //System.out.println("Column name is "+col+"value is "+rs.getString(col)); table.addCell(rs.getString(col)); } } /*PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1);*/ table.setHeaderRows(1); preface.add(table); //subCatPart.add(table); } catch (ClassNotFoundException ex) { Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex); } catch (SQLException ex) { Logger.getLogger(VirtualkeyController.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.nerdcastle.nazmul.filetest.MainActivity.java
private static void createTable(Section subCatPart) throws BadElementException { ArrayList<String> a = new ArrayList<>(); a.add("1");//from ww w . j a v a 2 s . c o m a.add("2"); a.add("3"); ArrayList<String> b = new ArrayList<>(); b.add("4"); b.add("5"); b.add("6"); ArrayList<String> c = new ArrayList<>(); c.add("7"); c.add("8"); c.add("9"); PdfPTable table = new PdfPTable(3); // t.setBorderColor(BaseColor.GRAY); // t.setPadding(4); // t.setSpacing(4); // t.setBorderWidth(1); PdfPCell c1 = new PdfPCell(new Phrase("Table Header 1")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 2")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); c1 = new PdfPCell(new Phrase("Table Header 3")); c1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(c1); table.setHeaderRows(1); for (int i = 0; i < a.size(); i++) { table.addCell(a.get(i)); table.addCell(b.get(i)); table.addCell(c.get(i)); } /* table.addCell("1.0"); table.addCell("1.1"); table.addCell("1.2"); table.addCell("2.1"); table.addCell("2.2"); table.addCell("2.3");*/ subCatPart.add(table); }
From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java
License:Open Source License
public int generate(String saveUrl, SerializableBitmap sign, Form form, ArrayList<String> photos, ArrayList<String> workers) { try {/*ww w . j a va 2s.co m*/ Document document = new Document(); url = saveUrl; PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(url)); document.setMargins(20, 20, 20, 20); document.open(); Bitmap inputLogo = BitmapFactory.decodeStream(context.getAssets().open("logo.jpg")); ByteArrayOutputStream outstream = new ByteArrayOutputStream(); inputLogo.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image logo = Image.getInstance(outstream.toByteArray()); Bitmap inputQR = BitmapFactory.decodeStream(context.getAssets().open("qr.jpg")); outstream = new ByteArrayOutputStream(); inputQR.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image qr = Image.getInstance(outstream.toByteArray()); outstream = new ByteArrayOutputStream(); sign.getImage().compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image sgn = Image.getInstance(outstream.toByteArray()); qr.scaleAbsolute(90f, 90f); qr.setAbsolutePosition(340f, 705f); logo.scaleAbsolute(150f, 50f); logo.setAbsolutePosition(50f, 750f); sgn.scaleAbsolute(130f, 30f); sgn.setAbsolutePosition(25f, 75f); Paragraph p = new Paragraph("\r\n\r\n\r\nMPWiK S.A.\r\n50-421 Wrocaw\r\nul.Na Grobli 14-16", normal); p.setIndentationLeft(420f); document.add(p); p = new Paragraph("RAPORT WYMIANY WODOMIERZA", bold); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingBefore(60f); document.add(p); document.add(table(form)); p = new Paragraph(form.getInformations(), normal); p.setAlignment(Element.ALIGN_LEFT); p.setIndentationLeft(50f); p.setSpacingBefore(20f); document.add(p); document.add(signTable(form, sgn, workers)); document.add(logo); document.add(qr); if (photos != null && photos.size() > 0) { document.newPage(); for (int i = 0; i < photos.size(); i++) { try { if (photos.get(i) != null && !photos.get(i).equals("")) { Log.d(TAG, photos.get(i)); Bitmap temp = PictureHelper.bitmapFromUrl(photos.get(i)); outstream = new ByteArrayOutputStream(); temp.compress(Bitmap.CompressFormat.JPEG, 100, outstream); Image photo = Image.getInstance(outstream.toByteArray()); photo.scaleToFit(document.getPageSize().getWidth() - 50, document.getPageSize().getHeight()); document.add(photo); } } catch (Exception e) { } } } document.close(); writer.close(); return 1; } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); return 0; } catch (DocumentException e) { Log.e(TAG, e.getMessage()); return 0; } catch (IOException e) { Log.e(TAG, e.getMessage()); return 0; } catch (Exception e) { Log.e(TAG, e.getMessage()); return 0; } }
From source file:com.norbsoft.pdfconverter.helpers.PDFHelper.java
License:Open Source License
private PdfPTable table(Form form) { int cellPadding = 5; PdfPTable table = new PdfPTable(8); table.setSpacingBefore(20);/*from w w w. j av a 2 s. c o m*/ try { table.setWidths(new int[] { 100, 120, 30, 60, 60, 50, 50, 50 }); } catch (DocumentException e) { Log.e(TAG, "Width error:" + e.getMessage()); } PdfPCell cell = new PdfPCell(new Paragraph("Adres: " + form.getAddress(), normal)); cell.setColspan(8); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT | Rectangle.TOP); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("Odbiorca: " + form.getOwner(), normal)); cell.setColspan(8); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.RIGHT); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("Data: " + form.getDate(), normal)); cell.setColspan(3); cell.setPadding(cellPadding); cell.setBorder(Rectangle.LEFT | Rectangle.BOTTOM); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Paragraph("tel: " + form.getPhone(), normal)); cell.setColspan(5); cell.setPadding(cellPadding); cell.setBorder(Rectangle.RIGHT | Rectangle.BOTTOM); cell.setBorderColorBottom(BaseColor.BLACK); table.addCell(cell); //Header Paragraph p = new Paragraph("WODOMIERZ", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setNoWrap(true); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Nr fabryczny", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("DN", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Typ\r\nProducent", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Stan w (m3)", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Rok\r\nlegalizacji", bold); cell = new PdfPCell(p); ; cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph("Czy plomba\r\nlegalizacyjna jest\r\nuszkodzona?", bold); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //First row cell = new PdfPCell(new Paragraph("Zamontowany", bold)); cell.setNoWrap(true); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getNewSN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewDN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewType() + "\r\n" + form.getNewManufacturer(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewState(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getNewYear(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getNewSeal().equals("Tak")) p = new Paragraph("tak", normal); else p = new Paragraph("tak", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getNewSeal().equals("Nie")) p = new Paragraph("nie", normal); else p = new Paragraph("nie", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //Second row cell = new PdfPCell(new Paragraph("Wymontowany", bold)); cell.setNoWrap(true); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getOldSN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldDN(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldType() + "\r\n" + form.getOldManufacturer(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldState(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); p = new Paragraph(form.getOldYear(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getOldSeal().equals("Tak")) p = new Paragraph("tak", normal); else p = new Paragraph("tak", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); if (form.getOldSeal().equals("Nie")) p = new Paragraph("nie", normal); else p = new Paragraph("nie", strike); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); //Third row cell = new PdfPCell(new Paragraph("Plomba nr 1", bold)); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getSealFirst(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph("Przyczyna wymiany: " + form.getReason(), normal)); cell.setPadding(cellPadding); cell.setColspan(5); table.addCell(cell); //Fourth row cell = new PdfPCell(new Paragraph("Plomba nr 2", bold)); cell.setPadding(cellPadding); table.addCell(cell); p = new Paragraph(form.getSealSecond(), normal); cell = new PdfPCell(p); cell.setPadding(cellPadding); cell.setColspan(2); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); cell = new PdfPCell(new Paragraph("Umiejscowienie wodomierza: " + form.getPlacement(), normal)); cell.setPadding(cellPadding); cell.setColspan(5); table.addCell(cell); //Fourth row cell = new PdfPCell(new Paragraph("Nr moduu\r\nradiowego", bold)); cell.setPadding(cellPadding); table.addCell(cell); cell = new PdfPCell(new Paragraph(form.getNewModuleNumber(), normal)); cell.setPadding(cellPadding); cell.setColspan(7); cell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(cell); table.setWidthPercentage(100); return table; }
From source file:com.pdfwriter.PrintInventoryReport.java
public void create(ObservableList list, String totalSales) { try {/*from w w w .j a va 2s.c o m*/ Document document = new Document(PageSize.LETTER); document.setMargins(1, 1, 1, 1); PdfWriter.getInstance(document, new FileOutputStream(filename)); document.open(); Font font2 = new Font(Font.FontFamily.UNDEFINED, 10, Font.BOLD); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(95); table.setWidths(new int[] { 40, 40, 40, 40, 40 }); PdfPCell cell; cell = new PdfPCell(new Phrase("", font2)); cell.setBorder(0); cell.setColspan(8); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setVerticalAlignment(Element.ALIGN_CENTER); cell.setBorderWidthTop(0); cell.setBorderWidthBottom(0); table.addCell(cell); cell = new PdfPCell( new Phrase("KELNOVI SHOPPING BOTIQUE", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Pondol,Loon, Bohol", new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Phone/Fax#:000-000-000", new Font(Font.FontFamily.UNDEFINED, 9, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setRowspan(3); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("SALES REPORT", new Font(Font.FontFamily.TIMES_ROMAN, 12, Font.BOLD))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("NO.")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("PRODUCT NAME")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("PRICE")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("QUANTITY")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); cell = new PdfPCell(new Phrase("AMOUNT PAYABLE")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); cell.setBackgroundColor(BaseColor.GRAY); table.addCell(cell); for (int i = 0; i < list.size(); i++) { it = (ProductClass) list.get(i); cell = new PdfPCell(new Phrase("" + it.idProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productDescriptionProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productPriceProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); cell = new PdfPCell(new Phrase("" + it.productQtyProperty().get())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); //totalSales.setText(String.format("%,.2f",globalSales)); cell = new PdfPCell(new Phrase( String.format("%,.2f", Double.parseDouble(it.productTotalSalesProperty().get())))); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setBorder(14); table.addCell(cell); } cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("TOTAL AMOUNT PAYABLE:")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell( new Phrase("Php " + totalSales, new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("Approved by:")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("MICHAEL NOVI MALUENDA II", new Font(Font.FontFamily.UNDEFINED, 14, Font.UNDERLINE))); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase("General Manager")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); cell = new PdfPCell(new Phrase(" ")); cell.setColspan(10); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); cell.setBorder(0); table.addCell(cell); document.add(table); document.close(); openFile(); } catch (Exception e) { e.printStackTrace(); } }