List of usage examples for com.itextpdf.text Chunk NEWLINE
Chunk NEWLINE
To view the source code for com.itextpdf.text Chunk NEWLINE.
Click Source Link
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSectionDocumentProvisions(Section section) { String sectionIntro = "Stakeholders exchange information by means of documents with other stakeholders. The following description enlists all the provisions from one role/agent representing the stakeholder, to other roles/agents. %iDocument provision% is represented as an arrow from the provider to the providee, with a rectangle representing the document. The security needs expressed over the provisions are described, if applicable. Security needs are specified with the help of labels that appear below the document."; section.add(createParagraph(sectionIntro)); List<Actor> selActor = getDocumentProvisionsActors(); List<Paragraph> phrases = new ArrayList<Paragraph>(); for (Actor a : selActor) { for (Provision p : a.getOutgoingProvisions()) { Paragraph par = createParagraph("%b" + a.getName() + "% provides document %i" + p.getSourceResource().getName() + "% to %b" + p.getTarget().getName() + "%."); List<String> secNeeds = buildProvisionSecNeedList(p); if (secNeeds.size() > 0) { par.add(new Phrase(" The following security needs apply to this provision:")); par.add(Chunk.NEWLINE); par.add(new Phrase(separateListOfString(secNeeds) + ".")); }//from w ww . j a v a 2 s. c o m phrases.add(par); } } /* * for (Actor a : selActor) { StringBuilder sbInc = new StringBuilder(); * sbInc.append("%b" + a.getName() + "% is provided by "); int incCount * = 0; for (Provision p : a.getIncomingProvisions()) { if (incCount > * 0) sbInc.append(", and is provided by "); sbInc.append("%i" + * p.getSource().getName() + "% document %i" + * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) { * sbInc.append(" and requires %b" + p.getSource().getName() + * "% to ensure %iintegrity of transmission% over the provision of this document" * ); } * * incCount++; } * * StringBuilder sbOut = new StringBuilder(); int outCount = 0; for * (Provision p : a.getOutgoingProvisions()) { if (outCount > 0) * sbOut.append(", and it provides to "); sbOut.append("%i" + * p.getTarget().getName() + "% document %i" + * p.getSourceResource().getName() + "%"); if (p.isIntegrity()) { * sbInc.append(" and requires %iAvailability% level of " + * p.getAvailabilityValue() + "%"); } outCount++; } * * StringBuilder sb = new StringBuilder(); if (incCount > 0) { if * (outCount > 0) { sb.append(sbInc.toString() + * " while it provides to " + sbOut.toString() + "."); } else { * sb.append(sbInc.toString() + "."); } } else { if (outCount > 0) { * sb.append("%b" + a.getName() + "% provides to " + sbOut.toString() + * "."); } } * * if (sb.length() > 0) { phrases.add(createParagraph(sb.toString())); } * } */ if (phrases.size() != 0) { String s = "In the " + getProjectName() + " project " + socialDiagRef() + ", we have the following %idocument provisions%:"; section.add(createParagraph(s)); section.add(listParagraphs(phrases)); section.add(createParagraph(ftc.getTable(FigureConstant.PROVISION_TABLE) + " summarises the %idocument provisions% for the " + getProjectName() + " project.")); List<String[]> headers = new ArrayList<String[]>(); headers.add(new String[] { "Providor" }); headers.add(new String[] { "Document" }); headers.add(new String[] { "Providee" }); headers.add(new String[] { "Security", "Needs" }); headers.add(new String[] { "Provision", "Descr." }); PdfPTable table = createTable(headers); for (Actor a : selActor) { if (a.getOutgoingProvisions().size() > 0) { PdfPCell cell = getContentCell(); cell.setPhrase(new Phrase(a.getName(), TABLE_CONTENT)); cell.setRowspan(a.getOutgoingProvisions().size()); table.addCell(cell); for (Provision p : a.getOutgoingProvisions()) { table.addCell(getContentCell(p.getSourceResource().getName())); table.addCell(getContentCell(p.getTarget().getName())); List<String> sn = buildProvisionSecNeedList(p); Phrase pr = null; for (int i = 0; i < sn.size(); i++) { if (i == 0) pr = new Phrase(sn.get(i), TABLE_CONTENT_SMALL); else { pr.add(Chunk.NEWLINE); pr.add(new Phrase(sn.get(i), TABLE_CONTENT_SMALL)); } } PdfPCell c = getContentCell(); c.addElement(pr); table.addCell(c); table.addCell(getContentCell(p.getDescription())); } } } addTableCaption(table, ftc.getTable(FigureConstant.PROVISION_TABLE) + " - Document Provisions"); section.add(table); table.setComplete(true); } else { section.add(createParagraph("In the " + getProjectName() + " project there are no document provisions taking place for the given agents/roles.")); } section.setComplete(true); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private void buildSecurityRequirementsChapterContentTable(Chapter chapter) { List<Actor> selActors = getSecurityRequirementsActors(); List<String[]> headers = new ArrayList<String[]>();// headers.add(new String[] { "Responsible" }); headers.add(new String[] { "Security Requirement" }); headers.add(new String[] { "Requester" }); headers.add(new String[] { "Description" }); PdfPTable table = createTable(headers); for (Actor act : selActors) { List<PdfPCell> cells = new ArrayList<PdfPCell>(); for (Delegation d : act.getIncomingDelegations()) { if (selActors.contains(d.getSource()) && (d.getTimesTransferable() >= 0 || d.getRepudiationType() != RepudiationType.NO_REPUDIATION || d.getRedundancyType() != RedundancyType.NO_REDUNDANCY || d.isAvailability())) { if (d.getRedundancyType() != RedundancyType.NO_REDUNDANCY) { String red = ""; switch (d.getRedundancyType()) { case TRUE_SINGLE: red = "single-actor-true-redundancy"; break; case TRUE_MULTI: red = "multi-actor-true-redundancy"; break; case FALLBACK_SINGLE: red = "single-actor-fallback-redundancy"; break; case FALLBACK_MULTI: red = "single-actor-fallback-redundancy"; break; }/*w w w . java 2s .c om*/ cells.add(getContentCell(new String[] { red, "(" + d.getSourceGoal().getName() + ")" })); cells.add(getContentCell(d.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getTarget().getName() + " requires " + red + " for goal " + d.getSourceGoal().getName() + ","); sb.append("when delegating " + d.getSourceGoal().getName() + " to " + d.getTarget().getName() + "."); cells.add(getContentCell(sb.toString())); } if (d.getTimesTransferable() >= 0) { String s = "no-delegation"; cells.add(getContentCell(new String[] { s, "(" + d.getSourceGoal().getName() + ")" })); cells.add(getContentCell(d.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getTarget().getName() + " requires " + s + " for goal " + d.getSourceGoal().getName() + ","); sb.append("when delegating " + d.getSourceGoal().getName() + " to " + d.getTarget().getName() + "."); cells.add(getContentCell(sb.toString())); } if (d.getRepudiationType() == RepudiationType.DUAL_REPUDIATION || d.getRepudiationType() == RepudiationType.DELEGATEEE_REPUDIATION) { cells.add(getContentCell(new String[] { "non-repudiation-of-acceptance", "(delegated(" + d.getSource().getName() + "," + d.getTarget().getName() + "," + d.getSourceGoal().getName() + "))" })); cells.add(getContentCell(d.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getSource().getName() + " require non-repudiation-of-acceptance for goal " + d.getSourceGoal().getName() + ","); sb.append("when delegating " + d.getSourceGoal().getName() + " to " + d.getTarget().getName() + "."); cells.add(getContentCell(sb.toString())); } if (d.isAvailability()) { cells.add(getContentCell(new String[] { "availability", "(" + d.getSourceGoal().getName() + "," + d.getAvailabilityValue() + "%)" })); cells.add(getContentCell(d.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getSource().getName() + " require " + d.getTarget().getName() + " to assure an availability level of " + d.getAvailabilityValue() + "% for goal " + d.getSourceGoal().getName() + "."); cells.add(getContentCell(sb.toString())); } } } for (Delegation d : act.getOutgoingDelegations()) { if (selActors.contains(d.getTarget()) && (d.getRepudiationType() != RepudiationType.NO_REPUDIATION || d.isTrustworthiness())) { if (d.getRepudiationType() == RepudiationType.DUAL_REPUDIATION || d.getRepudiationType() == RepudiationType.DELEGATOR_REPUDIATION) { cells.add(getContentCell(new String[] { "non-repudiation-of-delegation", "(delegated(" + d.getSource().getName() + "," + d.getTarget().getName() + "," + d.getSourceGoal().getName() + "))" })); cells.add(getContentCell(d.getTarget().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getTarget().getName() + " require non-repudiation-of-delegation for goal " + d.getSourceGoal().getName() + ","); sb.append("when delegated " + d.getSourceGoal().getName() + " by " + d.getSource().getName() + "."); cells.add(getContentCell(sb.toString())); } if (d.isTrustworthiness()) { cells.add(getContentCell( new String[] { "trustworthiness", "(delegatedTo(" + d.getTarget().getName() + ", trustworthiness level: " + d.getTrustworthinessValue() + "))" })); cells.add(getContentCell(d.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(d.getSource().getName() + " will delegate to " + d.getTarget().getName() + " that have trustwhorthiness level only grater than " + d.getTrustworthinessValue()); cells.add(getContentCell(sb.toString())); } } } for (Provision p : act.getIncomingProvisions()) { if (selActors.contains(p.getTarget()) && (p.isAvailability())) { if (p.isAvailability()) { cells.add(getContentCell(new String[] { "availability", "(" + p.getSourceResource().getName() + "," + p.getAvailabilityValue() + "%)" })); cells.add(getContentCell(p.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(p.getSource().getName() + " require " + p.getTarget().getName() + " to assure an availability level of " + p.getAvailabilityValue() + "% for document " + p.getSourceResource().getName() + "."); cells.add(getContentCell(sb.toString())); } } } for (Provision p : act.getOutgoingProvisions()) { if (selActors.contains(p.getTarget()) && (p.isIntegrity() || p.isConfidentiality())) { if (p.isIntegrity()) { cells.add( getContentCell(new String[] { "integrity", "(provided(" + p.getSource().getName() + "," + p.getTarget().getName() + "," + p.getSourceResource().getName(), "))" })); cells.add(getContentCell(p.getSource().getName())); StringBuilder sb = new StringBuilder(); String a = p.getTarget().getName(); String b = p.getSource().getName(); String d = p.getSourceResource().getName(); sb.append(a + " requires " + b + " to ensure integrity of transmission over the provision of document " + d + ", when " + b + " provides " + d + " to " + a + "."); cells.add(getContentCell(sb.toString())); } if (p.isConfidentiality()) { cells.add( getContentCell(new String[] { "confidentiality", "(provided(" + p.getSource().getName() + "," + p.getTarget().getName() + "," + p.getSourceResource().getName(), "))" })); cells.add(getContentCell(p.getSource().getName())); StringBuilder sb = new StringBuilder(); String a = p.getTarget().getName(); String b = p.getSource().getName(); String d = p.getSourceResource().getName(); sb.append(a + " requires " + b + " to ensure confidentiality of transmission over the provision of document " + d + ", when " + b + " provides " + d + " to " + a + "."); cells.add(getContentCell(sb.toString())); } } } for (Authorisation a : act.getIncomingAuthorisations()) { if (selActors.contains(a.getSource()) && a.getResources().size() > 0 && (a.isDistribution() || a.isModification() || a.isUsage() || a.isProduce())) { List<String> res = new ArrayList<String>(); List<String> goal = new ArrayList<String>(); for (IResource r : a.getResources()) { res.add(r.getName()); } for (Goal g : a.getGoals()) { goal.add(g.getName()); } if (!a.isUsage()) { String s = "non-usage"; cells.add(getContentCell( new String[] { s, "(" + separateListOfString(res, ",", ",") + ")" })); cells.add(getContentCell(a.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(a.getSource().getName() + " requires " + a.getTarget().getName() + " " + s + " of Information "); sb.append(separateListOfString(res) + "."); cells.add(getContentCell(sb.toString())); } if (!a.isModification()) { String s = "non-modification"; cells.add(getContentCell( new String[] { s, "(" + separateListOfString(res, ",", ",") + ")" })); cells.add(getContentCell(a.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(a.getSource().getName() + " requires " + a.getTarget().getName() + " " + s + " of Information "); sb.append(separateListOfString(res) + "."); cells.add(getContentCell(sb.toString())); } if (!a.isProduce()) { String s = "non-production"; cells.add(getContentCell( new String[] { s, "(" + separateListOfString(res, ",", ",") + ")" })); cells.add(getContentCell(a.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(a.getSource().getName() + " requires " + a.getTarget().getName() + " " + s + " of Information "); sb.append(separateListOfString(res) + "."); cells.add(getContentCell(sb.toString())); } if (!a.isDistribution()) { String s = "non-disclosure"; cells.add(getContentCell( new String[] { s, "(" + separateListOfString(res, ",", ",") + ")" })); cells.add(getContentCell(a.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(a.getSource().getName() + " requires " + a.getTarget().getName() + " " + s + " of Information "); sb.append(separateListOfString(res) + "."); cells.add(getContentCell(sb.toString())); } if (a.getGoals().size() > 0) { String s = "need-to-know"; cells.add(getContentCell(new String[] { s, "(" + separateListOfString(res, ",", ",") + ")", "(" + separateListOfString(goal, ",", ",") + ")" })); cells.add(getContentCell(a.getSource().getName())); StringBuilder sb = new StringBuilder(); sb.append(a.getSource().getName() + " requires " + a.getTarget().getName() + " " + s + " of Information "); sb.append(separateListOfString(res) + ", in the scope of goal " + separateListOfString(goal) + "."); cells.add(getContentCell(sb.toString())); } } } PdfPCell respCell = getContentCell(act.getName()); if (cells.size() > 0) { if (cells.size() >= 3) { respCell.setRowspan(cells.size() / 3); } table.addCell(respCell); for (PdfPCell c : cells) { table.addCell(c); } } } List<PdfPCell> cells = new ArrayList<PdfPCell>(); for (Actor act : selActors) { if (act instanceof Role) { Role r = (Role) act; for (IncompatibleDuties id : r.getIncompatibleDutiesIn()) { cells.add(getContentCell(new String[] { "not-play-both", "(" + ((Role) id.getSource()).getName() + "," + ((Role) id.getTarget()).getName() + ")" })); cells.add(getContentCell( "Any agent that play " + r.getName() + " or " + ((Role) id.getSource()).getName() + ", is required not to play (adopt) the other role too.")); } } for (Goal g : act.getGoals()) { for (IncompatibleDuties id : g.getIncompatibleDutiesIn()) { cells.add(getContentCell(new String[] { "not-achieve-both", "(" + g.getName() + "," + ((Goal) id.getSource()).getName() + ")" })); cells.add(getContentCell( "Any agent that achieves " + g.getName() + " or " + ((Goal) id.getSource()).getName() + ", is required not to achieve the other goal too.")); } for (CompatibleDuties cd : g.getCompatibleDutiesIn()) { cells.add(getContentCell(new String[] { "achieve-in-combination", "(" + g.getName() + "," + ((Goal) cd.getSource()).getName() + ")" })); cells.add(getContentCell("Any agent that achieves one of " + g.getName() + " or " + ((Goal) cd.getSource()).getName() + ", is required to achieve the other goal too.")); } } /* * for(Goal g:act.getGoals()){ for (IncompatibleDuties id : * g.getIncompatibleDutiesIn()) { cells.add(getContentCell(new * String[] {"achieves(a,"+g.getName()+")", * "then not achieve(a,"+((Goal)id.getSource()).getName()+")"})); * cells * .add(getContentCell("Org requires any agent a that achieves " * +g.getName * ()+" not to achieve "+((Goal)id.getSource()).getName())); } for * (IncompatibleDuties id : g.getIncompatibleDutiesOut()) { * cells.add(getContentCell(new String[] * {"achieves(a,"+g.getName()+")", * "then not achieve(a,"+((Goal)id.getTarget()).getName()+")"})); * cells * .add(getContentCell("Org requires any agent a that achieves " * +g.getName * ()+" not to achieve "+((Goal)id.getTarget()).getName())); } * * for (CompatibleDuties cd : g.getCompatibleDutiesIn()) { * cells.add(getContentCell(new String[] * {"achieves(a,"+g.getName()+")", * "then achieve(a,"+((Goal)cd.getSource()).getName()+")"})); * cells.add * (getContentCell("Org requires any agent a that achieves " * +g.getName * ()+" to achieve "+((Goal)cd.getSource()).getName()+" as well")); * } for (CompatibleDuties cd : g.getCompatibleDutiesOut()) { * cells.add(getContentCell(new String[] * {"achieves(a,"+g.getName()+")", * "then achieve(a,"+((Goal)cd.getTarget()).getName()+")"})); * cells.add * (getContentCell("Org requires any agent a that achieves " * +g.getName * ()+" to achieve "+((Goal)cd.getTarget()).getName()+" as well")); * } } */ } PdfPCell respCell = getContentCell("\"Any agents\""); if (cells.size() > 0) { if (cells.size() >= 2) { respCell.setRowspan(cells.size() / 2); } table.addCell(respCell); for (int i = 0; i < cells.size(); i++) { table.addCell(cells.get(i)); table.addCell(getContentCell("-")); table.addCell(cells.get(++i)); } } addTableCaption(table, ftc.getTable(FigureConstant.COMM_TABLE) + " - Security Requirements for the " + getProjectName() + " Project"); chapter.add(table); table.setComplete(true); boolean addAuthTable = false; // Chapter section = chapter; List<String[]> headers2 = new ArrayList<String[]>(); headers2.add(new String[] { "Authorisor" }); headers2.add(new String[] { "Information" }); headers2.add(new String[] { "Goal" }); headers2.add(new String[] { "Operation" }); headers2.add(new String[] { "Authorisee" }); headers2.add(new String[] { "Description" }); PdfPTable table2 = createTable(headers2); for (Actor a : selActors) { List<Authorisation> validAuth = new ArrayList<Authorisation>(); for (Authorisation au : a.getOutgoingAuthorisations()) { if (isValidAuth(au)) validAuth.add(au); } if (validAuth.size() > 0) { addAuthTable = true; PdfPCell actorCell = getContentCell(a.getName()); actorCell.setRowspan(validAuth.size()); table2.addCell(actorCell); for (Authorisation au : validAuth) { Phrase p = null; for (int i = 0; i < au.getResources().size(); i++) { if (i == 0) p = new Phrase(au.getResources().get(i).getName(), TABLE_CONTENT_SMALL); else { p.add(Chunk.NEWLINE); p.add(new Phrase(au.getResources().get(i).getName(), TABLE_CONTENT_SMALL)); } } /* * com.itextpdf.text.List resList = new * com.itextpdf.text.List(com.itextpdf.text.List.ORDERED, * com.itextpdf.text.List.NUMERICAL); for (IResource r : * au.getResources()) { ListItem listItem = new ListItem(new * Phrase(r.getName(), TABLE_CONTENT)); * resList.add(listItem); } */ PdfPCell c = getContentCell(); c.addElement(p); table2.addCell(c); // -------------------------------------// if (au.getGoals().size() > 0) { Phrase p1 = null; for (int i = 0; i < au.getGoals().size(); i++) { if (i == 0) p1 = new Phrase(au.getGoals().get(i).getName(), TABLE_CONTENT_SMALL); else { p1.add(Chunk.NEWLINE); p1.add(new Phrase(au.getGoals().get(i).getName(), TABLE_CONTENT_SMALL)); } } /* * com.itextpdf.text.List goalList = new * com.itextpdf.text * .List(com.itextpdf.text.List.ORDERED, * com.itextpdf.text.List.NUMERICAL); for (Goal g : * au.getGoals()) { ListItem listItem = new ListItem(new * Phrase(g.getName(), TABLE_CONTENT)); * goalList.add(listItem); } */ PdfPCell c1 = getContentCell(); c1.addElement(p1); table2.addCell(c1); } else { table2.addCell(getContentCell("")); } // -------------------------------------// table2.addCell(getContentCell(getOperationsTable(au))); // -------------------------------------// table2.addCell(getContentCell(au.getTarget().getName())); if (au.getTimesTransferable() == 0) { table2.addCell(getContentCell("Non-transferable authority")); } else { table2.addCell(getContentCell("Transferable authority")); } } } } if (addAuthTable) { chapter.add(createParagraph("")); chapter.add(createParagraph( ftc.getTable(FigureConstant.AUTH_TABLE) + " summarises the authorisations actors in the " + getProjectName() + " project grant to one another.")); chapter.add(table2); addTableCaption(table2, ftc.getTable(FigureConstant.AUTH_TABLE) + " - Authorisations in the " + getProjectName() + " project"); table2.setComplete(true); } }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private Paragraph getRiskAnalysisDescription(final String analysis) { Paragraph desc = createParagraph("?"); if (analysis.equals(RiskAnalysisTasksNames.THREAT_ANALISIS)) { desc = createParagraph(/*from ww w . ja v a 2s . c o m*/ "This analysis starts with the known events, and propagates their impact over goal trees, documents and social relationships. The new discovered elements are treated as threated elements. The analysis ends when no new elements are found."); desc.add(Chunk.NEWLINE); desc.add(new Phrase("The propagation rules are the following:")); List<Paragraph> pr = new ArrayList<Paragraph>(); pr.add(createP( "If the threatened element is a goal, then the following are also threatened: goal's decomposition's parents, porduced document and delegated goals.")); pr.add(createP( "If the threatened element is a document, then the following are also threatened: document's partOf's parents, goals that need or modify the document and if the document is provided the provided goal.")); desc.add(listParagraphs(pr)); } return getAlaysisDescription(analysis, desc); }
From source file:eu.aniketos.wp1.ststool.report.pdfgenerator.ReportContentFactory.java
License:Open Source License
private Paragraph getAlaysisDescription(String analysisName, Paragraph analysisDesc) { Paragraph res = createParagraph("%b" + analysisName + "% "); res.add(Chunk.NEWLINE); analysisDesc.setSpacingAfter(0);/* w w w. j ava 2 s.c o m*/ analysisDesc.setSpacingBefore(0); res.add(analysisDesc); return res; }
From source file:ExternalNonFormClasses.PDFEnator.java
public void createPDF() { try {/*from w w w.j av a2s. c o m*/ Rectangle one = new Rectangle(PageSize.LETTER); Document doc = new Document(one); PdfWriter writer = PdfWriter.getInstance(doc, new FileOutputStream(getDirectory() + "\\" + data_title + ".pdf")); //doc.setMargins(1, 1, 1, 1); doc.open(); PdfContentByte canvas = writer.getDirectContent(); Font font = new Font(Font.FontFamily.TIMES_ROMAN, 11); x = one.getWidth(); y = one.getHeight(); tableX = (x / 2) - 235; tableY = y - 180; getHeader(); Paragraph para = new Paragraph("Province of " + formHeaderValues[0], font); para.setAlignment(Element.ALIGN_CENTER); doc.add(para); Paragraph para2 = new Paragraph("City/Municipality of " + formHeaderValues[1], font); para2.setAlignment(Element.ALIGN_CENTER); doc.add(para2); Paragraph para3 = new Paragraph("Barangay " + formHeaderValues[2], font); para3.setAlignment(Element.ALIGN_CENTER); doc.add(para3); doc.add(Chunk.NEWLINE); doc.add(Chunk.NEWLINE); Paragraph para4 = new Paragraph(data_title, font); para4.setAlignment(Element.ALIGN_CENTER); doc.add(para4); PdfPTable pdftable; pdftable = writeHeaders(font); //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, y - 180, canvas); int counter = 1, rowCounter = 0, columnCounter = 0; int yIncrementor = 16; boolean test = true; while (counter <= this.totalDataSize) { //System.out.println("data#: " + counter + "@ (" + rowCounter + "," + (columnCounter) + ") = " + this.table.getValueAt(rowCounter, columnCounter).toString()); PdfPCell cell1 = new PdfPCell( new Paragraph(this.table.getValueAt(rowCounter, columnCounter++).toString(), font)); cell1.setPaddingBottom(5); cell1.setHorizontalAlignment(Element.ALIGN_LEFT); pdftable.addCell(cell1); if (counter > 0 && (counter % column) == 0) { //if there are 4 columns //pdftable.writeSelectedRows(0, -1, (x / 2) - 235, (y - 180) - yIncrementor, canvas); //print row of 4 columns yIncrementor += 16; //move to next row coordinate, so y coordinate plus plus rowCounter++; //move to next row columnCounter = 0; //back to start column boolean newPage = false; if ((tableY - ((yIncrementor - 16) + 80)) <= 72) { //if it exceeds 1 inch in footer, new page // System.out.println("(" + tableY + "-((" + yIncrementor + "-16)+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - ((yIncrementor - 16) + 16))); newPage = true; } else if ((tableY - (yIncrementor + 80)) <= 72) { // System.out.println("(" + tableY + "-(" + yIncrementor + "+" + 16 + "))"); // System.out.println("Nanobra? YES; " + (tableY - (yIncrementor + 16))); newPage = true; } if (newPage) { pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); //print the data for the current page doc.newPage(); //create new page pdftable = writeHeaders(font); //write headers to new page yIncrementor = 16; //restore default } } // if (counter == this.totalDataSize) { //para lng mudouble ang data // if (test) { // test = false; // counter = 0; // rowCounter = 0; // columnCounter = 0; // } // } else if (counter == this.totalDataSize) { // if (!test) { // break; // } // } counter++; } pdftable.completeRow(); pdftable.writeSelectedRows(0, -1, tableX, tableY, canvas); doc.close(); } catch (DocumentException | FileNotFoundException ex) { Logger.getLogger(PDFEnator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:file.PDFWriter.java
License:Open Source License
/** * Add the page number and line to the PDF * @param splitLines the array of line segments to print * @param page the page number the line was on * @throws DocumentException /*from ww w . j a v a2s . c o m*/ */ private void addLineTableToPDF(String[] splitLines, String page) throws DocumentException { PdfPTable lineTable = new PdfPTable(2); PdfPCell pageCell = new PdfPCell(new Paragraph("Page: " + page, lineFont)); pageCell.setPadding(20); pageCell.setPaddingLeft(0); pageCell.setBorder(PdfPCell.NO_BORDER); Chunk lineSegment1 = new Chunk(splitLines[0]); lineSegment1.setFont(lineFont); Chunk error1 = new Chunk(splitLines[1]); error1.setFont(lineFontBold); Chunk lineSegment2 = new Chunk(splitLines[2]); lineSegment2.setFont(lineFont); Chunk error2 = new Chunk(splitLines[3]); error2.setFont(lineFontBold); Chunk lineSegment3 = new Chunk(splitLines[4]); lineSegment3.setFont(lineFont); Phrase line = new Phrase(lineSegment1); line.add(error1); line.add(lineSegment2); line.add(error2); line.add(lineSegment3); PdfPCell lineCell = new PdfPCell(line); lineCell.setPadding(20); lineCell.setBorder(PdfPCell.NO_BORDER); lineTable.setWidthPercentage(100); lineTable.setWidths(new int[] { 2, 10 }); lineTable.setSpacingBefore(1f); lineTable.setSpacingAfter(1f); lineTable.addCell(pageCell); lineTable.addCell(lineCell); document.add(lineTable); document.add(Chunk.NEWLINE); }
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 w w w . j a v a 2 s .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.scheduler.TournamentSchedule.java
License:Open Source License
/** * Output the detailed schedule for a team for the day. * /*from www . j a v a 2 s.co m*/ * @throws DocumentException */ private void outputTeamSchedule(final SchedParams params, final Document detailedSchedules, final TeamScheduleInfo si) throws DocumentException { final Paragraph para = new Paragraph(); para.add(new Chunk( String.format("Detailed schedule for Team #%d - %s", si.getTeamNumber(), si.getTeamName()), TEAM_TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk(String.format("Organization: %s", si.getOrganization()), TEAM_TITLE_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk("Division: ", TEAM_HEADER_FONT)); para.add(new Chunk(si.getAwardGroup(), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); for (final String subjectiveStation : subjectiveStations) { para.add(new Chunk(subjectiveStation + ": ", TEAM_HEADER_FONT)); final LocalTime start = si.getSubjectiveTimeByName(subjectiveStation).getTime(); final LocalTime end = start.plus(params.getStationByName(subjectiveStation).getDuration()); para.add(new Chunk(String.format("%s - %s", formatTime(start), formatTime(end)), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); } for (int round = 0; round < getNumberOfRounds(); ++round) { para.add(new Chunk(String.format(PERF_HEADER_FORMAT, round + 1) + ": ", TEAM_HEADER_FONT)); final LocalTime start = si.getPerfTime(round); final LocalTime end = start.plus(Duration.ofMinutes(params.getPerformanceMinutes())); para.add(new Chunk(String.format("%s - %s %s %d", formatTime(start), formatTime(end), si.getPerfTableColor(round), si.getPerfTableSide(round)), TEAM_VALUE_FONT)); para.add(Chunk.NEWLINE); } para.add(Chunk.NEWLINE); para.add(new Chunk( "Performance rounds must start on time, and will start without you. Please ensure your team arrives at least 5 minutes ahead of scheduled time, and checks in.", TEAM_HEADER_FONT)); para.add(Chunk.NEWLINE); para.add(new Chunk( "Note that there may be more judging and a head to head round after this judging, please see the main tournament schedule for these details.", TEAM_HEADER_FONT)); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); para.add(Chunk.NEWLINE); para.setKeepTogether(true); detailedSchedules.add(para); }
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 www .j av a 2 s . com*/ 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
/** * @throws ParseException/*from www . j a v a2 s. c o m*/ */ private void writeColumnHeaders(final TournamentSchedule schedule, final double[] weights, final ScoreCategory[] subjectiveCategories, final float[] relativeWidths, final ChallengeDescription challengeDescription, final PdfPTable divTable) throws ParseException { // ///////////////////////////////////////////////////////////////////// // Write the table column headers // ///////////////////////////////////////////////////////////////////// // team information final PdfPCell organizationCell = new PdfPCell(new Phrase("Organization", ARIAL_8PT_BOLD)); organizationCell.setBorder(0); organizationCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(organizationCell); // judging group if (null != schedule) { final Paragraph judgingGroup = new Paragraph("Judging", ARIAL_8PT_BOLD); judgingGroup.add(Chunk.NEWLINE); judgingGroup.add(new Chunk("Group")); final PdfPCell osCell = new PdfPCell(judgingGroup); osCell.setBorder(0); osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(osCell); } divTable.addCell(""); // weight/raw&scaled for (int cat = 0; cat < subjectiveCategories.length; cat++) { if (weights[cat] > 0.0) { final String catTitle = subjectiveCategories[cat].getTitle(); final Paragraph catPar = new Paragraph(catTitle, ARIAL_8PT_BOLD); final PdfPCell catCell = new PdfPCell(catPar); catCell.setBorder(0); catCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); catCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(catCell); } } final Paragraph perfPar = new Paragraph("Performance", ARIAL_8PT_BOLD); final PdfPCell perfCell = new PdfPCell(perfPar); perfCell.setBorder(0); perfCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); perfCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(perfCell); final Paragraph overallScore = new Paragraph("Overall", ARIAL_8PT_BOLD); overallScore.add(Chunk.NEWLINE); overallScore.add(new Chunk("Score")); final PdfPCell osCell = new PdfPCell(overallScore); osCell.setBorder(0); osCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); osCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(osCell); // ///////////////////////////////////////////////////////////////////// // Write a table row with the relative weights of the subjective scores // ///////////////////////////////////////////////////////////////////// final PdfPCell teamCell = new PdfPCell(new Phrase("Team # / Team Name", ARIAL_8PT_BOLD)); teamCell.setBorder(0); teamCell.setVerticalAlignment(com.itextpdf.text.Element.ALIGN_MIDDLE); divTable.addCell(teamCell); final Paragraph wPar = new Paragraph("Weight:", ARIAL_8PT_NORMAL); final PdfPCell wCell = new PdfPCell(wPar); if (null != schedule) { wCell.setColspan(2); } wCell.setBorder(0); wCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_RIGHT); divTable.addCell(wCell); final PdfPCell[] wCells = new PdfPCell[subjectiveCategories.length]; final Paragraph[] wPars = new Paragraph[subjectiveCategories.length]; for (int cat = 0; cat < subjectiveCategories.length; cat++) { if (weights[cat] > 0.0) { wPars[cat] = new Paragraph(Double.toString(weights[cat]), ARIAL_8PT_NORMAL); wCells[cat] = new PdfPCell(wPars[cat]); wCells[cat].setBorder(0); wCells[cat].setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); divTable.addCell(wCells[cat]); } } final PerformanceScoreCategory performanceElement = challengeDescription.getPerformance(); final double perfWeight = performanceElement.getWeight(); final Paragraph perfWeightPar = new Paragraph(Double.toString(perfWeight), ARIAL_8PT_NORMAL); final PdfPCell perfWeightCell = new PdfPCell(perfWeightPar); perfWeightCell.setHorizontalAlignment(com.itextpdf.text.Element.ALIGN_CENTER); perfWeightCell.setBorder(0); divTable.addCell(perfWeightCell); divTable.addCell(""); PdfPCell blankCell = new PdfPCell(); blankCell.setBorder(0); blankCell.setBorderWidthBottom(1.0f); blankCell.setColspan(relativeWidths.length); divTable.addCell(blankCell); // Cause the first 4 rows to be repeated on // each page - 1 row for box header, 2 rows text headers and 1 for // the horizontal line. divTable.setHeaderRows(4); }