List of usage examples for com.itextpdf.text.pdf PdfPTable setHorizontalAlignment
public void setHorizontalAlignment(final int horizontalAlignment)
From source file:Output.QuotePDf.java
private PdfPTable rateTable() throws DocumentException { PdfPTable table = new PdfPTable(2); table.setHorizontalAlignment(Element.ALIGN_LEFT); float[] columnWidths = new float[] { 35f, 75f }; table.setWidths(columnWidths);//from w w w . j a v a2s . c o m table.setSpacingAfter(10f); cell = new PdfPCell(new Phrase("Base Ocean Freight:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(oft, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("MAFI Minimum Charge:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); if (includeMafiMinimum) { cell = new PdfPCell(new Phrase("$" + mafiMinimum + " per MAFI unit.", textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("N/A", textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } cell = new PdfPCell(new Phrase("Subject To:", subjectToFont)); cell.setColspan(2); cell.setBorder(Rectangle.NO_BORDER); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Bunker Adjustment Factor:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(baf, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("ECA Surcharge:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(eca, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Terminal Handling (Origin):", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(thc, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Wharfage (Origin):", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(wfg, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("Documentation Fee:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase(doc, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); cell = new PdfPCell(new Phrase("War Risk Surcharge:", labelFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); if (includeWarRisk) { cell = new PdfPCell(new Phrase(wRsk, textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase("N/A", textFont)); cell.setColspan(1); cell.setBorder(Rectangle.NO_BORDER); table.addCell(cell); } return table; }
From source file:Output.QuotePDf.java
private PdfPTable carrierComments(Boolean includeCarrierComments, String carrierComments) { PdfPTable table = new PdfPTable(1); table.setHorizontalAlignment(Element.ALIGN_CENTER); table.setWidthPercentage(100f);/*from ww w . j a v a 2s. c o m*/ table.setSpacingAfter(10f); if (includeCarrierComments) { cell = new PdfPCell(new Phrase("Carrier Comments", tableHeadingFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setPaddingBottom(10f); cell.setBackgroundColor(BaseColor.BLACK); table.addCell(cell); cell = new PdfPCell(new Phrase(carrierComments, textFont)); cell.setPadding(5f); table.addCell(cell); } return table; }
From source file:Output.QuotePDf.java
private PdfPTable packingListTable(JTable packingListTable) throws DocumentException { PdfPTable table = new PdfPTable(11); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100f);/*from www . j av a 2 s.co m*/ table.setWidths(new int[] { 5, 2, 2, 2, 2, 3, 2, 2, 2, 3, 3 }); table.setSpacingAfter(10f); cell = new PdfPCell(new Phrase("Packing List", tableHeadingFont)); cell.setBackgroundColor(BaseColor.BLACK); cell.setColspan(11); cell.setPaddingBottom(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Commodity", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Qty", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("L(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("W(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("H(cm)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Kgs", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("L(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("W(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("H(in)", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("M3", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); cell = new PdfPCell(new Phrase("Lbs", plLabelFont)); cell.setBackgroundColor(BaseColor.LIGHT_GRAY); cell.setPaddingBottom(5); table.addCell(cell); for (int row = 0; row < packingListTable.getRowCount(); row++) { for (int col = 0; col < 11; col++) { String packingListData = String.valueOf(packingListTable.getValueAt(row, col)); if (packingListData.equals("null")) { packingListData = " "; cell = new PdfPCell(new Phrase(packingListData, textFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(packingListData, textFont)); table.getDefaultCell().setHorizontalAlignment(Element.ALIGN_LEFT); table.addCell(cell); } } } return table; }
From source file:Output.QuotePDf.java
private PdfPTable sailingScheduleTable(JTable sailingScheduleTable, Boolean includeSailngSchedule) throws DocumentException { PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f);// w w w. j a v a 2 s. c o m table.setHorizontalAlignment(Element.ALIGN_CENTER); if (includeSailngSchedule) { cell = new PdfPCell(new Phrase("Sailing Schedule", tableHeadingFont)); cell.setPaddingBottom(5); cell.setBackgroundColor(BaseColor.BLACK); cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(4); table.addCell(cell); cell = new PdfPCell(new Phrase("Vessel/Voyage", rowLabelFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Sail Date", rowLabelFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Transit Time", rowLabelFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Transshipment", rowLabelFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); for (int r = 0; r < sailingScheduleTable.getRowCount(); r++) { for (int c = 0; c < 4; c++) { Object sailingScheduleData = sailingScheduleTable.getValueAt(r, c); if (sailingScheduleData == null) { sailingScheduleData = " "; cell = new PdfPCell(new Phrase(String.valueOf(sailingScheduleData), textFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } else { cell = new PdfPCell(new Phrase(String.valueOf(sailingScheduleData), textFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } } } } return table; }
From source file:Print.Print.java
public void printIndex(ArrayList<String> imagesPath, String customer) { try {// w w w . j av a2s .c om //ArrayList<Image> images = new ArrayList<Image>(); Map<Image, String> dict = new HashMap<Image, String>(); for (String path : imagesPath) { try { System.out.println("path = /home/student" + path); int index = path.lastIndexOf("/"); String photoId = path.substring(index + 1, path.length()); Image newImage = Image.getInstance("/home/student" + path); //images.add(newImage); dict.put(newImage, photoId); } catch (BadElementException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } } System.out.println("Total images = " + dict.size()); Document index = new Document(PageSize.A4.rotate()); FileOutputStream fos = new FileOutputStream("/home/student/Pictures/index.pdf"); PdfWriter writer = PdfWriter.getInstance(index, fos); writer.open(); index.open(); PdfPTable adresTable = new PdfPTable(3); PdfPCell adresCell = new PdfPCell(new Paragraph(customer)); adresCell.setColspan(3); adresTable.addCell(adresCell); adresTable.setHorizontalAlignment(Element.ALIGN_CENTER); adresTable.setWidthPercentage(100); index.add(adresTable); PdfPTable table = new PdfPTable(imagesPath.size()); for (Map.Entry<Image, String> image : dict.entrySet()) { PdfPCell cell = new PdfPCell(); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(10); table.addCell(image.getValue()); cell.addElement(image.getKey()); table.addCell(cell); } index.add(table); //index.add(adresTable); index.close(); writer.close(); System.out.println("Index printed"); // // define pdfprinter and within try clause create // PdfWriter writer = null; // FileOutputStream fos = null; // Document index = new Document(PageSize.A4.rotate()); // File file; // try { // file = new File("/home/student/Pictures/index.pdf"); // if(!file.exists()){ // file.createNewFile(); // // } // String test = "test data"; // fos = new FileOutputStream(file); // fos.write(test.getBytes()); // fos.flush(); // } catch (FileNotFoundException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // // for (BufferedImage image : bufferedImages) { // try { // writer = PdfWriter.getInstance(index, fos); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } // writer.open(); // index.open(); // try { // PdfContentByte pdfCB = new PdfContentByte(writer); // Image newImage = Image.getInstance(pdfCB, image, 1); // index.add(Image.getInstance(newImage)); // } catch (DocumentException ex) { // System.out.println(ex.getMessage()); // } catch (IOException ex) { // Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); // } // } // index.close(); // writer.close(); // System.out.println("Index done."); } catch (DocumentException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } catch (FileNotFoundException ex) { Logger.getLogger(Print.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:projetohorus.DadosColetadosPDF.java
void GerarPDF() throws IOException, DocumentException, EmailException { Document doc = null;//from w w w.jav a2 s. co m OutputStream os = null; try { doc = new Document(PageSize.A4, 72, 72, 72, 72); os = new FileOutputStream("tesfinal11.pdf"); PdfWriter.getInstance(doc, os); doc.open(); Image img = Image.getInstance("LogoProject.png"); img.setAlignment(Element.ALIGN_CENTER); doc.add(img); InetAddress localHost = Inet4Address.getLocalHost(); NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localHost); short x = networkInterface.getInterfaceAddresses().get(0).getNetworkPrefixLength(); String n = localHost.getHostAddress() + "/" + x; SubnetUtils utils = new SubnetUtils(n); ; PdfPTable table = new PdfPTable(new float[] { 0.50f, 0.70f, 0.90f }); table = new PdfPTable(3); Paragraph p = new Paragraph(""); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); p = new Paragraph("Informaes da Network"); p.setAlignment(Element.ALIGN_CENTER); p.setSpacingAfter(30); doc.add(p); Paragraph paragraph = new Paragraph("" + utils.getInfo()); paragraph.setAlignment(Element.ALIGN_CENTER); paragraph.setSpacingAfter(30); doc.add(paragraph); table.setHorizontalAlignment(Element.ALIGN_CENTER); PdfPCell header = new PdfPCell(new Paragraph("Diagnostico do Scanner da Rede")); header.setColspan(3); table.addCell(header); table.addCell("IP"); table.addCell("HostName"); table.addCell("Portas Abertas"); for (int i = 0; i < IP.size(); i++) { table.addCell(IP.get(i)); table.addCell(NameHost.get(i)); table.addCell("" + PortasA.get(i)); } doc.add(table); } finally { if (doc != null) { doc.close(); } if (os != null) { os.close(); } } EnvioEmail sc = new EnvioEmail(); sc.EnvioEmail(); }
From source file:sandbox.columntext.DropTablePart.java
public void createPdf(String dest) throws IOException, DocumentException { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest)); document.open();/*from w w w . j ava2 s. c o m*/ Rectangle column = new Rectangle(36, 36, 559, 806); ColumnText ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); for (int i = 0; i < 4;) { PdfPTable table = new PdfPTable(new float[] { 0.25f, 0.25f, 0.25f, 0.25f }); table.setHorizontalAlignment(Element.ALIGN_LEFT); table.setWidthPercentage(100); PdfPCell cell = new PdfPCell(new Phrase("inner table " + (++i))); cell.setColspan(4); table.addCell(cell); for (int j = 0; j < 18; j++) { table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); table.addCell(new Phrase("test Data " + (j + 1) + ".1")); } ct.addElement(table); if (ColumnText.hasMoreText(ct.go())) { document.newPage(); ct = new ColumnText(writer.getDirectContent()); ct.setSimpleColumn(column); } } document.close(); }
From source file:servlet.AdministrarRestriccion.java
public void genDocTren(HttpServletRequest request, HttpServletResponse response) throws Exception { int linea = Integer.parseInt(request.getParameter("idLinea")); //PrintWriter salida = response.getWriter(); HttpSession session = request.getSession(); // PrintWriter out = response.getWriter(); Usuario usr = (Usuario) session.getAttribute("usuario"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try {//from ww w . j a v a 2s . c om String nota = new String(request.getParameter("nota").getBytes(), "UTF-8"); String nota2 = new String(request.getParameter("nota2").getBytes(), "UTF-8"); MaterialRodanteJpaController mrjc = new MaterialRodanteJpaController(Conex.getEmf()); MaterialRodante mr = mrjc .findMaterialRodante(Integer.parseInt(request.getParameter("materialRodante"))); String comunicaciones = new String(request.getParameter("comunicaciones").getBytes(), "UTF-8"); String instrucciones = new String(request.getParameter("instrucciones").getBytes(), "UTF-8"); String precauciones = new String(request.getParameter("precauciones").getBytes(), "UTF-8"); String nombre = new String(request.getParameter("nombre").getBytes(), "UTF-8"); String vigencia = request.getParameter("vigencia"); String[] fecha = vigencia.split("-"); LineaJpaController ljc = new LineaJpaController(Conex.getEmf()); Linea l = ljc.findLinea(linea); Document documento = new Document(PageSize.A4); com.itextpdf.text.Font arialNegrita = FontFactory.getFont("arial", 9, Font.BOLD); com.itextpdf.text.Font arial = FontFactory.getFont("arial", 9, Font.PLAIN); com.itextpdf.text.Font saltoDeLinea = FontFactory.getFont("arial", 5, Font.BOLD); Paragraph parrafo = new Paragraph(); int numResAs = 0; int numResDes = 0; RestriccionJpaController rjc = new RestriccionJpaController(Conex.getEmf()); List<Restriccion> restDes = rjc.buscarIdLineaDescendenteDocTren(linea, l.getVelocidadLinea()); List<Restriccion> restAsc = rjc.buscarIdLineaAscendenteDocTren(linea, l.getVelocidadLinea()); int restAscTotal = restAsc.size() - 1; int restDescTotal = restDes.size() - 1; System.out.println(restAscTotal); System.out.println(restDescTotal); PdfWriter.getInstance(documento, baos); documento.open(); do { try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tabla = new PdfPTable(1); tabla.setHorizontalAlignment(10); tabla.setWidthPercentage(100f); tabla.addCell(new Paragraph("Operaciones Del Tren: circular a una velocidad no mayor de " + l.getVelocidadLinea() + " Km/h", arial)); tabla.addCell(new Paragraph("Nota: " + nota, arial)); //tabla.getDefaultCell().setBorder(2); if (numResAs < restAscTotal) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.addCell(new Paragraph("Restricciones Ascendentes ", arialNegrita)); } tabla.getDefaultCell().setBorderColorBottom(BaseColor.WHITE); int c = 0; for (int i = numResAs; i <= restAscTotal; i++) { if (c > 30) { break; } // System.out.println("imrimiento asc: "+numResAs); int pkI = (int) (restAsc.get(numResAs).getProgInicio() / 1000); int pkI1 = (int) (((restAsc.get(numResAs).getProgInicio() / 1000) - pkI) * 1000); int pkF = (int) (restAsc.get(numResAs).getProgFinal() / 1000); int pkF1 = (int) (((restAsc.get(numResAs).getProgFinal() / 1000) - pkF) * 1000); tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restAsc.get(numResAs).getVelocidadMaxAscendente() + " " + restAsc.get(numResAs).getObservacion(), arial)); numResAs++; c++; } if (c < 30) { tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setBorder(14); tabla.addCell(new Paragraph("Restricciones Descendentes ", arialNegrita)); } int d = c; if (c < 30) { for (int i = numResDes; i <= restDescTotal; i++) { if (d > 30) { break; } tabla.getDefaultCell().setBorder(14); tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); int pkI = (int) (restDes.get(numResDes).getProgFinal() / 1000); int pkI1 = (int) (((restDes.get(numResDes).getProgFinal() / 1000) - pkI) * 1000); int pkF = (int) (restDes.get(numResDes).getProgInicio() / 1000); int pkF1 = (int) (((restDes.get(numResDes).getProgInicio() / 1000) - pkF) * 1000); tabla.addCell(new Paragraph("*PK " + pkI + "+" + pkI1 + " al " + pkF + "+" + pkF1 + " circular a una velocidad no mayor de " + restDes.get(numResDes).getVelocidadMaxDescendente() + " " + restDes.get(numResDes).getObservacion(), arial)); numResDes++; d++; } } int espacios = d; while (espacios < 30) { tabla.getDefaultCell().setBorderWidthBottom(0); tabla.getDefaultCell().setBorderWidthTop(0); tabla.addCell(new Paragraph(" ", arial)); espacios++; } tabla.getDefaultCell().setBorder(15); tabla.getDefaultCell().setBorderWidthBottom(1); tabla.getDefaultCell().setBorderWidthTop(1); tabla.getDefaultCell().setMinimumHeight(50f); tabla.addCell(new Paragraph("Instrucciones: " + instrucciones, arial)); tabla.addCell(new Paragraph("Comunicaciones: " + comunicaciones, arial)); tabla.addCell(new Paragraph("Precauciones: " + precauciones, arial)); tabla.getDefaultCell().setMinimumHeight(10f); tabla.addCell(new Paragraph("Vigencia A Partir De: " + fecha[0] + "/" + fecha[1] + "/" + fecha[2], arial)); tabla.getDefaultCell().setBorder(1); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString() + " - Gerencia de Gestin de Trfico", arialNegrita); preface.setAlignment(Element.ALIGN_CENTER); tabla.addCell(preface); tabla.getDefaultCell().setBorder(0); tabla.getDefaultCell().setVerticalAlignment(Element.ALIGN_CENTER); preface = new Paragraph(Paragraph.ALIGN_CENTER, "EL NO CUMPLIR CON LAS LIMITACIONES PRESCRITAS EN ESTE" + " DOCUMENTO VA EN CONTRA DE LA SEGURIDAD EN LA CIRCULACIN, POR LO TANTO SER? MOTIVO DE SANCIN", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Nota: Informacin sustentada con el informe tcnico " + "de limitaciones de velocidad, emitido por el CCF (Centro de Control de Fallas)", FontFactory.getFont("arial", 8f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "Sentido Ascendente: Sentido en el cual aumenta la progresiva ej: 0+0 -> 41+000 -- Sentido Descendente: Sentido en el cual disminuye la progresiva ej: 41+000 -> 0+0 ", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); preface = new Paragraph(Paragraph.ALIGN_CENTER, "En la lnea Caracas-Cua el sentido ASCENDENTE corresponde a la V?A PAR y el DESCENDENTE a la V?A IMPAR", FontFactory.getFont("arial", 6f)); tabla.addCell(preface); documento.add(tabla); if (numResAs < restAscTotal || numResDes < restDescTotal) { documento.newPage(); } } while (numResAs < restAscTotal || numResDes < restDescTotal); System.out.println("Termine"); //CARACTER?STICAS DE MATERIAL RODANTE documento.newPage(); try { URL url = getClass().getResource("/img/cintillo_s1.png"); Image foto = Image.getInstance(url); foto.scaleToFit(500, 70); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph("DOCUMENTO DE TREN: " + nombre, arialNegrita)); documento.add(new Paragraph( "L?NEA: " + l.getNombreLinea() + " : Documento Vlido Para Todos Los Trenes", arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add( new Paragraph("CARACTER?STICAS DE LA UNIDAD: " + mr.getNombreMaterialRodante(), arialNegrita)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable tablaMT = new PdfPTable(2); tablaMT.addCell(new Paragraph("ITEM", arialNegrita)); tablaMT.addCell(new Paragraph("DESCRIPCIN", arialNegrita)); tablaMT.addCell(new Paragraph("Nmero de Unidades Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroRemolque() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Nmero de Unidades Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getNumeroMotriz() + " Unidades", arial)); tablaMT.addCell(new Paragraph("Longitud Total", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudTotal() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Longitud Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getLongitudMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoMotriz() + " m", arial)); tablaMT.addCell(new Paragraph("Alto x Ancho Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getAltoXAnchoRemolque() + " m", arial)); tablaMT.addCell(new Paragraph("Masa o Tara Total", arial)); tablaMT.addCell(new Paragraph(mr.getMasa() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getMasaRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Masa Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getMasaMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Frenado", arial)); tablaMT.addCell(new Paragraph(mr.getFrenadoDescripcion() + "", arial)); tablaMT.addCell(new Paragraph("Trocha", arial)); tablaMT.addCell(new Paragraph(l.getTrocha() + " m", arial)); tablaMT.addCell(new Paragraph("Velocidad Comercial", arial)); tablaMT.addCell(new Paragraph(mr.getVelocidadOperativa() + " Km/h", arial)); tablaMT.addCell(new Paragraph("Aceleracin Mx.", arial)); tablaMT.addCell(new Paragraph(mr.getAceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracin de Servicio", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionMax() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Desaceleracion de Emergencia", arial)); tablaMT.addCell(new Paragraph(mr.getDesaceleracionEmergencia() + " m/s^2", arial)); tablaMT.addCell(new Paragraph("Voltaje", arial)); tablaMT.addCell(new Paragraph(mr.getVoltaje() + " V", arial)); tablaMT.addCell(new Paragraph("Voltaje de Bateras", arial)); tablaMT.addCell(new Paragraph(mr.getVoltajeBateria() + " V", arial)); tablaMT.addCell(new Paragraph("Presin de Trabajo", arial)); tablaMT.addCell(new Paragraph(mr.getPresionTrabajo() + "", arial)); if (mr.getSubTipo().equals("Tren de Viajeros")) { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " pasajeros", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " pasajeros", arial)); } else { tablaMT.addCell(new Paragraph("Capacidad Coche Remolque", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadRemolque() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Coche Motriz", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadMotriz() + " t", arial)); tablaMT.addCell(new Paragraph("Capacidad Total", arial)); tablaMT.addCell(new Paragraph(mr.getCapacidadPasajeros() + " t", arial)); } documento.add(tablaMT); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); try { URL url = getClass().getResource("/img/" + request.getParameter("materialRodante") + ".jpg"); Image foto = Image.getInstance(url); foto.scaleToFit(300, 300); foto.setAlignment(Chunk.ALIGN_MIDDLE); documento.add(foto); } catch (Exception e) { e.printStackTrace(); } documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); PdfPTable t = new PdfPTable(1); t.setWidthPercentage(100f); t.addCell("Nota: " + nota2); documento.add(t); documento.add(new Paragraph(" ", saltoDeLinea)); documento.add(new Paragraph(" ", saltoDeLinea)); Paragraph preface = new Paragraph(Paragraph.ALIGN_CENTER, "Realizado Por: " + usr.toString(), arialNegrita); documento.add(preface); documento.close(); response.addHeader("Content-Disposition", "attachment; filename=DocumentoDeTren.pdf"); response.addHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.addHeader("Pragma", "public"); response.setContentType("application/pdf"); DataOutput output = new DataOutputStream(response.getOutputStream()); byte[] bytes = baos.toByteArray(); response.setContentLength(bytes.length); for (int i = 0; i < bytes.length; i++) { output.writeByte(bytes[i]); } } catch (Exception e) { e.printStackTrace(); // salida.print("http://localhost:8084/MODULO2.3/img/error.png"); } }
From source file:servlet.PdfGenerator.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.// w w w . j a v a2s . co m * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Document report = new Document(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PdfWriter.getInstance(report, baos); DBManager manager = (DBManager) getServletContext().getAttribute("dbmanager"); Group groupToReport = manager.getGroup(Integer.parseInt(request.getParameter("id"))); LinkedList<User> groupUsers = manager.getUsersForGroupAndVisible(groupToReport.getId()); Timestamp lastPosted = manager.getLatestPost(groupToReport); int numberOfPosts = manager.getGroupPosts(groupToReport).size(); String context = request.getServletContext().getRealPath("/"); Iterator<User> groupIterator = groupUsers.iterator(); report.open(); // INSERTING DOCUMENT CONTENT AREA Font title = FontFactory.getFont(FontFactory.HELVETICA_BOLD, 24); Font text = FontFactory.getFont(FontFactory.HELVETICA, 12); Paragraph documentHead = new Paragraph(groupToReport.getName(), title); Paragraph newLine = new Paragraph(Chunk.NEWLINE); Paragraph latestPost = new Paragraph("Latest post inserted on: " + lastPosted, text); Paragraph postsNumberToReport = new Paragraph("Number of posts: " + numberOfPosts, text); //LAYOUT AND FINAL PARAGRAPH EDITING AREA report.add(documentHead); report.add(newLine); report.add(postsNumberToReport); report.add(newLine); report.add(latestPost); report.add(newLine); PdfPTable usersTable = new PdfPTable(5); // LOOP FOR SETTING TABLE while (groupIterator.hasNext()) { User u = groupIterator.next(); String userName = u.getName(); PdfPCell avatarCell = new PdfPCell(Image.getInstance(context + u.getAvatar(request))); avatarCell.setBorder(0); avatarCell.setPaddingBottom(10); avatarCell.setColspan(1); PdfPCell userNameCell = new PdfPCell(new Phrase(userName)); userNameCell.setColspan(4); userNameCell.setBorder(0); userNameCell.setPaddingBottom(10); userNameCell.setPaddingLeft(10); usersTable.addCell(avatarCell); usersTable.addCell(userNameCell); } usersTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); report.add(usersTable); report.close(); // SETTING SOME RESPONSE HEADER response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // SETTING THE CONTENT TYPE response.setContentType("application/pdf"); // THE CONTENTLENGHT response.setContentLength(baos.size()); System.out.println("ci sono"); try (OutputStream os = response.getOutputStream()) { baos.writeTo(os); os.flush(); os.close(); } catch (Exception e) { throw new IOException(e.getMessage()); } } catch (DocumentException e) { throw new IOException(e.getMessage()); } }
From source file:view.PrincipalView.java
public void gerarDocumento() throws IOException, DocumentException { doc = new Document(PageSize.A4.rotate()); String caminho = "C:/RelatoriosAgenda/Ficha.pdf"; PdfWriter.getInstance(doc, new FileOutputStream(caminho)); doc.open();/* w w w . ja v a 2 s .c o m*/ PdfPTable tabela = new PdfPTable(1); tabela.setHorizontalAlignment(Element.ALIGN_RIGHT); tabela.setWidthPercentage(100f); tabela.setTotalWidth(472); tabela.setLockedWidth(true); Paragraph pNome = new Paragraph("" + tfdNome.getText() + "\n" + tfdSobrenome.getText() + "\n \n"); pNome.setAlignment(Element.ALIGN_JUSTIFIED); PdfPCell colNome = new PdfPCell(pNome); tabela.addCell(colNome); doc.add(tabela); JOptionPane.showMessageDialog(null, "Relatrio de Funcionrios salvo com sucesso em C:/RelatoriosAgenda/"); Desktop.getDesktop().open(new File(caminho)); doc.close(); }