List of usage examples for com.itextpdf.text Image setAbsolutePosition
public void setAbsolutePosition(final float absoluteX, final float absoluteY)
Image
. From source file:PDFIMG.IMAGEStoPDF.java
public static void convertToIMG(String[] RESOURCES, String result, String path, int s) throws FileNotFoundException, DocumentException, BadElementException, IOException { System.out.println(":)"); // step 1/*from w w w .j a v a 2 s . c o m*/ Document document = new Document(); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(result)); // step 3 document.open(); // step 4 // Adding a series of images Image img; System.out.println(":) :)"); for (String image : RESOURCES) { System.out.println(image); img = Image.getInstance(path + image); document.setPageSize(img); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); System.out.println(":("); } System.out.println(":) :) :) Pdf is outo"); // step 5 document.close(); if (s == 1) { JOptionPane.showMessageDialog(null, "Converted Successfully"); //JOptionPane.showMessageDialog(null, "Finished\nFile save in :\nC:\\DjVu++Task\\ImagestoPDF\\"+RESOURCES[0].substring(0,RESOURCES[0].lastIndexOf("."))+".pdf"); } }
From source file:pkgAgenda_Virtual.frmActividades.java
public void PDFpersonales() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;// w ww. j av a2 s .com try { FacturaPdf = new FileOutputStream("archives/ActividadesPersonales.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Personales de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tblHoy = new PdfPTable(4); PdfPTable tblAntes = new PdfPTable(4); PdfPTable tblDespues = new PdfPTable(4); tblHoy.addCell("Titulo"); tblHoy.addCell("Fecha"); tblHoy.addCell("Hora"); tblHoy.addCell("Lugar"); tblAntes.addCell("Titulo"); tblAntes.addCell("Fecha"); tblAntes.addCell("Hora"); tblAntes.addCell("Lugar"); tblDespues.addCell("Titulo"); tblDespues.addCell("Fecha"); tblDespues.addCell("Hora"); tblDespues.addCell("Lugar"); //sdfhfjhsdfsd int valor; rs = H.Buscar("SELECT nom_act, fecha_act, hora_act, lugar_act FROM Actividades WHERE cod_usu = " + H.Usuario + " AND id_tipoact = 2"); while (rs.next()) { String fecharecibida = rs.getString(2).substring(0, 10); valor = H.FechaAnterior(fecharecibida); if (valor == 2) { tblHoy.addCell(H.desencriptar(rs.getString(1))); tblHoy.addCell(fecharecibida); tblHoy.addCell(rs.getString(3).substring(0, 5)); tblHoy.addCell(H.desencriptar(rs.getString(4))); } else if (valor == 1) { tblAntes.addCell(H.desencriptar(rs.getString(1))); tblAntes.addCell(fecharecibida); tblAntes.addCell(rs.getString(3).substring(0, 5)); tblAntes.addCell(H.desencriptar(rs.getString(4))); } else if (valor == 0) { tblDespues.addCell(H.desencriptar(rs.getString(1))); tblDespues.addCell(fecharecibida); tblDespues.addCell(rs.getString(3).substring(0, 5)); tblDespues.addCell(H.desencriptar(rs.getString(4))); } } //askjdhskfjhdf documento.add(new Paragraph("Actividades Pasadas")); documento.add(new Paragraph(" ")); documento.add(tblAntes); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Hoy")); documento.add(new Paragraph(" ")); documento.add(tblHoy); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Futuras")); documento.add(new Paragraph(" ")); documento.add(tblDespues); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgAgenda_Virtual.frmActividades.java
public void PDFdeestudio() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;/*from www.j a v a2 s . c om*/ try { FacturaPdf = new FileOutputStream("archives/ActividadesdeEstudio.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Estudio de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tblHoy = new PdfPTable(4); PdfPTable tblAntes = new PdfPTable(4); PdfPTable tblDespues = new PdfPTable(4); tblHoy.addCell("Asignatura"); tblHoy.addCell("Tarea"); tblHoy.addCell("Fecha"); tblHoy.addCell("Hora"); tblAntes.addCell("Asignatura"); tblAntes.addCell("Tarea"); tblAntes.addCell("Fecha"); tblAntes.addCell("Hora"); tblDespues.addCell("Asignatura"); tblDespues.addCell("Tarea"); tblDespues.addCell("Fecha"); tblDespues.addCell("Hora"); //sdfhfjhsdfsd int valor; rs = H.Buscar("SELECT nom_act, des_act, fecha_act, hora_act FROM Actividades WHERE cod_usu = " + H.Usuario + " AND id_tipoact = 1"); while (rs.next()) { String fecharecibida = rs.getString(3).substring(0, 10); valor = H.FechaAnterior(fecharecibida); if (valor == 2) { tblHoy.addCell(H.desencriptar(rs.getString(1))); tblHoy.addCell(H.desencriptar(rs.getString(2))); tblHoy.addCell(fecharecibida); tblHoy.addCell(rs.getString(4).substring(0, 5)); } else if (valor == 1) { tblAntes.addCell(H.desencriptar(rs.getString(1))); tblAntes.addCell(H.desencriptar(rs.getString(2))); tblAntes.addCell(fecharecibida); tblAntes.addCell(rs.getString(4).substring(0, 5)); } else if (valor == 0) { tblDespues.addCell(H.desencriptar(rs.getString(1))); tblDespues.addCell(H.desencriptar(rs.getString(2))); tblDespues.addCell(fecharecibida); tblDespues.addCell(rs.getString(4).substring(0, 5)); } } //askjdhskfjhdf documento.add(new Paragraph("Actividades Pasadas")); documento.add(new Paragraph(" ")); documento.add(tblAntes); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades de Hoy")); documento.add(new Paragraph(" ")); documento.add(tblHoy); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Actividades Futuras")); documento.add(new Paragraph(" ")); documento.add(tblDespues); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pkgAgenda_Virtual.frmAgenda.java
public void PDF() throws SQLException { Document documento = new Document(); FileOutputStream FacturaPdf;//from w ww .j ava 2 s . c om try { FacturaPdf = new FileOutputStream("archives/Notas.pdf"); PdfWriter writer = PdfWriter.getInstance(documento, FacturaPdf); com.itextpdf.text.Rectangle rct = new com.itextpdf.text.Rectangle(36, 54, 559, 788); writer.setBoxSize("art", rct); HeaderFooter event = new HeaderFooter(); writer.setPageEvent(event); } catch (DocumentException | FileNotFoundException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } try { Calendar fecha = Calendar.getInstance(); documento.open(); com.itextpdf.text.Image imagen = com.itextpdf.text.Image.getInstance("archives\\AgendaVirtual.png"); imagen.setAbsolutePosition(0f, 0f); documento.add(imagen); Paragraph AV = new Paragraph("Agenda Virtual", FontFactory.getFont("Segoe UI", 22, Font.NORMAL, BaseColor.BLACK)); AV.setAlignment(Element.ALIGN_RIGHT); documento.add(AV); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph("Notas de " + frmLogin.usuario)); documento.add(new Paragraph("Fecha de Reporte: " + fecha.get(Calendar.DAY_OF_MONTH) + "/" + fecha.get(Calendar.MONTH) + "/" + fecha.get(Calendar.YEAR) + " " + fecha.get(Calendar.HOUR_OF_DAY) + ":" + fecha.get(Calendar.MINUTE))); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); PdfPTable tabla = new PdfPTable(2); tabla.addCell("Titulo"); tabla.addCell("Descripcion"); //sdfhfjhsdfsd rs = H.Buscar( "SELECT nom_nota, des_nota FROM Notas WHERE cod_usu = " + H.Usuario + " ORDER BY nom_nota ASC"); while (rs.next()) { tabla.addCell(rs.getString(1)); tabla.addCell(rs.getString(2)); } //askjdhskfjhdf documento.add(tabla); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(new Paragraph(" ")); documento.add(P); documento.close(); } catch (DocumentException | IOException ex) { JOptionPane.showMessageDialog(null, ex.toString()); } }
From source file:pl.marcinmilkowski.hocrtopdf.Main.java
License:Open Source License
/** * @param args//from ww w . j a v a 2 s . c o m */ public static void main(String[] args) { try { if (args.length < 1 || args[0] == "--help" || args[0] == "-h") { System.out.print("Usage: java pl.marcinmilkowski.hocrtopdf.Main INPUTURL.html OUTPUTURL.pdf\n" + "\n" + "Converts hOCR files into PDF\n" + "\n" + "Example: java pl.marcinmilkowski.hocrtopdf.Main hocr.html output.pdf\n"); if (args.length < 1) System.exit(-1); else System.exit(0); } URL inputHOCRFile = null; FileOutputStream outputPDFStream = null; try { File file = new File(args[0]); inputHOCRFile = file.toURI().toURL(); } catch (MalformedURLException e) { System.out.println("The first parameter has to be a valid file."); System.out.println("We got an error: " + e.getMessage()); System.exit(-1); } try { outputPDFStream = new FileOutputStream(args[1]); } catch (FileNotFoundException e) { System.out.println("The second parameter has to be a valid URL"); System.exit(-1); } // The resolution of a PDF file (using iText) is 72pt per inch float pointsPerInch = 72.0f; // Using the jericho library to parse the HTML file Source source = new Source(inputHOCRFile); int pageCounter = 1; Document pdfDocument = null; PdfWriter pdfWriter = null; PdfContentByte cb = null; RandomAccessFileOrArray ra = null; // Find the tag of class ocr_page in order to load the scanned image StartTag pageTag = source.getNextStartTag(0, "class", OCRPAGE); while (pageTag != null) { int prevPos = pageTag.getEnd(); Pattern imagePattern = Pattern.compile("image\\s+([^;]+)"); Matcher imageMatcher = imagePattern.matcher(pageTag.getElement().getAttributeValue("title")); if (!imageMatcher.find()) { System.out.println("Could not find a tag of class \"ocr_page\", aborting."); System.exit(-1); } // Load the image Image pageImage = null; try { File file = new File(imageMatcher.group(1)); pageImage = Image.getInstance(file.toURI().toURL()); } catch (MalformedURLException e) { System.out.println("Could not load the scanned image from: " + "file://" + imageMatcher.group(1) + ", aborting."); System.exit(-1); } if (pageImage.getOriginalType() == Image.ORIGINAL_TIFF) { // this might // be // multipage // tiff! File file = new File(imageMatcher.group(1)); if (pageCounter == 1 || ra == null) { ra = new RandomAccessFileOrArray(file.toURI().toURL()); } int nPages = TiffImage.getNumberOfPages(ra); if (nPages > 0 && pageCounter <= nPages) { pageImage = TiffImage.getTiffImage(ra, pageCounter); } } int dpiX = pageImage.getDpiX(); if (dpiX == 0) { // for images that don't set the resolution we assume // 300 dpi dpiX = 300; } int dpiY = pageImage.getDpiY(); if (dpiY == 0) { // as above for dpiX dpiY = 300; } float dotsPerPointX = dpiX / pointsPerInch; float dotsPerPointY = dpiY / pointsPerInch; float pageImagePixelHeight = pageImage.getHeight(); if (pdfDocument == null) { pdfDocument = new Document(new Rectangle(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY)); pdfWriter = PdfWriter.getInstance(pdfDocument, outputPDFStream); pdfDocument.open(); // Put the text behind the picture (reverse for debugging) // cb = pdfWriter.getDirectContentUnder(); cb = pdfWriter.getDirectContent(); } else { pdfDocument.setPageSize(new Rectangle(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY)); pdfDocument.newPage(); } // first define a standard font for our text BaseFont base = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); Font defaultFont = new Font(base, 8); // FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD, // CMYKColor.BLACK); cb.setHorizontalScaling(1.0f); pageImage.scaleToFit(pageImage.getWidth() / dotsPerPointX, pageImage.getHeight() / dotsPerPointY); pageImage.setAbsolutePosition(0, 0); // Put the image in front of the text (reverse for debugging) // pdfWriter.getDirectContent().addImage(pageImage); pdfWriter.getDirectContentUnder().addImage(pageImage); // In order to place text behind the recognised text snippets we are // interested in the bbox property Pattern bboxPattern = Pattern.compile("bbox(\\s+\\d+){4}"); // This pattern separates the coordinates of the bbox property Pattern bboxCoordinatePattern = Pattern.compile("(\\d+)\\s+(\\d+)\\s+(\\d+)\\s+(\\d+)"); // Only tags of the ocr_line class are interesting StartTag ocrTag = source.getNextStartTag(prevPos, "class", OCRPAGEORLINE); while (ocrTag != null) { prevPos = ocrTag.getEnd(); if ("ocrx_word".equalsIgnoreCase(ocrTag.getAttributeValue("class"))) { net.htmlparser.jericho.Element lineElement = ocrTag.getElement(); Matcher bboxMatcher = bboxPattern.matcher(lineElement.getAttributeValue("title")); if (bboxMatcher.find()) { // We found a tag of the ocr_line class containing a bbox property Matcher bboxCoordinateMatcher = bboxCoordinatePattern.matcher(bboxMatcher.group()); bboxCoordinateMatcher.find(); int[] coordinates = { Integer.parseInt((bboxCoordinateMatcher.group(1))), Integer.parseInt((bboxCoordinateMatcher.group(2))), Integer.parseInt((bboxCoordinateMatcher.group(3))), Integer.parseInt((bboxCoordinateMatcher.group(4))) }; String line = lineElement.getContent().getTextExtractor().toString(); float bboxWidthPt = (coordinates[2] - coordinates[0]) / dotsPerPointX; float bboxHeightPt = (coordinates[3] - coordinates[1]) / dotsPerPointY; // Put the text into the PDF cb.beginText(); // Comment the next line to debug the PDF output (visible Text) cb.setTextRenderingMode(PdfContentByte.TEXT_RENDER_MODE_INVISIBLE); // height cb.setFontAndSize(defaultFont.getBaseFont(), Math.max(Math.round(bboxHeightPt), 1)); // width cb.setHorizontalScaling(bboxWidthPt / cb.getEffectiveStringWidth(line, false)); cb.moveText((coordinates[0] / dotsPerPointX), ((pageImagePixelHeight - coordinates[3]) / dotsPerPointY)); cb.showText(line); cb.endText(); cb.setHorizontalScaling(1.0f); } } else { if ("ocr_page".equalsIgnoreCase(ocrTag.getAttributeValue("class"))) { pageCounter++; pageTag = ocrTag; break; } } ocrTag = source.getNextStartTag(prevPos, "class", OCRPAGEORLINE); } if (ocrTag == null) { pdfDocument.close(); break; } } } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:presentation.frmReportForm.java
private void btnGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGenerateActionPerformed Date dateNow = new Date(); SimpleDateFormat df = new SimpleDateFormat("dd_MM_yyyy_HH_mm_ss"); System.out.println(dtcMonthChooser.getMonth()); System.out.println(dtcYearChooser.getYear()); if (radInMonth.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchRecordByMonth(dtcMonthChooser.getMonth() + 1, dtcYearChooser.getYear()); Document document = new Document(); try {/*w ww . j ava 2 s . c o m*/ Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records at " + (dtcMonthChooser.getMonth() + 1) + "/" + dtcYearChooser.getYear(), FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInDateRange.isSelected()) { try { List<Transfer> transferList = new ArrayList<>(); java.sql.Date fromDateSql = formatDateForSearching(dtcFromDate.getDate()); java.sql.Date toDateSql = formatDateForSearching(dtcToDate.getDate()); transferList = empObj.searchRecordByDate(fromDateSql, toDateSql); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); SimpleDateFormat df2 = new SimpleDateFormat("dd/MM/yyyy"); String fromDate = df2.format(dtcFromDate.getDate()); String toDate = df2.format(dtcToDate.getDate()); Paragraph slashPara = new Paragraph("Transfer records from " + fromDate + " to " + toDate, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } catch (ParseException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radInProject.isSelected()) { String fromProjectId = (String) cbxFromProject.getSelectedItem(); String toProjectId = (String) cbxToProject.getSelectedItem(); List<Transfer> transferList = new ArrayList<>(); String andOr = ""; if (cbxAndOr.getSelectedItem().equals("And")) { andOr = "and"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } else { andOr = "or"; transferList = empObj.searchRecordByFromAndToProject(fromProjectId, toProjectId, andOr); } Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph( "Transfer records from Project ID " + fromProjectId + " " + andOr + " " + toProjectId, FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } if (radAllRecord.isSelected()) { List<Transfer> transferList = new ArrayList<>(); transferList = empObj.searchAllRecord(); Document document = new Document(); try { Font fontTitle = new Font(FontFamily.HELVETICA, 20, Font.BOLD); String fileName = "../EMPtranfermanagement/Report" + " " + df.format(dateNow) + ".pdf"; PdfWriter.getInstance(document, new FileOutputStream(fileName)); document.open(); Image imageLogo = Image .getInstance(this.getClass().getResource("/images/onlinelogomaker-afterscale2.png")); imageLogo.setAbsolutePosition(20, 750f); document.add(imageLogo); Paragraph titlePara = new Paragraph("EMP Transfer Application", fontTitle); titlePara.setAlignment(Element.ALIGN_CENTER); titlePara.setSpacingAfter(5); document.add(titlePara); Paragraph creditPara = new Paragraph("Created by Ly Thanh Hai + Nguyen Khanh", FontFactory.getFont(FontFactory.HELVETICA, 10, Font.ITALIC)); creditPara.setAlignment(Element.ALIGN_CENTER); creditPara.setSpacingAfter(10); document.add(creditPara); Paragraph slashPara = new Paragraph("All transfer records", FontFactory.getFont(FontFactory.HELVETICA, 15, Font.BOLD)); slashPara.setSpacingAfter(40); slashPara.setAlignment(Element.ALIGN_CENTER); document.add(slashPara); PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); Font font = new Font(FontFamily.HELVETICA, 15, Font.BOLD); Paragraph paragraphCellHeading = new Paragraph("Report", font); PdfPCell cellHeading = new PdfPCell(paragraphCellHeading); BaseColor myColor = WebColors.getRGBColor("#41a5c2"); cellHeading.setColspan(5); cellHeading.setBackgroundColor(myColor); cellHeading.setFixedHeight(30.3f); cellHeading.setVerticalAlignment(Element.ALIGN_MIDDLE); cellHeading.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellHeading); Font fBody = new Font(FontFamily.HELVETICA, 13, Font.NORMAL, GrayColor.BLACK); PdfPCell cellTitle1 = new PdfPCell(new Phrase("Transfer ID", fBody)); cellTitle1.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle1.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle1); PdfPCell cellTitle2 = new PdfPCell(new Phrase("Emp ID", fBody)); cellTitle2.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle2.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle2); PdfPCell cellTitle3 = new PdfPCell(new Phrase("From Project", fBody)); cellTitle3.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle3.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle3); PdfPCell cellTitle4 = new PdfPCell(new Phrase("To Project", fBody)); cellTitle4.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitle4.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitle4); PdfPCell cellTitleStatus = new PdfPCell(new Phrase("Status", fBody)); cellTitleStatus.setVerticalAlignment(Element.ALIGN_MIDDLE); cellTitleStatus.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTitleStatus); int cellColorCheck = 1; for (Transfer e : transferList) { PdfPCell cellBody1 = new PdfPCell(new Phrase(e.getId())); PdfPCell cellBody2 = new PdfPCell(new Phrase(e.getEmployeeId())); PdfPCell cellBody3 = new PdfPCell(new Phrase(e.getFromProjectId())); PdfPCell cellBody4 = new PdfPCell(new Phrase(e.getToProjectId())); PdfPCell cellBody5 = new PdfPCell(new Phrase(e.getStatus())); if (cellColorCheck % 2 == 1) { cellBody1.setBackgroundColor(BaseColor.ORANGE); cellBody2.setBackgroundColor(BaseColor.ORANGE); cellBody3.setBackgroundColor(BaseColor.ORANGE); cellBody4.setBackgroundColor(BaseColor.ORANGE); cellBody5.setBackgroundColor(BaseColor.ORANGE); } table.addCell(cellBody1); table.addCell(cellBody2); table.addCell(cellBody3); table.addCell(cellBody4); table.addCell(cellBody5); cellColorCheck++; } document.add(table); JOptionPane.showMessageDialog(this, "Report saved"); if (Desktop.isDesktopSupported()) { File reportFile = new File(fileName); Desktop.getDesktop().open(reportFile); ; } document.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(frmReportForm.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:printInv.GenerateInvoice.java
public void generateLayout(Document doc, PdfContentByte cb) { try {//from w w w . j a v a 2s .co m cb.setLineWidth(1f); // Invoice Header box layout cb.rectangle(420, 700, 150, 60); cb.moveTo(420, 720); cb.lineTo(570, 720); cb.moveTo(420, 740); cb.lineTo(570, 740); cb.moveTo(480, 700); cb.lineTo(480, 760); cb.stroke(); // Invoice Header box Text Headings createHeadings(cb, 422, 743, "Invoice No."); createHeadings(cb, 422, 723, "Name"); createHeadings(cb, 422, 703, "Invoice Date"); // Invoice Detail box layout cb.rectangle(20, 50, 550, 600); cb.moveTo(20, 630); cb.lineTo(570, 630); cb.moveTo(50, 50); cb.lineTo(50, 650); cb.moveTo(360, 50); cb.lineTo(360, 650); cb.moveTo(430, 50); cb.lineTo(430, 650); cb.moveTo(500, 50); cb.lineTo(500, 650); cb.stroke(); // Invoice Detail box Text Headings createHeadings(cb, 22, 633, "SNo."); createHeadings(cb, 52, 633, "Product ID"); createHeadings(cb, 362, 633, "Quantity"); createHeadings(cb, 432, 633, "Unit Price"); createHeadings(cb, 502, 633, "Line Total"); //add the images Image companyLogo = Image.getInstance("src/image/icon.png"); companyLogo.setAbsolutePosition(25, 700); companyLogo.scalePercent(25); doc.add(companyLogo); } catch (DocumentException dex) { dex.printStackTrace(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:printom.PDFCreator.java
public static void createBOL(ArrayList<Shipment> aShipmentList, int aTemplate) { ArrayList<Shipment> shipmentList = aShipmentList; Order chosenOrder = shipmentList.get(0).getChosenOrder(); String bolCode = shipmentList.get(0).getBolCode(); String bolFileName = bolCode + ".pdf"; String myCustName = Customer.getCustomerName(chosenOrder.getCustID()); String myShipDate = Prompter.dateString(shipmentList.get(0).getDateShipped()); String myCarrier = shipmentList.get(0).getCarrier(); String myInstructs = shipmentList.get(0).getInstructions(); Address myAddress = Address.retAddress(shipmentList.get(0).getChosenOrder().getShipAddressID()); try {// w w w .ja v a 2s . co m //BaseFont bf1 = BaseFont.createFont("c:/windows/fonts/consola.ttf", //BaseFont.WINANSI, BaseFont.EMBEDDED); Font timesJob = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD, BaseColor.WHITE); Font timesDef = new Font(Font.FontFamily.TIMES_ROMAN, 16, Font.NORMAL, BaseColor.BLACK); Font courierNorm = new Font(Font.FontFamily.COURIER, 11, Font.NORMAL, BaseColor.BLACK); Font courierSBig = new Font(Font.FontFamily.COURIER, 13, Font.NORMAL, BaseColor.BLACK); // step 1 Document document = new Document(PageSize.LETTER, 18, 18, 126, 54); // step 2 PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(bolFileName)); // step 3 document.open(); // step 4 // we set the compression to 0 so that we can read the PDF syntax writer.setCompressionLevel(0); // writes something to the direct content using a convenience method PdfContentByte canvas = writer.getDirectContentUnder(); // Graphic Letterheard Image image = Image.getInstance("AresLH.jpg"); image.scalePercent(50f); image.setAbsolutePosition(43, 680); if (aTemplate == 1) document.add(image); // 11" = 792 // 8.5 = 612 // TEXT SIZE = 11 // LINE SPACING = 11 // PARAGRAPH SPACE = 3 * 11 int myPageWidth = 612; int myPageHeight = 792; int myTopMargin = 655; int myTopSubMargin = 622; int myPageLeftMargin = 54; // HEADER LINES ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ARES BOL# " + bolCode, courierNorm), myPageLeftMargin, myTopMargin, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("DATE: " + myShipDate, courierNorm), myPageWidth - myPageLeftMargin, myTopMargin, 0); // CONSIGNEE ADDRESS int myAddressStartY = myTopSubMargin; int myCurrentY = myTopSubMargin; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CONSIGNEE", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ADDRESS:", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY = myAddressStartY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getAttention(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getAddress1(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getCity() + ", " + myAddress.getState() + " " + myAddress.getZipCode(), courierNorm), 125, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(myAddress.getLastLine(), courierNorm), 125, myCurrentY, 0); // FROM ADDRESS myCurrentY = myAddressStartY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FROM:", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Ares Printing & Packaging", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("63 Flushing Ave, Bldg 5", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn Navy Yard", courierNorm), 98 + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("Brooklyn, NY 11205", courierNorm), 98 + 288, myCurrentY, 0); // CARRIER, FOB AND SPECIAL INSTRUCTIONS myCurrentY -= 33; int myItemStartY = myCurrentY; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CARRIER: " + myCarrier, courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("FOB: Brooklyn", courierNorm), myPageLeftMargin, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("SPECIAL INSTRUCTIONS: " + myInstructs, courierNorm), myPageLeftMargin, myCurrentY, 0); int myBOLTPallets = 0; int myBOLTCases = 0; int myBOLTPieces = 0; myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); // Start Item/ShipLine Information for (Shipment shipment : shipmentList) { ArrayList<Inventory> shipInventoryList = shipment.getInvenList(); ArrayList<Inventory.InventoryLine> invenLineList = new ArrayList<>(); Item item = new Item(shipInventoryList.get(0).getItemID()); String apo = ""; for (int i = 0; i < shipInventoryList.size(); i++) { if (i == 0) { apo += shipInventoryList.get(i).getJobNum(); } else { apo += ", " + shipInventoryList.get(i).getJobNum(); } invenLineList.addAll(shipInventoryList.get(i).getInvenLines()); } //START ITEM myCurrentY -= 22; if (myCurrentY < 100) { document.newPage(); if (aTemplate == 1) { document.add(image); } myCurrentY = myTopSubMargin; } ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: " + item.getItemName(), courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: " + chosenOrder.getPOrderNum(), courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: " + item.getItemCode(), courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: " + apo, courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; int myItemTPallets = 0; int myItemTCases = 0; int myItemTPieces = 0; for (Inventory.InventoryLine invenLine : invenLineList) { ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getPallets()), courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getCases()), courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase(String.valueOf(invenLine.getPieces()), courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; myItemTPallets += invenLine.getPallets(); myItemTCases += invenLine.getPallets() * invenLine.getCases(); myItemTPieces += invenLine.getPallets() * invenLine.getCases() * invenLine.getPieces(); myBOLTPallets += myItemTPallets; myBOLTCases += myItemTCases; myBOLTPieces += myItemTPieces; } myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned( canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: " + myItemTPallets + " CASES: " + myItemTCases + " QUANTITY: " + myItemTPieces, courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// /* //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); ////////////// //END ITEM ////////////// myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ////////////// //START ITEM ////////////// ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// */ ////////////// //START FOOTER ////////////// myCurrentY -= 33; if (myCurrentY < 85) { document.newPage(); myCurrentY = myTopSubMargin; } ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("SHIPMENT RECEIVED IN GOOD CONDITION BY:", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("______________________________________", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY -= 16; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("(SIGNATURE) (DATE & TIME)", courierNorm), myPageLeftMargin + 128, myCurrentY, 0); myCurrentY += 49; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL PALLETS: " + myBOLTPallets, courierSBig), myPageLeftMargin + 500, myCurrentY, 0); myCurrentY -= 13; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL CASES: " + myBOLTCases, courierSBig), myPageLeftMargin + 500, myCurrentY, 0); myCurrentY -= 13; ColumnText.showTextAligned(canvas, Element.ALIGN_RIGHT, new Phrase("TOTAL WEIGHT: ~" + ((myBOLTCases * 25) + (myBOLTPallets * 40)) + " lbs", courierSBig), myPageLeftMargin + 500, myCurrentY, 0); ////////////// //END FOOTER ////////////// /* document.newPage(); myCurrentY = myTopSubMargin; ////////////// //START ITEM ////////////// ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); //START ITEM myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM NAME: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("CUSTOMER PO#: 2011444", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM CODE: ZCART-248", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("APO: 14900", courierNorm), myPageLeftMargin + 288, myCurrentY, 0); myCurrentY -= 22; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pallets", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Cases per pallet", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("Pieces per case", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 6; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); // ITEM 1 myCurrentY -= 12; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("11", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("24", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); // LINE 2 myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("1", courierNorm), myPageLeftMargin + 115, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 150, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("18", courierNorm), myPageLeftMargin + 215, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("@", courierNorm), myPageLeftMargin + 281, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, new Phrase("180", courierNorm), myPageLeftMargin + 340, myCurrentY, 0); myCurrentY -= 1; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("_______________________________________________", courierNorm), myPageLeftMargin + 85, myCurrentY, 0); myCurrentY -= 33; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("ITEM TOTALS:", courierNorm), myPageLeftMargin, myCurrentY, 0); ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase(" PALLETS: 12 CASES: 282 QUANTITY: 50,760", courierNorm), myPageLeftMargin + 95, myCurrentY, 0); myCurrentY -= 11; ColumnText.showTextAligned(canvas, Element.ALIGN_LEFT, new Phrase("---------------------------------------------------------------------------", courierNorm), myPageLeftMargin, myCurrentY, 0); ////////////// //END ITEM ////////////// */ // step 5 document.close(); if (Desktop.isDesktopSupported()) { try { File f = new File(bolFileName); Desktop.getDesktop().open(f); } catch (IOException ex) { // no application registered for PDFs } } } catch (IOException | DocumentException ex) { Logger.getLogger(PDFCreator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:Report.RelatorioAluno.java
/** * funcao para gerar o stream do relatorio * * @return ByteArrayOutputStream/* w w w .j a va 2 s . c om*/ */ public ByteArrayOutputStream relatorioAlunosMatriculados() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FacesContext faces = FacesContext.getCurrentInstance(); // pega o contexto da aplicacao realPath = faces.getExternalContext().getRealPath("/"); //realPath = "C:/Users/Alessandro/Desktop/TCC2/SisGES/build/web"; try { BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); //---------------------------------------------------------------------- // creation of the document with a certain size and certain margins // may want to use PageSize.LETTER instead Document document = new Document(PageSize.A4, 40, 40, 20, 50); document.addAuthor("SisGES"); // optional document.addSubject("Relatrio"); // opcional document.addKeywords("SisGES"); document.addCreator("iText"); //---------------------------------------------------------------------- // creation of the different writers //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf")); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setBoxSize("header", new Rectangle(36, 54, 559, 788)); //---------------------------------------------------------------------- // ADICIONA HEADER E FOOTER //---------------------------------------------------------------------- HeaderFooter headerFooter = new HeaderFooter(); writer.setPageEvent(headerFooter); //---------------------------------------------------------------------- // ABRE DOCUMENTO PARA ESCRITA //---------------------------------------------------------------------- document.open(); //---------------------------------------------------------------------- //ADICIONAR LOGO NO DOCUMENTO //---------------------------------------------------------------------- Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFU.png"); logoUfu.scaleAbsolute(57, 56);//(largura,altura) logoUfu.isImgTemplate(); //add no template //logoUfu.setAbsolutePosition(30, 745); //x ,y por referencia do rodape document.add(logoUfu); Image logoFacom = Image.getInstance(realPath + "/resources/images/logoFacom.png"); logoFacom.scaleAbsolute(62, 55);//(largura,altura) logoFacom.setAbsolutePosition(92, 767); //x ,y por referencia do rodape //logoFacom.isImgTemplate(); //add no template document.add(logoFacom); //---------------------------------------------------------------------- //ADICIONAR CABEALHO //---------------------------------------------------------------------- PdfContentByte univ = writer.getDirectContentUnder(); univ.beginText(); univ.setFontAndSize(fHelvetica, 10); univ.setTextMatrix(349, 805); // x e y univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA"); univ.setTextMatrix(405, 790); // x e y univ.showText("FACULDADE DE COMPUTAO"); univ.setTextMatrix(403, 775); // x e y univ.showText("COORDENADORIA DE ESTGIO "); univ.endText(); PdfContentByte univEnd = writer.getDirectContentUnder(); univEnd.beginText(); univEnd.setFontAndSize(fHelvetica, 7); univEnd.setTextMatrix(326, 761); // x e y univEnd.showText("Campus Universitrio - Santa Mnica - CEP 38408-100 - Uberlndia - MG"); univEnd.setTextMatrix(432, 750); // x e y univEnd.showText("Telefone: (34) 3239-4144 ou 3239-4393"); univEnd.endText(); //---------------------------------------------------------------------- //ADICIONAR TITULO //---------------------------------------------------------------------- PdfContentByte titulo = writer.getDirectContentUnder(); titulo.beginText(); titulo.setFontAndSize(fHelvetica, 16); titulo.setTextMatrix(210, 700); // x e y titulo.showText("Alunos Matrculados"); titulo.endText(); //---------------------------------------------------------------------- //---------------------------------------------------------------------- AlunoDAO aDAO = new AlunoDAO(); List<Aluno> allAlunos = aDAO.getAllAlunos(); aDAO.closeSession(); PdfPTable table = new PdfPTable(5); table.setTotalWidth(100f); table.setWidthPercentage(100); float[] widths = { 10, 30, 30, 13, 17 };//largura das colunas table.setWidths(widths); table.setHeaderRows(1); Paragraph cabecalho = new Paragraph("Matricula"); PdfPCell cellMatricula = new PdfPCell(cabecalho); // celula cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); cellMatricula.setBackgroundColor(BaseColor.LIGHT_GRAY); cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY); cellMatricula.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellMatricula); cabecalho = new Paragraph("Nome"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cellNome = new PdfPCell(cabecalho); // celula cellNome.setBackgroundColor(BaseColor.LIGHT_GRAY); cellNome.setBorderColor(BaseColor.LIGHT_GRAY); cellNome.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellNome); cabecalho = new Paragraph("Email"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cellEmail = new PdfPCell(cabecalho); // celula cellEmail.setBackgroundColor(BaseColor.LIGHT_GRAY); cellEmail.setBorderColor(BaseColor.LIGHT_GRAY); cellEmail.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellEmail); cabecalho = new Paragraph("Telefone"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cellTelefone = new PdfPCell(cabecalho); // celula cellTelefone.setBackgroundColor(BaseColor.LIGHT_GRAY); cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY); cellTelefone.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellTelefone); cabecalho = new Paragraph("Curso"); cabecalho.getFont().setStyle(Font.BOLD); cabecalho.getFont().setSize(8); PdfPCell cellCurso = new PdfPCell(cabecalho); // celula cellCurso.setBackgroundColor(BaseColor.LIGHT_GRAY); cellCurso.setBorderColor(BaseColor.LIGHT_GRAY); cellCurso.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellCurso); for (int i = 0; i < allAlunos.size(); i++) { Aluno aluno = allAlunos.get(i); Paragraph texto = new Paragraph(aluno.getMatricula()); cellMatricula = new PdfPCell(texto); // celula cellMatricula.setBorderColor(BaseColor.LIGHT_GRAY); texto.getFont().setSize(8); table.addCell(cellMatricula); texto = new Paragraph(aluno.getNome()); texto.getFont().setSize(8); cellNome = new PdfPCell(texto); // celula cellNome.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cellNome); texto = new Paragraph(aluno.getEmail()); texto.getFont().setSize(8); cellEmail = new PdfPCell(texto); // celula cellEmail.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cellEmail); texto = new Paragraph(aluno.getTelefone()); texto.getFont().setSize(8); cellTelefone = new PdfPCell(texto); // celula cellTelefone.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cellTelefone); texto = new Paragraph(aluno.getCursoidcurso().getNomecurso()); texto.getFont().setSize(8); cellCurso = new PdfPCell(texto); // celula cellCurso.setBorderColor(BaseColor.LIGHT_GRAY); table.addCell(cellCurso); } table.setSpacingBefore(100); table.setSpacingAfter(10); table.completeRow(); document.add(table); //add nova pagina document.newPage(); //close document document.close(); } catch (DocumentException | IOException ex) { Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex); } catch (Exception ex) { Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex); } //return stream return baos; }
From source file:Report.RelatorioCurso.java
/** * Funo para gerar o stream do relatrio anual de atividades * * @param proforiseparada//w w w . ja va2 s . c o m * @param sm * @param sa * @param am * @param aa * @param dtinicial * @param dtfinal * @param ano * @param cursoNome * @param coordenador * @param campus * @return ByteArrayOutputStream */ public ByteArrayOutputStream relatorioAnualDeAtividades(ArrayList<Professororientacaoseparada> proforiseparada, ArrayList<Sumariomatricula> sm, ArrayList<Sumarioaprovado> sa, ArrayList<Alunomatriculado> am, ArrayList<Alunoaprovado> aa, Date dtinicial, Date dtfinal, String ano, String cursoNome, Professor coordenador, Campus campus) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); FacesContext faces = FacesContext.getCurrentInstance(); // pega o contexto da aplicacao realPath = faces.getExternalContext().getRealPath("/"); //realPath = "C:/Users/Alessandro/Desktop/TCC2/SisGES/build/web"; try { BaseFont fHelvetica = BaseFont.createFont(BaseFont.HELVETICA, "Cp1252", false); BaseFont fHelveticaBOLD = BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false); //---------------------------------------------------------------------- // creation of the document with a certain size and certain margins // may want to use PageSize.LETTER instead Document document = new Document(PageSize.A4, 40, 40, 20, 50); document.addAuthor("SisGES"); // optional document.addSubject("Relatrio"); // opcional document.addKeywords("SisGES"); document.addCreator("iText"); //---------------------------------------------------------------------- // creation of the different writers //PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("web/resources/report/alunosMatriculados.pdf")); PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setBoxSize("header", new Rectangle(36, 54, 559, 788)); //---------------------------------------------------------------------- // ADICIONA HEADER E FOOTER //---------------------------------------------------------------------- HeaderFooter headerFooter = new HeaderFooter(); writer.setPageEvent(headerFooter); //---------------------------------------------------------------------- // ABRE DOCUMENTO PARA ESCRITA //---------------------------------------------------------------------- document.open(); //---------------------------------------------------------------------- //ADICIONAR LOGO NO DOCUMENTO //---------------------------------------------------------------------- Image logoUfu = Image.getInstance(realPath + "/resources/images/logoUFU.png"); logoUfu.scaleAbsolute(57, 56);//(largura,altura) logoUfu.isImgTemplate(); //add no template //logoUfu.setAbsolutePosition(30, 745); //x ,y por referencia do rodape document.add(logoUfu); Image logoFacom = Image.getInstance(realPath + "/resources/images/logoFacom.png"); logoFacom.scaleAbsolute(62, 55);//(largura,altura) logoFacom.setAbsolutePosition(92, 767); //x ,y por referencia do rodape //logoFacom.isImgTemplate(); //add no template document.add(logoFacom); //---------------------------------------------------------------------- //ADICIONAR CABEALHO //---------------------------------------------------------------------- PdfContentByte univ = writer.getDirectContentUnder(); univ.beginText(); univ.setFontAndSize(fHelvetica, 10); univ.setTextMatrix(349, 805); // x e y univ.showText("UNIVERSIDADE FEDERAL DE UBERLNDIA"); univ.setTextMatrix(405, 790); // x e y univ.showText("FACULDADE DE COMPUTAO"); univ.setTextMatrix(403, 775); // x e y univ.showText("COORDENADORIA DE ESTGIO "); univ.endText(); String info = "Campus Universitrio - " + campus.getNomecampus() + " - CEP " + campus.getCep() + " - " + campus.getCidade() + " - " + campus.getEstadosigla().toUpperCase(); Chunk txtCampus = new Chunk(info); Paragraph paragraph0 = new Paragraph(); paragraph0.setSpacingBefore(-10); paragraph0.setFont(new Font(fHelvetica, 7)); paragraph0.add(txtCampus); paragraph0.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph0); info = "Telefone: " + coordenador.getTelefone() + " Email: " + coordenador.getEmail(); Chunk txtCoordenador = new Chunk(info); Paragraph paragraph1 = new Paragraph(); paragraph1.setSpacingBefore(-5); paragraph1.setSpacingAfter(10); paragraph1.setFont(new Font(fHelvetica, 7)); paragraph1.add(txtCoordenador); paragraph1.setAlignment(Element.ALIGN_RIGHT); document.add(paragraph1); //---------------------------------------------------------------------- //ADICIONAR TITULO //---------------------------------------------------------------------- PdfContentByte t1 = writer.getDirectContentUnder(); t1.beginText(); t1.setFontAndSize(fHelveticaBOLD, 12); t1.setTextMatrix(175, 700); // x e y t1.showText("RELATRIO ANUAL DE ATIVIDADES - " + ano); t1.endText(); PdfContentByte t2 = writer.getDirectContentUnder(); t2.beginText(); t2.setFontAndSize(fHelveticaBOLD, 12); t2.setTextMatrix(160, 680); // x e y if (cursoNome.contains("sistema") || cursoNome.contains("Sistemas") || cursoNome.contains("Sistema")) { t2.showText("BACHARELADO EM SISTEMAS DE INFORMAO"); cursoNome = "Sistemas de Informao"; } else if (cursoNome.contains("cincia") || cursoNome.contains("Cincias") || cursoNome.contains("Cincia")) { t2.showText("BACHARELADO EM CINCIA DA COMPUTAO"); cursoNome = "Cincia da Computao"; } else { t2.showText("BACHARELADO EM " + cursoNome.toUpperCase()); } t2.endText(); Paragraph p0 = new Paragraph("1. Introduo"); p0.setSpacingBefore(95); p0.getFont().setStyle(Font.BOLD); p0.getFont().setSize(12); document.add(p0); //---------------------------------------------------------------------- String textoIntro = "Este documento tem o objetivo de apresentar as atividades da coordenao de estgio " + "supervisionado da Faculdade de Computao da Universidade Federal de Uberlndia. As principais " + "atividades desenvolvidas foram:"; Chunk chunk1 = new Chunk(textoIntro); Paragraph paragraph = new Paragraph(); paragraph.setSpacingBefore(20); paragraph.setSpacingAfter(10); paragraph.setFont(new Font(fHelvetica, 12)); paragraph.add(chunk1); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph); //lista List overview = new List(false, 10); overview.setAutoindent(true); overview.add("Aprovao dos documentos de matricula do estgio supervisionado;"); overview.add("Alocao de professores orientadores de estgio;"); overview.add( "Matrcula de alunos do curso de " + cursoNome + " na disciplina de estgio supervisionado;"); overview.add("Acompanhamento das atividades do estagirio na empresa;"); overview.add("Aprovao do Relatrio parcial/final do estagirio."); document.add(overview); String textoIntro2 = "Os resultados das atividades listadas so apresentados nas prximas sees."; Chunk chunk2 = new Chunk(textoIntro2); Paragraph paragraph2 = new Paragraph(); paragraph2.setSpacingBefore(10); paragraph2.setSpacingAfter(10); paragraph2.setFont(new Font(fHelvetica, 12)); paragraph2.add(chunk2); paragraph2.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph2); Paragraph p01 = new Paragraph("2. Sumrio das Atividades"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(12); document.add(p01); //---------------------------------------------------------------------- //FAZER SUMARIO //---------------------------------------------------------------------- PdfPTable tabelaSumario = new PdfPTable(4); tabelaSumario.setTotalWidth(100f); tabelaSumario.setWidthPercentage(100); float[] widths = { 40, 20, 20, 20 };//largura das colunas tabelaSumario.setWidths(widths); tabelaSumario.setHeaderRows(1); Paragraph l1 = new Paragraph(" "); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.WHITE); cell1.setBorderColor(BaseColor.WHITE); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell2 = new PdfPCell(l1); // celula cell2.setBackgroundColor(BaseColor.LIGHT_GRAY); cell2.setBorderColor(BaseColor.LIGHT_GRAY); cell2.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell2); l1 = new Paragraph("Aprovaes"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell3 = new PdfPCell(l1); // celula cell3.setBackgroundColor(BaseColor.LIGHT_GRAY); cell3.setBorderColor(BaseColor.LIGHT_GRAY); cell3.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell3); l1 = new Paragraph("Reprovaes"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); PdfPCell cell4 = new PdfPCell(l1); // celula cell4.setBackgroundColor(BaseColor.LIGHT_GRAY); cell4.setBorderColor(BaseColor.LIGHT_GRAY); cell4.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaSumario.addCell(cell4); int i = 0; for (Sumariomatricula m : sm) { Sumarioaprovado a = sa.get(i); Paragraph texto = new Paragraph(m.getTipoestagio()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); if (m.getMatriculas() != null) { texto = new Paragraph(String.valueOf(m.getMatriculas())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } if (m.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") && a.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio")) { if (a.getAprovados() != null) { //aprovados texto = new Paragraph(String.valueOf(a.getAprovados())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } //reprovados texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else if (m.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio") && a.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio")) { if (a.getAprovados() != null) { //aprovados texto = new Paragraph(String.valueOf(a.getAprovados())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } else { texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } //reprovados texto = new Paragraph(String.valueOf(0)); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaSumario.addCell(cell1); } i++; } tabelaSumario.setSpacingBefore(20); tabelaSumario.setSpacingAfter(20); tabelaSumario.completeRow(); document.add(tabelaSumario); //---------------------------------------------------------------------- //ALUNOS MATRICULADOS //---------------------------------------------------------------------- Paragraph p1 = new Paragraph("3. Alunos Matriculados"); p1.setSpacingBefore(5); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); p01 = new Paragraph("Estgio Obrigatrio"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(10); document.add(p01); //---------------------------------------------------------------------- //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- PdfPTable tabelaAlunoMatriculadoEO = new PdfPTable(4); tabelaAlunoMatriculadoEO.setTotalWidth(100f); tabelaAlunoMatriculadoEO.setWidthPercentage(100); float[] widthsEO = { 20, 30, 30, 20 };//largura das colunas tabelaAlunoMatriculadoEO.setWidths(widthsEO); tabelaAlunoMatriculadoEO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoEO.addCell(cell1); for (int j = 0; j < am.size(); j++) { Alunomatriculado amat = am.get(j); if (amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") || amat.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio") || amat.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) { Paragraph texto = new Paragraph(amat.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(amat.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(amat.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoEO.addCell(cell1); } } tabelaAlunoMatriculadoEO.setSpacingBefore(20); tabelaAlunoMatriculadoEO.setSpacingAfter(20); tabelaAlunoMatriculadoEO.completeRow(); document.add(tabelaAlunoMatriculadoEO); //---------------------------------------------------------------------- //FAZER TABELA ALUNOS MATRICULADOS ESTAGIO NO OBRIGATORIO //---------------------------------------------------------------------- p01 = new Paragraph("Estgio No Obrigatrio"); p01.setSpacingBefore(5); p01.getFont().setStyle(Font.BOLD); p01.getFont().setSize(10); document.add(p01); PdfPTable tabelaAlunoMatriculadoENO = new PdfPTable(4); tabelaAlunoMatriculadoENO.setTotalWidth(100f); tabelaAlunoMatriculadoENO.setWidthPercentage(100); float[] widthsENO = { 20, 30, 30, 20 };//largura das colunas tabelaAlunoMatriculadoENO.setWidths(widthsENO); tabelaAlunoMatriculadoENO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoMatriculadoENO.addCell(cell1); for (int k = 0; k < am.size(); k++) { Alunomatriculado amat = am.get(k); if (amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatrio") || amat.getTipoestagio().equalsIgnoreCase("Estgio No Obrigatorio") || amat.getTipoestagio().equalsIgnoreCase("Estagio No Obrigatorio")) { Paragraph texto = new Paragraph(amat.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(amat.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(amat.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(amat.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoMatriculadoENO.addCell(cell1); } } tabelaAlunoMatriculadoENO.setSpacingBefore(20); tabelaAlunoMatriculadoENO.setSpacingAfter(20); tabelaAlunoMatriculadoENO.completeRow(); document.add(tabelaAlunoMatriculadoENO); //add nova pagina //document.newPage(); //---------------------------------------------------------------------- //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- p1 = new Paragraph("4. Alunos Aprovados em Estgio Obrigatrio"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); PdfPTable tabelaAlunoAprovadoEO = new PdfPTable(5); tabelaAlunoAprovadoEO.setTotalWidth(100f); tabelaAlunoAprovadoEO.setWidthPercentage(100); float[] widthsAprovadoEO = { 20, 30, 30, 10, 10 };//largura das colunas tabelaAlunoAprovadoEO.setWidths(widthsAprovadoEO); tabelaAlunoAprovadoEO.setHeaderRows(1); l1 = new Paragraph("Matrculas"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Nome"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Orientador"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Data de Matrcula"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); l1 = new Paragraph("Data de Finalizao"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaAlunoAprovadoEO.addCell(cell1); for (int t = 0; t < aa.size(); t++) { Alunoaprovado aprov = aa.get(t); if (aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatrio") || aprov.getTipoestagio().equalsIgnoreCase("Estgio Obrigatorio") || aprov.getTipoestagio().equalsIgnoreCase("Estagio Obrigatorio")) { Paragraph texto = new Paragraph(aprov.getMatricula()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(aprov.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(aprov.getOrientador()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatamatricula())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); texto = new Paragraph(CalendarFormat.getDataBRtoDate(aprov.getDatafinalizacao())); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaAlunoAprovadoEO.addCell(cell1); } } tabelaAlunoAprovadoEO.setSpacingBefore(20); tabelaAlunoAprovadoEO.setSpacingAfter(20); tabelaAlunoAprovadoEO.completeRow(); document.add(tabelaAlunoAprovadoEO); //---------------------------------------------------------------------- //ALUNOS APROVADOS EM ESTAGIO OBRIGATORIO //---------------------------------------------------------------------- p1 = new Paragraph("5. Participao dos professores FACOM"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); // PdfPTable tabelaProfOriSeparada = new PdfPTable(3); tabelaProfOriSeparada.setTotalWidth(100f); tabelaProfOriSeparada.setWidthPercentage(100); float[] widths0 = { 60, 20, 20 };//largura das colunas tabelaProfOriSeparada.setWidths(widths0); tabelaProfOriSeparada.setHeaderRows(1); l1 = new Paragraph("Professor"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); l1 = new Paragraph("Orientaes Estgio Obrigatrio"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); l1 = new Paragraph("Orientaes Estgio No Obrigatrio"); l1.getFont().setStyle(Font.BOLD); l1.getFont().setSize(8); cell1 = new PdfPCell(l1); // celula cell1.setBackgroundColor(BaseColor.LIGHT_GRAY); cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); tabelaProfOriSeparada.addCell(cell1); for (int ii = 0; ii < proforiseparada.size(); ii++) { Professororientacaoseparada profoe = proforiseparada.get(ii); Paragraph texto = new Paragraph(profoe.getNome()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); texto = new Paragraph(profoe.getOrientacoesestobrigatorio().toString()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); texto = new Paragraph(profoe.getOrientacoesestnaoobrigatorio().toString()); cell1 = new PdfPCell(texto); // celula cell1.setBorderColor(BaseColor.LIGHT_GRAY); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); texto.getFont().setSize(8); tabelaProfOriSeparada.addCell(cell1); } tabelaProfOriSeparada.setSpacingBefore(20); tabelaProfOriSeparada.setSpacingAfter(20); tabelaProfOriSeparada.completeRow(); document.add(tabelaProfOriSeparada); //---------------------------------------------------------------------- p1 = new Paragraph("6. Observaes e Consideraes Finais"); p1.setSpacingBefore(20); p1.getFont().setStyle(Font.BOLD); p1.getFont().setSize(12); document.add(p1); String text6 = "O processo de matrcula, acompanhamento, composio de bancas e " + "defesas ocorreu sem nenhum problema ou acontecimento excepcional."; chunk1 = new Chunk(text6); paragraph = new Paragraph(); paragraph.setSpacingBefore(20); paragraph.setSpacingAfter(10); paragraph.setFont(new Font(fHelvetica, 12)); paragraph.add(chunk1); paragraph.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraph); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); //----------------------------------------------------- Paragraph paragraphCab = new Paragraph(); paragraphCab.setSpacingBefore(25); paragraphCab.add("Uberlndia, " + CalendarFormat.getDataPorExtenso(CalendarFormat.getDataSO()) + "."); paragraphCab.setAlignment(Element.ALIGN_JUSTIFIED); document.add(paragraphCab); document.add(Chunk.NEWLINE); //----------------------------------------------------- // distancia do fim da pagina float y = 120f; float x = 160f; //----------------------------------------------------- //linha PdfContentByte linha = writer.getDirectContentUnder(); linha.setLineWidth(1f); // mostrar linha linha.setGrayStroke(0.5f); // 0 = preto, 1 = branco linha.moveTo(x, y); linha.lineTo(450f, y); // ate onde a linha vai linha.stroke(); //assinatura PdfContentByte a0 = writer.getDirectContentUnder(); a0.beginText(); a0.setFontAndSize(fHelvetica, 10); a0.setTextMatrix(x + 50, y - 15); // x e y a0.showText("Prof. " + coordenador.getNome()); a0.endText(); PdfContentByte a1 = writer.getDirectContentUnder(); a1.beginText(); a1.setFontAndSize(fHelvetica, 10); a1.setTextMatrix(x + 50, y - 30); // x e y a1.showText("Coordenao de Estgio Supervisionado"); a1.endText(); //assinatura PdfContentByte a2 = writer.getDirectContentUnder(); a2.beginText(); a2.setFontAndSize(fHelvetica, 10); a2.setTextMatrix(x + 50, y - 45); // x e y a2.showText("SIAPE: " + coordenador.getSiape()); a2.endText(); //---------------------------------------------------------------------- //FIM DO DOCUMENTO //add nova pagina document.newPage(); //close document document.close(); //---------------------------------------------------------------------- } catch (DocumentException | IOException ex) { Logger.getLogger(RelatorioAluno.class.getName()).log(Level.SEVERE, null, ex); } //return stream return baos; }