List of usage examples for com.itextpdf.text.pdf PdfPTable setWidthPercentage
public void setWidthPercentage(final float widthPercentage)
From source file:file.PDFWriter.java
License:Open Source License
/** * Make the initial header to the PDF, with the date and character * @throws DocumentException/*from ww w. j a v a 2s . c om*/ */ public void makePDFHeader() throws DocumentException { PdfPTable headerTable = new PdfPTable(2); headerTable.setWidthPercentage(100); PdfPCell dateCell = new PdfPCell(new Paragraph( "Date: " + date.monthOfYear().getAsString() + "/" + date.dayOfMonth().getAsString(), lineFont)); dateCell.setHorizontalAlignment(Element.ALIGN_LEFT); dateCell.setBorder(PdfPCell.NO_BORDER); dateCell.setPadding(0.3f); PdfPCell characterCell = new PdfPCell(new Paragraph("Character: " + role.getName(), lineFont)); characterCell.setHorizontalAlignment(Element.ALIGN_RIGHT); characterCell.setBorder(PdfPCell.NO_BORDER); headerTable.addCell(dateCell); headerTable.addCell(characterCell); document.add(headerTable); document.add(Chunk.NEWLINE); document.add(Chunk.NEWLINE); }
From source file:fll.util.PdfUtils.java
License:Open Source License
/** * Create a table with the specified number of columns that is the full page * width.//from www. j a v a 2 s . c om */ public static PdfPTable createTable(final int columns) throws BadElementException { final PdfPTable table = new PdfPTable(columns); // table.setCellsFitPage(true); table.setWidthPercentage(100); return table; }
From source file:fll.web.playoff.ScoresheetGenerator.java
License:Open Source License
public void writeFile(final OutputStream out, final boolean orientationIsPortrait) throws DocumentException { // This creates our new PDF document and declares its orientation Document pdfDoc;//from ww w . j av a 2 s .co m if (orientationIsPortrait) { pdfDoc = new Document(PageSize.LETTER); // portrait } else { pdfDoc = new Document(PageSize.LETTER.rotate()); // landscape } PdfWriter.getInstance(pdfDoc, out); // Measurements are always in points (72 per inch) // This sets up 1/2 inch margins side margins and 0.35in top and bottom // margins pdfDoc.setMargins(0.5f * POINTS_PER_INCH, 0.5f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH, 0.35f * POINTS_PER_INCH); pdfDoc.open(); // Header cell with challenge title to add to both scoresheets final Paragraph titleParagraph = new Paragraph(); final Chunk titleChunk = new Chunk(m_pageTitle, FontFactory.getFont(FontFactory.HELVETICA_BOLD, 14, Font.NORMAL, BaseColor.WHITE)); titleParagraph.setAlignment(Element.ALIGN_CENTER); titleParagraph.add(titleChunk); titleParagraph.add(Chunk.NEWLINE); final Chunk swVersionChunk = new Chunk("SW version: " + Version.getVersion(), FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(swVersionChunk); if (null != m_revision) { final Chunk revisionChunk = new Chunk(" Descriptor revision: " + m_revision, FontFactory.getFont(FontFactory.HELVETICA, 8, Font.NORMAL, BaseColor.WHITE)); titleParagraph.add(revisionChunk); } final PdfPCell head = new PdfPCell(); head.setColspan(2); head.setBorder(1); head.setPaddingTop(0); head.setPaddingBottom(3); head.setBackgroundColor(new BaseColor(64, 64, 64)); head.setVerticalAlignment(Element.ALIGN_TOP); head.addElement(titleParagraph); // Cells for score field, and 2nd check initials final Phrase des = new Phrase("Data Entry Score _______", ARIAL_8PT_NORMAL); final PdfPCell desC = new PdfPCell(des); desC.setBorder(0); desC.setPaddingTop(9); desC.setPaddingRight(36); desC.setHorizontalAlignment(Element.ALIGN_RIGHT); final Phrase sci = new Phrase("2nd Check Initials _______", ARIAL_8PT_NORMAL); final PdfPCell sciC = new PdfPCell(sci); sciC.setBorder(0); sciC.setPaddingTop(9); sciC.setPaddingRight(36); sciC.setHorizontalAlignment(Element.ALIGN_RIGHT); // Create a table with a grid cell for each scoresheet on the page PdfPTable wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); for (int i = 0; i < m_numSheets; i++) { if (i > 0 && (orientationIsPortrait || (i % 2) == 0)) { pdfDoc.newPage(); wholePage = getTableForPage(orientationIsPortrait); wholePage.setWidthPercentage(100); } // This table is a single score sheet final PdfPTable scoreSheet = new PdfPTable(2); // scoreSheet.getDefaultCell().setBorder(Rectangle.LEFT | Rectangle.BOTTOM // | Rectangle.RIGHT | Rectangle.TOP); //FIXME DEBUG should be NO_BORDER scoreSheet.getDefaultCell().setBorder(Rectangle.NO_BORDER); scoreSheet.getDefaultCell().setPaddingRight(1); scoreSheet.getDefaultCell().setPaddingLeft(0); scoreSheet.addCell(head); final PdfPTable teamInfo = new PdfPTable(7); teamInfo.setWidthPercentage(100); teamInfo.setWidths(new float[] { 1f, 1f, 1f, 1f, 1f, 1f, .9f }); // Time label cell final Paragraph timeP = new Paragraph("Time:", ARIAL_10PT_NORMAL); timeP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell timeLc = new PdfPCell(scoreSheet.getDefaultCell()); timeLc.addElement(timeP); teamInfo.addCell(timeLc); // Time value cell final Paragraph timeV = new Paragraph(null == m_time[i] ? SHORT_BLANK : m_time[i], COURIER_10PT_NORMAL); final PdfPCell timeVc = new PdfPCell(scoreSheet.getDefaultCell()); timeVc.addElement(timeV); teamInfo.addCell(timeVc); // Table label cell final Paragraph tblP = new Paragraph("Table:", ARIAL_10PT_NORMAL); tblP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell tblLc = new PdfPCell(scoreSheet.getDefaultCell()); tblLc.addElement(tblP); teamInfo.addCell(tblLc); // Table value cell final Paragraph tblV = new Paragraph(m_table[i], COURIER_10PT_NORMAL); final PdfPCell tblVc = new PdfPCell(scoreSheet.getDefaultCell()); tblVc.addElement(tblV); teamInfo.addCell(tblVc); // Round number label cell final Paragraph rndP = new Paragraph("Round:", ARIAL_10PT_NORMAL); rndP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell rndlc = new PdfPCell(scoreSheet.getDefaultCell()); rndlc.addElement(rndP); teamInfo.addCell(rndlc); // Round number value cell final Paragraph rndV = new Paragraph(m_round[i], COURIER_10PT_NORMAL); final PdfPCell rndVc = new PdfPCell(scoreSheet.getDefaultCell()); // rndVc.setColspan(2); rndVc.addElement(rndV); teamInfo.addCell(rndVc); final PdfPCell temp1 = new PdfPCell(scoreSheet.getDefaultCell()); // temp1.setColspan(2); temp1.addElement(new Paragraph("Judge ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp1); // Team number label cell final Paragraph nbrP = new Paragraph("Team #:", ARIAL_10PT_NORMAL); nbrP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell nbrlc = new PdfPCell(scoreSheet.getDefaultCell()); nbrlc.addElement(nbrP); teamInfo.addCell(nbrlc); // Team number value cell final Paragraph nbrV = new Paragraph(null == m_number[i] ? SHORT_BLANK : String.valueOf(m_number[i]), COURIER_10PT_NORMAL); final PdfPCell nbrVc = new PdfPCell(scoreSheet.getDefaultCell()); nbrVc.addElement(nbrV); teamInfo.addCell(nbrVc); // Team division label cell final Paragraph divP = new Paragraph(m_divisionLabel[i], ARIAL_10PT_NORMAL); divP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell divlc = new PdfPCell(scoreSheet.getDefaultCell()); divlc.addElement(divP); divlc.setColspan(2); teamInfo.addCell(divlc); // Team division value cell final Paragraph divV = new Paragraph(m_division[i], COURIER_10PT_NORMAL); final PdfPCell divVc = new PdfPCell(scoreSheet.getDefaultCell()); divVc.setColspan(2); divVc.addElement(divV); teamInfo.addCell(divVc); final PdfPCell temp2 = new PdfPCell(scoreSheet.getDefaultCell()); // temp2.setColspan(2); temp2.addElement(new Paragraph("Team ____", ARIAL_8PT_NORMAL)); teamInfo.addCell(temp2); // Team name label cell final Paragraph nameP = new Paragraph("Team Name:", ARIAL_10PT_NORMAL); nameP.setAlignment(Element.ALIGN_RIGHT); final PdfPCell namelc = new PdfPCell(scoreSheet.getDefaultCell()); namelc.setColspan(2); namelc.addElement(nameP); teamInfo.addCell(namelc); // Team name value cell final Paragraph nameV = new Paragraph(m_name[i], COURIER_10PT_NORMAL); final PdfPCell nameVc = new PdfPCell(scoreSheet.getDefaultCell()); nameVc.setColspan(5); nameVc.addElement(nameV); teamInfo.addCell(nameVc); // add team info cell to the team table final PdfPCell teamInfoCell = new PdfPCell(scoreSheet.getDefaultCell()); teamInfoCell.addElement(teamInfo); teamInfoCell.setColspan(2); scoreSheet.addCell(teamInfoCell); if (null != m_goalsTable) { final PdfPCell goalCell = new PdfPCell(m_goalsTable); goalCell.setBorder(0); goalCell.setPadding(0); goalCell.setColspan(2); scoreSheet.addCell(goalCell); } scoreSheet.addCell(desC); scoreSheet.addCell(sciC); if (null != m_copyright) { final Phrase copyright = new Phrase("\u00A9" + m_copyright, f6i); final PdfPCell copyrightC = new PdfPCell(scoreSheet.getDefaultCell()); copyrightC.addElement(copyright); copyrightC.setBorder(0); copyrightC.setHorizontalAlignment(Element.ALIGN_CENTER); copyrightC.setColspan(2); scoreSheet.addCell(copyrightC); } // the cell in the whole page table that will contain the single score // sheet final PdfPCell scoresheetCell = new PdfPCell(scoreSheet); scoresheetCell.setBorder(0); scoresheetCell.setPadding(0); // Interior borders between scoresheets on a page if (!orientationIsPortrait) { if (i % 2 == 0) { scoresheetCell.setPaddingRight(0.1f * POINTS_PER_INCH); } else { scoresheetCell.setPaddingLeft(0.1f * POINTS_PER_INCH); } } // Add the current scoresheet to the page wholePage.addCell(scoresheetCell); // Add the current table of scoresheets to the document if (orientationIsPortrait || (i % 2 != 0)) { pdfDoc.add(wholePage); } } // Add a blank cells to complete the table of the last page if (!orientationIsPortrait && m_numSheets % 2 != 0) { final PdfPCell blank = new PdfPCell(); blank.setBorder(0); wholePage.addCell(blank); pdfDoc.add(wholePage); } pdfDoc.close(); }
From source file:fll.web.report.FinalComputedScores.java
License:Open Source License
/** * Generate the actual report./*from w w w.j a va 2 s .co m*/ */ private void generateReport(final Connection connection, final OutputStream out, final ChallengeDescription challengeDescription, final String challengeTitle, final Tournament tournament, final PdfPageEventHelper pageHandler, final Set<Integer> bestTeams) throws SQLException, IOException { if (tournament.getTournamentID() != Queries.getCurrentTournament(connection)) { throw new FLLRuntimeException( "Cannot generate final score report for a tournament other than the current tournament"); } final WinnerType winnerCriteria = challengeDescription.getWinner(); final TournamentSchedule schedule; if (TournamentSchedule.scheduleExistsInDatabase(connection, tournament.getTournamentID())) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Found a schedule for tournament: " + tournament); } schedule = new TournamentSchedule(connection, tournament.getTournamentID()); } else { schedule = null; } try { // This creates our new PDF document and declares it to be in portrait // orientation final Document pdfDoc = PdfUtils.createPortraitPdfDoc(out, pageHandler); final Iterator<String> agIter = Queries.getAwardGroups(connection).iterator(); while (agIter.hasNext()) { final String awardGroup = agIter.next(); final ScoreCategory[] subjectiveCategories = challengeDescription.getSubjectiveCategories() .toArray(new ScoreCategory[0]); // Figure out how many subjective categories have weights > 0. final double[] weights = new double[subjectiveCategories.length]; int nonZeroWeights = 0; for (int catIndex = 0; catIndex < subjectiveCategories.length; catIndex++) { weights[catIndex] = subjectiveCategories[catIndex].getWeight(); if (weights[catIndex] > 0.0) { nonZeroWeights++; } } // Array of relative widths for the columns of the score page // Array length varies with the number of subjective scores weighted > // 0. final int numColumnsLeftOfSubjective = 3; final int numColumnsRightOfSubjective = 2; final float[] relativeWidths = new float[numColumnsLeftOfSubjective + nonZeroWeights + numColumnsRightOfSubjective]; relativeWidths[0] = 3f; relativeWidths[1] = 1.0f; relativeWidths[2] = 1.0f; relativeWidths[relativeWidths.length - numColumnsRightOfSubjective] = 1.5f; relativeWidths[relativeWidths.length - numColumnsRightOfSubjective + 1] = 1.5f; for (int i = numColumnsLeftOfSubjective; i < numColumnsLeftOfSubjective + nonZeroWeights; i++) { relativeWidths[i] = 1.5f; } // Create a table to hold all the scores for this division final PdfPTable divTable = new PdfPTable(relativeWidths); divTable.getDefaultCell().setBorder(0); divTable.setWidthPercentage(100); final PdfPTable header = createHeader(challengeTitle, tournament.getName(), awardGroup); final PdfPCell headerCell = new PdfPCell(header); headerCell.setColspan(relativeWidths.length); divTable.addCell(headerCell); if (LOGGER.isTraceEnabled()) { LOGGER.trace("num relative widths: " + relativeWidths.length); for (int i = 0; i < relativeWidths.length; ++i) { LOGGER.trace("\twidth[" + i + "] = " + relativeWidths[i]); } } writeColumnHeaders(schedule, weights, subjectiveCategories, relativeWidths, challengeDescription, divTable); writeScores(connection, subjectiveCategories, weights, relativeWidths, awardGroup, winnerCriteria, tournament, divTable, bestTeams); // Add the division table to the document pdfDoc.add(divTable); // If there is another division to process, start it on a new page if (agIter.hasNext()) { pdfDoc.newPage(); } } pdfDoc.close(); } catch (final ParseException pe) { throw new RuntimeException("Error parsing category weight!", pe); } catch (final DocumentException de) { throw new RuntimeException("Error creating PDF document!", de); } }
From source file:fll.web.report.finalist.AbstractFinalistSchedule.java
License:Open Source License
/** * Create a page for the specified category. * /*from w w w . j av a 2s .c om*/ * @throws DocumentException * @throws SQLException */ private void createCategoryPage(final Document document, final Connection connection, final String category, final String room, final FinalistSchedule schedule) throws DocumentException, SQLException { // header name final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk(String.format("Finalist schedule for %s", category), TITLE_FONT)); para.add(Chunk.NEWLINE); if (null != room && !"".equals(room)) { para.add(new Chunk(String.format("Room: %s", room), TITLE_FONT)); } document.add(para); final PdfPTable schedTable = new PdfPTable(new float[] { 12.5f, 12.5f, 37.5f, 37.5f }); schedTable.setWidthPercentage(100); schedTable.getDefaultCell().setBorder(0); schedTable.getDefaultCell().enableBorderSide(Rectangle.BOTTOM); schedTable.getDefaultCell().setHorizontalAlignment(Element.ALIGN_CENTER); schedTable.addCell(new Phrase("Time", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Team #", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Team Name", SCHEDULE_HEADER_FONT)); schedTable.addCell(new Phrase("Organization", SCHEDULE_HEADER_FONT)); // foreach information output for (final FinalistDBRow row : schedule.getScheduleForCategory(category)) { // time, number, name, organization schedTable.addCell(new Phrase(String.format("%d:%02d", row.getHour(), row.getMinute()), SCHEDULE_FONT)); final Team team = Team.getTeamFromDatabase(connection, row.getTeamNumber()); schedTable.addCell(new Phrase(String.valueOf(team.getTeamNumber()), SCHEDULE_FONT)); schedTable.addCell(new Phrase(team.getTeamName(), SCHEDULE_FONT)); schedTable.addCell(new Phrase(team.getOrganization(), SCHEDULE_FONT)); } document.add(schedTable); document.add(Chunk.NEXTPAGE); }
From source file:fll.web.report.finalist.TeamFinalistSchedule.java
License:Open Source License
protected void processRequest(final HttpServletRequest request, final HttpServletResponse response, final ServletContext application, final HttpSession session) throws IOException, ServletException { Connection connection = null; try {// w w w.j av a 2 s . c o m final DataSource datasource = ApplicationAttributes.getDataSource(application); connection = datasource.getConnection(); final ChallengeDescription challengeDescription = ApplicationAttributes .getChallengeDescription(application); // create simple doc and write to a ByteArrayOutputStream final Document document = new Document(PageSize.LETTER); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final PdfWriter writer = PdfWriter.getInstance(document, baos); writer.setPageEvent(new ReportPageEventHandler(HEADER_FONT, "Finalist Callback Schedule", challengeDescription.getTitle(), Queries.getCurrentTournamentName(connection))); document.open(); document.addTitle("Ranking Report"); // add content final int currentTournament = Queries.getCurrentTournament(connection); final Collection<String> divisions = FinalistSchedule.getAllDivisions(connection, currentTournament); final Collection<FinalistSchedule> schedules = new LinkedList<FinalistSchedule>(); for (final String division : divisions) { final FinalistSchedule schedule = new FinalistSchedule(connection, currentTournament, division); schedules.add(schedule); } final Map<Integer, TournamentTeam> tournamentTeams = Queries.getTournamentTeams(connection, currentTournament); final List<Integer> teamNumbers = new LinkedList<Integer>(tournamentTeams.keySet()); Collections.sort(teamNumbers); for (final int teamNum : teamNumbers) { final TournamentTeam team = tournamentTeams.get(teamNum); for (final FinalistSchedule schedule : schedules) { final List<FinalistDBRow> finalistTimes = schedule.getScheduleForTeam(teamNum); final Map<String, String> rooms = schedule.getRooms(); if (!finalistTimes.isEmpty()) { final Paragraph para = new Paragraph(); para.add(Chunk.NEWLINE); para.add(new Chunk("Finalist times for Team " + teamNum, TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk(team.getTeamName() + " / " + team.getOrganization(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk("Award Group: " + team.getAwardGroup(), TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); final PdfPTable table = new PdfPTable(3); // table.getDefaultCell().setBorder(0); table.setWidthPercentage(100); table.addCell(new Phrase(new Chunk("Time", HEADER_FONT))); table.addCell(new Phrase(new Chunk("Room", HEADER_FONT))); table.addCell(new Phrase(new Chunk("Category", HEADER_FONT))); for (final FinalistDBRow row : finalistTimes) { final String categoryName = row.getCategoryName(); String room = rooms.get(categoryName); if (null == room) { room = ""; } table.addCell(new Phrase(String.format("%d:%02d", row.getHour(), row.getMinute()), VALUE_FONT)); table.addCell(new Phrase(new Chunk(room, VALUE_FONT))); table.addCell(new Phrase(new Chunk(categoryName, VALUE_FONT))); } // foreach row para.add(table); document.add(para); document.add(Chunk.NEXTPAGE); } // non-empty list of teams } // foreach schedule } // foreach team document.close(); // setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "filename=teamFinalistSchedule.pdf"); // the content length is needed for MSIE!!! response.setContentLength(baos.size()); // write ByteArrayOutputStream to the ServletOutputStream final ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush(); } catch (final SQLException e) { LOG.error(e, e); throw new RuntimeException(e); } catch (final DocumentException e) { LOG.error(e, e); throw new RuntimeException(e); } finally { SQLFunctions.close(connection); } }
From source file:fr.ensicaen.yousign.GenerePDF.java
public void genere() { try {/*from ww w. j a va 2 s . co m*/ OutputStream file = new FileOutputStream(util.generePDFFilenameToUse()); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); // // Affichage du logo, de la date et l'heure et avec ou sans frais // document.add(addEntete()); // // Caractristiques du missionnaire (table: nom, prenom, courriel = 1re colonne, adresse = 2me colonne // PdfPTable tableIdentite = new PdfPTable(2); tableIdentite.setWidthPercentage(100); PdfPCell nomCell = new PdfPCell( new Phrase(new Chunk("Nom: " + util.getOrdreMission().getNomMissionnaire() + "\n" + "Prenom: " + util.getOrdreMission().getPrenomMissionnaire() + "\n\n" + "Courriel: " + util.getOrdreMission().getEmailMissionnaire(), fontItemSection))); nomCell.setBorder(Rectangle.NO_BORDER); tableIdentite.addCell(nomCell); Chunk adresseChunk = new Chunk("Adresse: " + "\n" + util.getOrdreMission().getRueMissionnaire() + "\n" + util.getOrdreMission().getCodepostalMissionnaire() + " " + util.getOrdreMission().getVilleMissionnaire() + "\n" + util.getOrdreMission().getPaysMissionnaire(), fontItemSection); PdfPCell adresseCell = new PdfPCell(new Phrase(adresseChunk)); adresseCell.setBorder(Rectangle.NO_BORDER); tableIdentite.addCell(adresseCell); Paragraph identite; identite = new Paragraph(); addEmptyLine(identite, 1); identite.add(tableIdentite); document.add(identite); // // Numero IBAN // Paragraph iban = new Paragraph(); addEmptyLine(iban, 1); iban.add(new Chunk("Numro IBAN: " + util.getOrdreMission().getIban1() + " " + util.getOrdreMission().getIban2() + " " + util.getOrdreMission().getIban3() + " " + util.getOrdreMission().getIban4() + " " + util.getOrdreMission().getIban5() + " " + util.getOrdreMission().getIban6() + " " + util.getOrdreMission().getIban7(), fontItemSection)); document.add(iban); // // Motif de la mission // Paragraph mission = new Paragraph(); addEmptyLine(mission, 1); mission.add( new Chunk("Motif de la mission: " + util.getOrdreMission().getMotifMission(), fontItemSection)); addEmptyLine(mission, 1); // // Dtails de la mission (lieu, dates, ...) // PdfPTable tableMission = new PdfPTable(7); tableMission.setWidthPercentage(100); float[] columnWidths = { 1f, 2f, 1.5f, 1f, 2f, 1.5f, 1f }; tableMission.setWidths(columnWidths); PdfPCell cell; // // Ligne d'entete du tableau des dtails de la mission // tableMission.addCell(""); cell = new PdfPCell(new Phrase("Lieu de dpart")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase("Date")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase("Heure")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase("Lieu d'arrive")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase("Date")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase("Heure")); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); // // description du voyage aller // tableMission.addCell("Aller"); cell = new PdfPCell(new Phrase(util.getOrdreMission().getLieuDepartAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getDateDepartAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getHeureDepartAller() + ":" + util.getOrdreMission().getMinuteDepartAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getLieuArriveeAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getDateArriveeAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getHeureArriveeAller() + ":" + util.getOrdreMission().getMinuteArriveeAller())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); // // Description du voyage retour // tableMission.addCell("Retour"); cell = new PdfPCell(new Phrase(util.getOrdreMission().getLieuDepartRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getDateDepartRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getHeureDepartRetour() + ":" + util.getOrdreMission().getMinuteDepartRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getLieuArriveeRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getDateArriveeRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); cell = new PdfPCell(new Phrase(util.getOrdreMission().getHeureArriveeRetour() + ":" + util.getOrdreMission().getMinuteArriveeRetour())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); tableMission.addCell(cell); mission.add(tableMission); document.add(mission); // // Moyens de transport // Paragraph moyensTransport = new Paragraph(); addEmptyLine(moyensTransport, 1); moyensTransport.add(new Chunk("Moyens de transport utiliss\n", fontTitleSection)); if (util.use("Passager")) { moyensTransport.add(new Chunk("Pas de frais de transport comme passager de la voiture de: " + util.getOrdreMission().getNomConducteur() + "\n", fontItemSection)); } if (util.use("Train")) { moyensTransport.add(new Chunk("Train: Classe: " + util.getOrdreMission().getTrainClasse() + " Prix des billets: " + util.getOrdreMission().getTrainPrixBillet() + " Bon de commande: " + util.getOrdreMission().getTrainBonCommande() + " Carte affaire: " + util.getOrdreMission().getTrainCarteAffaire() + "\n", fontItemSection)); } if (util.use("Avion_Bateau")) { moyensTransport.add(new Chunk( "Avion ou Bateau: Classe: " + util.getOrdreMission().getAvionBateauClasse() + " Prix des billets: " + util.getOrdreMission().getAvionBateauPrixBillet() + " Bon de commande: " + util.getOrdreMission().getAvionBateauBonCommande() + " Carte affaire: " + util.getOrdreMission().getAvionBateauCarteAffaire() + "\n", fontItemSection)); } if (util.use("Vehicule_Service")) { moyensTransport.add(new Chunk( "Voiture de service: " + util.getOrdreMission().getVehiculeService() + " Nombre de kilomtres: " + util.getOrdreMission().getVehiculeServiceNombreKilometres() + "\n", fontItemSection)); moyensTransport.add(new Chunk( "Nom des passagers: " + util.getOrdreMission().getVehiculeServiceNomPassagers() + "\n", fontItemSection)); } if (util.use("Vehicule_Personnel")) { moyensTransport.add(new Chunk( "En vertu du dcret No 2006-781 du 3 juillet 2006: je soussign, " + util.getOrdreMission().getPrenomMissionnaire() + " " + util.getOrdreMission().getNomMissionnaire() + ", sollicite l'autorisation ", fontItemSection)); moyensTransport.add(new Chunk("d'utiliser mon vhicule de marque " + util.getOrdreMission().getVehiculePersonnelMarque() + ", de puissance " + util.getOrdreMission().getVehiculePersonnelPuissance() + ", d'immatriculation: " + util.getOrdreMission().getVehiculePersonnelImmatriculation(), fontItemSection)); moyensTransport.add(new Chunk( ", de date d'acquisition " + util.getOrdreMission().getVehiculePersonnelDateAcquisition() + " pour me rendre " + util.getOrdreMission().getLieuArriveeAller(), fontItemSection)); moyensTransport.add(new Chunk(" et dclare avoir souscrit auprs de " + util.getOrdreMission().getVehiculePersonnelNomAssureur() + " une police d'assurance garantissant de manire illimite ma responsabilit personnelle aux termes ", fontItemSection)); moyensTransport.add(new Chunk( "des articles 1382, 1383, 1384 du Code Civil, ainsi qu'ventuellement la responsabilit de l'Etat, y compris le cas o celle-ci est engage vis--vis des personnes transportes. ", fontItemSection)); moyensTransport .add(new Chunk("Cette police comprend l'assurance contentieuse.\n", fontItemSection)); moyensTransport.add(new Chunk( "DECLARATION COMPLEMENTAIRE: je certifie avoir contract l'assurance complmentaire couvrant tous les risques non compris dans l'assurance obligatoire.\n", fontItemSection)); } addEmptyLine(moyensTransport, 1); if (util.use("taxi")) { moyensTransport.add( new Chunk("Le Directeur autorise le remboursement d'un taxi " + "\n", fontItemSection)); } if (util.use("vehicule_location")) { moyensTransport .add(new Chunk("Le Directeur autorise le remboursement d'un vhicule de location " + "\n", fontItemSection)); } if (util.use("Vehicule_Service") || util.use("Vehicule_Personnel") || util.use("vehicule_location")) { moyensTransport .add(new Chunk( "\nJustication de l'utilisation du vhicule personnel ou de la location:" + util.getOrdreMission().getVehiculeJustificatif() + "\n", fontItemSection)); moyensTransport.add( new Chunk("\nJe certifie tre en possession du permis de conduire depuis plus d'un an\n", fontBoldItemSection)); } document.add(moyensTransport); // // Frais annexe // Paragraph fraisAnnexe = new Paragraph(); addEmptyLine(fraisAnnexe, 1); fraisAnnexe.add(new Chunk("Frais Annexe\n", fontTitleSection)); fraisAnnexe.add(new Chunk("Frais d'inscription: " + util.getOrdreMission().getFraisInscription() + " Montant: " + util.getOrdreMission().getMontantInscription() + " ", fontItemSection)); document.add(fraisAnnexe); Paragraph avance = new Paragraph(); addEmptyLine(avance, 1); avance.add(new Chunk("Avance: ", fontTitleSection)); avance.add(new Chunk(util.getOrdreMission().getAvance(), fontItemSection)); document.add(avance); // // Informations financieres // Paragraph finance = new Paragraph(); addEmptyLine(finance, 1); finance.add(new Chunk("Informations financires\n", fontTitleSection)); finance.add(new Chunk("Centre financier: " + util.getOrdreMission().getCentreFinancier() + " Projet ou eOTP: " + util.getOrdreMission().getProjet() + "\n", fontItemSection)); finance.add(new Chunk("Responsable financier: " + util.getOrdreMission().getPrenomResponsableFinancier() + " " + util.getOrdreMission().getNomResponsableFinancier() + "\n", fontItemSection)); finance.add( new Chunk("Autorit hirarchique: " + util.getOrdreMission().getPrenomAutoriteHierarchique() + " " + util.getOrdreMission().getNomAutoriteHierarchique(), fontItemSection)); document.add(finance); // // Informations complementaires eventuelles // if (util.getOrdreMission().getInformationsComplementaires() != null) { Paragraph informationsComplementaires = new Paragraph(); informationsComplementaires.add(new Chunk("\nInformations complementaires: ", fontTitleSection)); informationsComplementaires .add(new Chunk(util.getOrdreMission().getInformationsComplementaires(), fontItemSection)); document.add(informationsComplementaires); } document.close(); file.close(); } catch (DocumentException | IOException e) { System.err .println("Erreur a la generation du fichier " + util.getPdfFileName() + ": " + e.getMessage()); } }
From source file:fr.ensicaen.yousign.GenerePDF.java
private Paragraph addEntete() { Paragraph paragraph = new Paragraph(); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); try {/*from w w w . jav a2 s.c om*/ // // Affichage du logo // PdfPCell logoCell = new PdfPCell(Image.getInstance(YousignConfig.LOGO), false); // false: le logo ne remplit pas toute la cellule logoCell.setBorder(Rectangle.NO_BORDER); table.addCell(logoCell); // // Affichage de la date et du titre // Date date = new Date(); DateFormat format_fr = DateFormat.getDateInstance(DateFormat.FULL, Locale.FRENCH); PdfPCell titleCell = new PdfPCell(new Phrase( new Chunk(format_fr.format(date) + "\n\n" + title + util.getOrdreMission().getNumeroMission() + "\n" + util.getOrdreMission().getFrais(), fontItemTitleSection))); titleCell.setBorder(Rectangle.NO_BORDER); titleCell.setHorizontalAlignment(Element.ALIGN_CENTER); titleCell.setVerticalAlignment(Element.ALIGN_MIDDLE); table.addCell(titleCell); } catch (BadElementException | IOException ex) { Logger.getLogger(GenerePDF.class.getName()).log(Level.SEVERE, null, ex); } paragraph.add(table); return paragraph; }
From source file:fr.pigouchet.gestion.util.GeneratePdf.java
public static PdfPTable oneCategory(Categorie category) throws DocumentException { PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); table.setWidths(new int[] { 1, 2, 1, 1, 1 }); dataSubCate = Connection.listCategoryToSubCategory(category); for (SubCategorie subcategorie : dataSubCate) { PdfPCell cell;/*from w ww . j a v a 2 s .com*/ if (passed == true) { cell = new PdfPCell(new Phrase(" ")); cell.setColspan(5); table.addCell(cell); } cell = new PdfPCell(new Phrase(category.getNom(), subFont)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(subcategorie.getNom(), subFont)); cell.setColspan(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Code", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Achat", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Artisant", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Detail", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); data = Connection.listSubCategoryToProduit(subcategorie); for (Produit produit1 : data) { cell = new PdfPCell(new Phrase(produit1.getCode(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getNom(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceAchat(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceArtisant(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceDetail(), smallFont)); table.addCell(cell); } passed = true; } return table; }
From source file:fr.pigouchet.gestion.util.GeneratePdf.java
public static PdfPTable allSubCategory(Categorie categorie, Document document) throws DocumentException { PdfPTable table = new PdfPTable(5); table.setWidthPercentage(100); table.setWidths(new int[] { 1, 2, 1, 1, 1 }); dataSubCate = Connection.listCategoryToSubCategory(categorie); for (SubCategorie subcategorie : dataSubCate) { PdfPCell cell;/*from w ww .j a v a 2 s . co m*/ if (passed == true) { cell = new PdfPCell(new Phrase(" ")); cell.setColspan(5); table.addCell(cell); } cell = new PdfPCell(new Phrase(categorie.getNom(), subFont)); cell.setColspan(1); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(subcategorie.getNom(), subFont)); cell.setColspan(5); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Code", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Nom", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Achat", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Artisant", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase("Detail", smallFont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); data = Connection.listSubCategoryToProduit(subcategorie); for (Produit produit1 : data) { cell = new PdfPCell(new Phrase(produit1.getCode(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getNom(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceAchat(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceArtisant(), smallFont)); table.addCell(cell); cell = new PdfPCell(new Phrase(produit1.getPriceDetail(), smallFont)); table.addCell(cell); } passed = true; } return table; }