List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:com.photoshop.misc.Factuurgenerator.java
public Factuurgenerator(Order order, Environment env, MessageSource messageSource, Locale locale) { this.locale = locale; this.messageSource = messageSource; this.env = env; this.order = order; this.filename = "Factuur " + order.getId(); String FILE = env.getProperty("logo") + this.filename + ".pdf"; //order generate moet nog gemaakt worden catFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); subtitel = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); subFont = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL); smallBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); try {//from w ww .j av a2 s. co m Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); document.newPage(); addMetaData(document); addTitlePage(document); //addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.photoshop.misc.Indexkaartgenerator.java
public Indexkaartgenerator(Order order, Environment env, PhotoDao photoDao, MessageSource messageSource, Locale locale) {//from w w w .jav a 2 s.c o m this.photoDao = photoDao; this.env = env; this.order = order; this.messageSource = messageSource; this.locale = locale; this.filename = "Indexkaart " + order.getId(); String filename = "Indexkaart " + order.getId(); String FILE = env.getProperty("logo") + filename + ".pdf"; //order generate moet nog gemaakt worden catFont = new Font(Font.FontFamily.HELVETICA, 18, Font.BOLD); subtitel = new Font(Font.FontFamily.HELVETICA, 14, Font.BOLD); subFont = new Font(Font.FontFamily.HELVETICA, 12, Font.NORMAL); smallBold = new Font(Font.FontFamily.HELVETICA, 12, Font.BOLD); try { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(FILE)); document.open(); addMetaData(document); addTitlePage(document); //addContent(document); document.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.planfeed.services.MeetingServiceImpl.java
License:Apache License
public ByteArrayOutputStream getActa(String meetingId) throws Exception { Meeting meeting;//w w w .ja va2s.c o m try { meeting = this.getMeeting(meetingId); } catch (Exception e) { throw new MeetingNotFound(); } Document document = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter docWriter = null; HeaderFooter event = new HeaderFooter(meeting.getDate()); docWriter = PdfWriter.getInstance(document, baosPDF); docWriter.setBoxSize("art", new Rectangle(36, 54, 559, 788)); docWriter.setPageEvent(event); document.open(); //metadata document.addTitle(meeting.getTitle() + " Acta"); document.add(new Paragraph(" ")); //Title Paragraph title = new Paragraph("Acta of " + meeting.getTitle(), titleFont); title.setAlignment(Element.ALIGN_CENTER); addEmptyLine(title, 1); document.add(title); //Description Paragraph descriptionPar = new Paragraph(); descriptionPar.add(new Paragraph("Description", titlePointFont)); descriptionPar.add(new Paragraph(meeting.getDescription(), textFont)); addEmptyLine(descriptionPar, 1); document.add(descriptionPar); //Points int index = 1; for (PointOfAgenda point : meeting.getAgenda()) { Paragraph pointPar = new Paragraph(); pointPar.add(new Paragraph(index + ". " + point.getName(), titlePointFont)); pointPar.add(new Paragraph(point.getComment(), textFont)); addEmptyLine(pointPar, 2); document.add(pointPar); index += 1; } document.close(); return baosPDF; }
From source file:com.planning.project.controller.CreatePDF.java
/** * @param args/*from w w w . j a v a 2 s.c om*/ * @throws Exception */ public static Document createPDFBudwork(String file, TbDescriptionstatement tbDescriptionstatement, List<TbAddmoneyvara> tbAddmoneyvaras, List<TbAddmoneynovara> tbAddmoneynovaras, List<TbRemunerationcommittee> tbRemunerationcommittees, List<TbMaketimeformeal> tbMaketimeformeals, List<TbRentshouse> tbRentshouses, List<TbTeachextra> tbTeachextras, List<TbExpenpaper> tbExpenpapers, List<TbComlecturer> tbComlecturers, List<TbOthercompensation> tbOthercompensations, List<TbAllowancesrental> tbAllowancesrentals, List<TbRepairofequipment> tbRepairofequipments, List<TbWageservice> tbWageservices, List<TbMeetingofthesnack> tbMeetingofthesnacks, List<TbSocialsecurity> tbSocialsecuritys, List<TbRentalproperty> tbRentalpropertys, List<TbThecertificationfood> tbThecertificationfoods, List<TbThecertificationdrink> tbThecertificationdrinks, List<TbThegift> tbThegifts, List<TbTax> tbTaxs, List<TbFee> tbFees, List<TbInsurance> tbInsurances, List<TbEmploy> tbEmploys, List<TbMaterial> tbMaterials1, List<TbMaterial> tbMaterials2, List<TbMaterial> tbMaterials3, List<TbMaterial> tbMaterials4, List<TbMaterial> tbMaterials5, List<TbMaterial> tbMaterials6, List<TbMaterial> tbMaterials7, List<TbMaterial> tbMaterials8, List<TbMaterial> tbMaterials9, List<TbMaterial> tbMaterials10, List<TbMaterial> tbMaterials11, List<TbPublicutility> tbPublicutilitys, List<TbGasolineDetail> tbGasolineDetails) throws Exception { Document document = null; try { Font font16 = new Font( BaseFont.createFont("D:/THSarabunNew.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED)); font16.setSize(16); document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Paragraph paragraph = new Paragraph(); addMetaData(document); addTitlePageBud(document); createPagePDFBudwork(document, tbDescriptionstatement); createHeadlistBudwork(document, "1"); PdfPTable table = createtableAddmoneyvara(tbAddmoneyvaras, tbDescriptionstatement.getSumAddmoneyvara()); document.add(table); table.setSpacingBefore(25); table = createtableAddmoneynovara(tbAddmoneynovaras, tbDescriptionstatement.getSumAddmoneynovara()); table.setSpacingBefore(25); document.add(table); table = createtableRemunerationcommittee(tbRemunerationcommittees, tbDescriptionstatement.getSumRemunerationcomnittee()); table.setSpacingBefore(25); document.add(table); table = createtableMaketimeformeal(tbMaketimeformeals, tbDescriptionstatement.getSumMaketimeformeals()); table.setSpacingBefore(25); document.add(table); table = createtableRentshouse(tbRentshouses, tbDescriptionstatement.getSumRentshouse()); table.setSpacingBefore(25); document.add(table); table = createtableTeachextra(tbTeachextras, tbDescriptionstatement.getSumTeachextra()); table.setSpacingBefore(25); document.add(table); table = createtableExpenpaper(tbExpenpapers, tbDescriptionstatement.getSumExpenpaper()); table.setSpacingBefore(25); document.add(table); table = createtableComlecturer(tbComlecturers, tbDescriptionstatement.getSumComlecturer()); table.setSpacingBefore(25); document.add(table); table = createtableOthercompensation(tbOthercompensations, tbDescriptionstatement.getSumOthercompensation()); table.setSpacingBefore(25); document.add(table); createHeadlistBudwork(document, "2"); table = createtableAllowancesrental(tbAllowancesrentals, tbDescriptionstatement.getSumAllowancesrental()); table.setSpacingBefore(25); document.add(table); table = createtableGasolineDetail(tbGasolineDetails, tbDescriptionstatement.getSumGasoline()); table.setSpacingBefore(25); document.add(table); table = createtableRepairofequipment(tbRepairofequipments, tbDescriptionstatement.getSumRepairofequipment()); table.setSpacingBefore(25); document.add(table); table = createtableWageservice(tbWageservices, tbDescriptionstatement.getSumWageservice()); table.setSpacingBefore(25); document.add(table); table = createtableMeetingofthesnack(tbMeetingofthesnacks, tbDescriptionstatement.getSumMeetingofthesnack()); table.setSpacingBefore(25); document.add(table); table = createtableSocialsecurity(tbSocialsecuritys, tbDescriptionstatement.getSumSocialsecurity()); table.setSpacingBefore(25); document.add(table); table = createtableRentalproperty(tbRentalpropertys, tbDescriptionstatement.getSumRentalproperty()); table.setSpacingBefore(25); document.add(table); table = createtableThecertificationfood(tbThecertificationfoods, tbDescriptionstatement.getSumThecertificationfood()); table.setSpacingBefore(25); document.add(table); table = createtableThecertificationdrinks(tbThecertificationdrinks, tbDescriptionstatement.getSumThecertificationdrink()); table.setSpacingBefore(25); document.add(table); table = createtableThegift(tbThegifts, tbDescriptionstatement.getSumThegift()); table.setSpacingBefore(25); document.add(table); table = createtableTax(tbTaxs, tbDescriptionstatement.getSumTax()); table.setSpacingBefore(25); document.add(table); table = createtableFee(tbFees, tbDescriptionstatement.getSumFee()); table.setSpacingBefore(25); document.add(table); table = createtableInsurance(tbInsurances, tbDescriptionstatement.getSumInsurance()); table.setSpacingBefore(25); document.add(table); table = createtableEmploy(tbEmploys, tbDescriptionstatement.getSumEmploy()); table.setSpacingBefore(25); document.add(table); createHeadlistBudwork(document, "3"); table = createtableMaterial1(tbMaterials1, tbDescriptionstatement.getSumMOffice()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial2(tbMaterials2, tbDescriptionstatement.getSumMBuild()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial3(tbMaterials3, tbDescriptionstatement.getSumMKitchen()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial4(tbMaterials4, tbDescriptionstatement.getSumMElectrical()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial5(tbMaterials5, tbDescriptionstatement.getSumMMedic()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial6(tbMaterials6, tbDescriptionstatement.getSumMStudy()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial7(tbMaterials7, tbDescriptionstatement.getSumMBook()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial8(tbMaterials8, tbDescriptionstatement.getSumMFarm()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial9(tbMaterials9, tbDescriptionstatement.getSumMCom()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial10(tbMaterials10, tbDescriptionstatement.getSumMMul()); table.setSpacingBefore(25); document.add(table); table = createtableMaterial11(tbMaterials11, tbDescriptionstatement.getSumMOther()); table.setSpacingBefore(25); document.add(table); createHeadlistBudwork(document, "4"); table = createtablePublicutility(tbPublicutilitys, tbDescriptionstatement.getSumPublicutility()); table.setSpacingBefore(25); document.add(table); document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return document; }
From source file:com.planning.project.controller.CreatePDF.java
public static Document createPDFFormProject(String file, TbFormProject tbFormProject, List<TbActivity> activity, List<TbDetailSka> detailSka, List<TbDetailSm> detailSms, TbFormSubproject subProject, TbTargetgroup target) throws Exception { Document document = null;//from w ww.j ava 2s . c o m try { document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); addMetaData(document); addTitlePageProject(document); createPagePDFFormProject(document, tbFormProject, activity, detailSka, detailSms, subProject); PdfPTable table = createtableTargetGroup(target); document.add(table); table.setSpacingBefore(25); table = createtableTargetGroup2(target); table.setSpacingBefore(25); document.add(table); createPagePDFFormProject2(document, tbFormProject, activity, detailSka, detailSms, subProject); table = createtableFollowCheck(subProject); table.setSpacingBefore(25); document.add(table); table = createtablePro(tbFormProject); table.setSpacingBefore(25); document.add(table); createPagePDFFormProject3(document, tbFormProject, activity, detailSka, detailSms, subProject); document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return document; }
From source file:com.planning.project.controller.CreatePDF.java
public static Document createPDFActivity(String file, Long activityId) throws Exception { Document document = null;//from w ww . j ava 2s .c o m try { document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); addMetaData(document); addTitlePageProject(document); Paragraph created = new Paragraph(); created.setFont(TIME_ROMAN_SMALL); created.add(activityId.toString()); created.setAlignment(Element.ALIGN_RIGHT); document.add(created); document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } return document; }
From source file:com.poscoict.license.service.CertificateService.java
public Map<String, Object> getLicenseCertification(String userNo, String licenseFileName, HttpServletRequest req) throws Exception { logger.info("_________getLicenseCertification: " + userNo + " " + licenseFileName); String PDFFileName = userNo + licenseFileName; String PDFFilePath = Consts.PDF_PATH + PDFFileName + ".pdf"; String ImgFilePath = Consts.IMG_PATH + PDFFileName + "1." + Consts.IMG_FORMAT; Map<String, Object> map = new HashMap<String, Object>(); map.put("PDFFileName", PDFFileName + ".pdf"); map.put("ImgFileName", PDFFileName + "1." + Consts.IMG_FORMAT); Map<String, Object> licenseInfo = (Map<String, Object>) managementDao.getLicenseCertification(userNo, licenseFileName);/*from w w w . j a v a 2s .c om*/ Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(PDFFilePath)); document.open(); Paragraph p0 = new Paragraph(" "); Paragraph p1 = null; p1 = setParagraph("License Certificate", Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(p0); document.add(p0); document.add( setParagraph("? End User (?) : " + licenseInfo.get("USER_NAME"), Fonts.FONT12BOLD)); document.add( setParagraph("? Address (): " + licenseInfo.get("USER_ADDRESS"), Fonts.FONT12BOLD)); document.add( setParagraph("? Project (): " + licenseInfo.get("PROJECT_NAME"), Fonts.FONT12BOLD)); document.add(p0); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(" Product Description", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" " + licenseInfo.get("PRODUCT_FILE_NAME"), getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" License Number", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" " + licenseInfo.get("LICENSE_KEY"), getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" Quantity", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell( new Phrase(" " + licenseInfo.get("LICENSE_QUANTITY") + " EA", getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); document.add(table); document.add(p0); List list = new List(false, 20); list.add(new ListItem( " License Certificate ?? ? ? ? ? ?? ??.", getFont(Fonts.FONT12NOAML))); list.add(new ListItem( "License Certificate ? ?? ? ? ? ? ?.", getFont(Fonts.FONT12NOAML))); list.add(new ListItem(", ? ?? .", getFont(Fonts.FONT12NOAML))); document.add(list); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph(licenseInfo.get("USER_START_DATE").toString(), Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); p1 = setParagraph(licenseInfo.get("COMPANY_NAME").toString(), Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); // Image img = Image.getInstance(Consts.SIGNET_IMG_PATH); // img.setAbsolutePosition(350f, 390f); // document.add(img); document.close(); } catch (DocumentException de) { logger.error(ImgFilePath, de); } catch (IOException ioe) { logger.error(ImgFilePath, ioe); } String temp = req.getSession().getServletContext().getRealPath(Consts.IMG_TEMP_FOLDER); System.out.println("________________________________________________" + temp); if (extractPagesAsImage(PDFFilePath, PDFFileName, 100, "")) { fileCopy(ImgFilePath, temp + File.separator + map.get("ImgFileName")); } return map; }
From source file:com.poscoict.license.service.CertificateService.java
public Map<String, Object> getTechSupportCertificationInfo(String userNo, String productFileId, HttpServletRequest req) throws Exception { logger.info("_________getTechSupportCertificationInfo: " + userNo + " " + productFileId); String PDFFileName = userNo + "_TechSupportCertification"; String PDFFilePath = Consts.PDF_PATH + PDFFileName + ".pdf"; String ImgFilePath = Consts.IMG_PATH + PDFFileName + "1." + Consts.IMG_FORMAT; Map<String, Object> map = new HashMap<String, Object>(); map.put("PDFFileName", PDFFileName + ".pdf"); map.put("ImgFileName", PDFFileName + "1." + Consts.IMG_FORMAT); Map<String, Object> productInfo = managementDao.getTechSupportCertificationInfo(userNo, productFileId); if (productInfo.get("TECH_SUPPORT_DATE").equals("0")) { throw new UserException( "? ? . ?? ?."); }// w w w .ja v a2 s . co m Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(PDFFilePath)); document.open(); Paragraph p0 = new Paragraph(" "); Paragraph p1 = null; Paragraph header = new Paragraph("? ", getFont(Fonts.FONT20BOLD)); header.setAlignment(Paragraph.ALIGN_CENTER); document.add(header); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph("POSCO ICT ? ? " + productInfo.get("PRODUCT_FILE_NAME") + " ? ," + " ? ? ?? ? ? ?" + " ? .", Fonts.FONT18NOAML); document.add(p1); document.add(p0); document.add(p0); p1 = setParagraph("- -", Fonts.FONT18NOAML); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(p0); document.add(p0); List list = new List(false, 30); list.add(new ListItem("? ? ? : " + productInfo.get("USER_START_DATE"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("PRODUCT_FILE_NAME") + " (" + productInfo.get("LICENSE_QUANTITY") + "?)", getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? ? : POSCO ICT", getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("PROJECT_NAME"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("COMPANY_NAME"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? ? : " + productInfo.get("TECH_SUPPORT_DATE"), getFont(Fonts.FONT18NOAML))); document.add(list); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph("POSCO ICT", Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); // Image img = Image.getInstance(Consts.SIGNET_IMG_PATH); // img.setAbsolutePosition(350f, 260f); // document.add(img); document.close(); } catch (DocumentException de) { logger.error(ImgFilePath, de); } catch (IOException ioe) { logger.error(ImgFilePath, ioe); } String temp = req.getSession().getServletContext().getRealPath(Consts.IMG_TEMP_FOLDER); if (extractPagesAsImage(PDFFilePath, PDFFileName, 100, "")) { fileCopy(ImgFilePath, temp + File.separator + map.get("ImgFileName")); } return map; }
From source file:com.preselect.pdfservice.tasks.PdfConversionTask.java
License:Open Source License
private static void copyDocument(PdfReader reader, int start, int end, String path, OutlineItems outline) throws IOException, DocumentException { Document document = new Document(); PdfSmartCopy copy = new PdfSmartCopy(document, new FileOutputStream(path)); document.open();//from ww w.ja v a2 s. c om for (int i = (start - 1); i <= (end - 1);) { copy.addPage(copy.getImportedPage(reader, ++i)); } List<OutlineItem> outlineForChapter = getOutlineBetweenPages(outline, start, end); Iterator<OutlineItem> iterator = outlineForChapter.iterator(); if (iterator.hasNext()) { List<HashMap<String, Object>> bookmarksForChapter = getBookmarks(iterator.next(), iterator, 1); SimpleBookmark.shiftPageNumbers(bookmarksForChapter, (-start + 1), null); copy.setOutlines(bookmarksForChapter); } if (outlineForChapter.size() > 0) { OutlineItem firstOutline = outlineForChapter.get(0); document.addTitle(firstOutline.getTitle()); } document.addCreator("Content Select"); document.close(); copy.close(); }
From source file:com.prjhuellvotweb.controlador.PDF.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //Preguntar por la sesion del usuario admin HttpSession sessionOk = request.getSession(true); if (sessionOk.getAttribute("admin") != null) { //cambiar a tipo application/pdf response.setContentType("application/pdf;charset=UTF-8"); //flujo de salida OutputStream out = response.getOutputStream(); String texto = request.getParameter("report"); //texto = "Reporte de los proyectos Sena CTGI (Centro tecnologico de gestion industrial) donde se dan a conocer" // + " los nombres de los proyectos y cantidad de votos obtenidos para cada proyecto."; try {// w w w . j a v a 2 s . c o m Connection con = Conexion.conectar("mysql"); DAOVoto dao = new DAOVoto(); List<List> lista = dao.estadisticaNumeroVotos(); Voto t = dao.contarVotos(); int to = t.getIdUsuario(); if (!lista.isEmpty() && lista.size() > 0) { try { //programar pdf Document documento = new Document(); //asosciar documento con la salida PdfWriter.getInstance(documento, out);// salida del cocumento en pdf //abrir documento documento.open(); Paragraph par2 = new Paragraph(); Paragraph par4 = new Paragraph(); //agregar una imagen logo sena al pdf Image imagenes = Image .getInstance(getServletContext().getRealPath("") + "/Multimedia/reportes.png"); //Centrar la imagen imagenes.setAlignment(Element.ALIGN_CENTER); //tamao de la imagen imagenes.scaleToFit(530, 520); //agg imagen al documento F:\\Documentos\\yo\\huellvot 2 17-06-2016\\PrjHuellVotWeb\\web\\iCO.png //documento.add(imghuellvot); documento.add(imagenes); //Agg salto de linea par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); //fuente del pdf, tipo de fuente famimilia tamao de letra //Importar ttf que contiene el tipo de letra FontFactory.register( "C:\\Users\\pc\\Desktop\\PrjHuellVotWeb\\web\\fonts\\roboto\\Roboto-Bold.ttf", "Roboto"); //Font fondescripcion = FontFactory.getFont("Roboto"); Font fondescripcion = new Font(Font.getFamily("Roboto"), 16, Font.NORMAL, BaseColor.BLACK); //texto de la descripcion par2.add(new Phrase(texto, fondescripcion)); //justificar descripcion par2.setAlignment(Element.ALIGN_JUSTIFIED); //Agg salto de linea par2.add(new Phrase(Chunk.NEWLINE)); par2.add(new Phrase(Chunk.NEWLINE)); //agregar descripcion al documento documento.add(par2);//agregar todas las propiedades de la descripcin //crear una tabla PdfPTable tabla = new PdfPTable(5);//( Numero de columnas de la tabla) //columnas de la tabla, cabezera y agg un estilo PdfPCell celda = new PdfPCell( new Paragraph("Nmero", FontFactory.getFont("Roboto", 14, Font.BOLD))); PdfPCell celda1 = new PdfPCell( new Paragraph("Nombre", FontFactory.getFont("Roboto", 14, Font.BOLD))); celda1.setColspan(3); PdfPCell celda2 = new PdfPCell( new Paragraph("Votos", FontFactory.getFont("Roboto", 14, Font.BOLD))); //Color de fondo celda.setBackgroundColor(new BaseColor(252, 115, 35)); celda1.setBackgroundColor(new BaseColor(252, 115, 35)); celda2.setBackgroundColor(new BaseColor(252, 115, 35)); //Centrar celda.setHorizontalAlignment(Element.ALIGN_CENTER); celda1.setHorizontalAlignment(Element.ALIGN_CENTER); celda2.setHorizontalAlignment(Element.ALIGN_CENTER); //padding celda.setPadding(8.0f); celda1.setPadding(8.0f); celda2.setPadding(8.0f); //agg columna ala tabla tabla.addCell(celda); tabla.addCell(celda1); tabla.addCell(celda2); for (int i = 0; i < lista.size(); i++) { List l = lista.get(i); //Convertir el entero a string String num = String.valueOf(l.get(0)); String nom = String.valueOf(l.get(1)); String tot = String.valueOf(l.get(2)); //Agregar valores a las celdas PdfPCell c = new PdfPCell( new Paragraph(num, FontFactory.getFont("Roboto", 12, Font.BOLD))); PdfPCell c1 = new PdfPCell( new Paragraph(nom, FontFactory.getFont("Roboto", 12, Font.BOLD))); c1.setColspan(3); PdfPCell c2 = new PdfPCell( new Paragraph(tot, FontFactory.getFont("Roboto", 12, Font.BOLD))); //Padding para las celdas c.setPadding(4.0f); c1.setPadding(4.0f); c2.setPadding(4.0f); //Centrar contenido de celda c.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setHorizontalAlignment(Element.ALIGN_CENTER); //mostrar los resultados de cada columna los agrega a la tabla tabla.addCell(c); tabla.addCell(c1); tabla.addCell(c2); } PdfPCell c1 = new PdfPCell(new Paragraph("Total Votos: ", fondescripcion)); c1.setColspan(4); PdfPCell c2 = new PdfPCell(new Paragraph("" + to, fondescripcion)); c1.setHorizontalAlignment(Element.ALIGN_CENTER); c2.setHorizontalAlignment(Element.ALIGN_CENTER); c1.setPadding(4.0f); c2.setPadding(4.0f); tabla.addCell(c1); tabla.addCell(c2); //Agrega la tabla a el documento documento.add(tabla); //agregar fecha Font fonfecha = new Font(Font.getFamily("Roboto"), 12, Font.NORMAL, BaseColor.LIGHT_GRAY); par4.add(new Phrase("Expedido por HuellVot", fonfecha)); DateFormat formato = DateFormat.getDateInstance(DateFormat.FULL); par4.add(new Paragraph(formato.format(new Date()))); documento.add(par4); //cerrar el documento documento.close(); } catch (DocumentException | IOException e) { e.getMessage(); System.out.println("Error al generar el reporte PDF" + e); } } else { try { Document documento = new Document(); PdfWriter.getInstance(documento, out);// salida del cocumento en pdf //abrir documento documento.open(); System.out.println("no hat datos"); //agregar una imagen logo sena al pdf Image imagenes = Image.getInstance( "C:\\Users\\pc\\Desktop\\PrjHuellVotWeb\\web\\Multimedia\\reportes.png"); //Centrar la imagen imagenes.setAlignment(Element.ALIGN_CENTER); //tamao de la imagen imagenes.scaleToFit(530, 520); //agg imagen al documento F:\\Documentos\\yo\\huellvot 2 17-06-2016\\PrjHuellVotWeb\\web\\iCO.png //documento.add(imghuellvot); documento.add(imagenes); Paragraph par1 = new Paragraph(); Paragraph par2 = new Paragraph(); //Agg salto de linea par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); //fuente del pdf, tipo de fuente famimilia tamao de letra //Importar ttf que contiene el tipo de letra FontFactory.register( "C:\\Users\\pc\\Desktop\\PrjHuellVotWeb\\web\\fonts\\roboto\\Roboto-Bold.ttf", "Roboto"); //Font fondescripcion = FontFactory.getFont("Roboto"); Font fondescripcion = new Font(Font.getFamily("Roboto"), 16, Font.NORMAL, BaseColor.BLACK); //texto de la descripcion par1.add(new Phrase("lo sentimos pero no hay datos para mostrar.!", fondescripcion)); //justificar descripcion par1.setAlignment(Element.ALIGN_CENTER); //Agg salto de linea par1.add(new Phrase(Chunk.NEWLINE)); par1.add(new Phrase(Chunk.NEWLINE)); //agregar descripcion al documento documento.add(par1);//agregar todas las propiedades de la descripcin //agregar fecha Font fonfecha = new Font(Font.getFamily("Roboto"), 12, Font.NORMAL, BaseColor.LIGHT_GRAY); par2.add(new Phrase("Expedido por HuellVot", fonfecha)); DateFormat formato = DateFormat.getDateInstance(DateFormat.FULL); par2.add(new Paragraph(formato.format(new Date()))); documento.add(par2); //cerrar el documento documento.close(); } catch (DocumentException ex) { ex.getMessage(); System.out.println("Error al generar el reporte PDF sin datos registrados" + ex); } } } finally { out.close(); } } else { sessionOk.invalidate(); response.sendRedirect("index.jsp"); } }