List of usage examples for com.lowagie.text.pdf PdfWriter getDirectContentUnder
public PdfContentByte getDirectContentUnder()
From source file:org.sonarqube.report.extendedpdf.ExtendedHeader.java
License:Open Source License
public void onEndPage(PdfWriter writer, Document document) { String pageTemplate = "/templates/page.pdf"; try {//ww w .j a v a2 s . co m PdfContentByte cb = writer.getDirectContentUnder(); PdfReader reader = new PdfReader(this.getClass().getResourceAsStream(pageTemplate)); PdfImportedPage page = writer.getImportedPage(reader, 1); cb.addTemplate(page, 0, 0); Font font = FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL, Color.GRAY); Rectangle pageSize = document.getPageSize(); PdfPTable head = new PdfPTable(1); head.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); head.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_CENTER); head.getDefaultCell().setBorder(0); Phrase projectName = new Phrase(project.getName(), font); head.addCell(projectName); head.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); head.writeSelectedRows(0, -1, document.leftMargin(), pageSize.getHeight() - 15, writer.getDirectContent()); head.setSpacingAfter(10); PdfPTable foot = new PdfPTable(1); foot.getDefaultCell().setVerticalAlignment(PdfCell.ALIGN_MIDDLE); foot.getDefaultCell().setHorizontalAlignment(PdfCell.ALIGN_LEFT); foot.getDefaultCell().setBorder(0); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy hh:mm"); Phrase projectAnalysisDate = new Phrase(df.format(project.getMeasures().getDate()), font); foot.addCell(projectAnalysisDate); foot.setTotalWidth(pageSize.getWidth() - document.leftMargin() - document.rightMargin()); foot.writeSelectedRows(0, -1, document.leftMargin(), 20, writer.getDirectContent()); foot.setSpacingBefore(10); } catch (IOException e) { Logger.error("Cannot find the required template: " + pageTemplate); e.printStackTrace(); } }
From source file:papertoolkit.render.SheetRenderer.java
License:BSD License
/** * Uses the iText package to render a PDF file from scratch. iText is nice because we can write to a * Graphics2D context. Alternatively, we can use PDF-like commands. * //from www. jav a2 s. com * @param destPDFFile */ public void renderToPDF(File destPDFFile) { try { final FileOutputStream fileOutputStream = new FileOutputStream(destPDFFile); final Rectangle pageSize = new Rectangle(0, 0, (int) Math.round(sheet.getWidth().getValueInPoints()), (int) Math.round(sheet.getHeight().getValueInPoints())); // create a document with these margins (worry about margins later) final Document doc = new Document(pageSize, 0, 0, 0, 0); final PdfWriter writer = PdfWriter.getInstance(doc, fileOutputStream); doc.open(); final PdfContentByte topLayer = writer.getDirectContent(); final PdfContentByte bottomLayer = writer.getDirectContentUnder(); renderToPDFContentLayers(destPDFFile, topLayer, bottomLayer); doc.close(); // save the pattern info to the same directory automatically savePatternInformation(); // do this automatically } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }
From source file:questions.graphics2D.SplitCanvas.java
public static void main(String[] args) { Document document = new Document(); try {//from www . j a v a2 s .c om document.setPageSize(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // create the canvas for the complete drawing: PdfContentByte directContent = writer.getDirectContentUnder(); PdfTemplate canvas = directContent.createTemplate(200, 200); Graphics2D g2d = canvas.createGraphicsShapes(200, 200); // draw to the complete drawing to the canvas: g2d.setPaint(new Color(150, 150, 255)); g2d.setStroke(new BasicStroke(10.0f)); g2d.drawArc(50, 50, 100, 100, 0, 360); g2d.dispose(); // wrap the canvas inside an image: Image img = Image.getInstance(canvas); // distribute the image over 4 pages: img.setAbsolutePosition(0, -100); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 25, 25, 100); g2d.drawLine(25, 25, 100, 25); g2d.dispose(); document.newPage(); img.setAbsolutePosition(-100, -100); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 25, 75, 25); g2d.drawLine(75, 25, 75, 100); g2d.dispose(); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 0, 25, 75); g2d.drawLine(25, 75, 100, 75); g2d.dispose(); document.newPage(); img.setAbsolutePosition(-100, 0); document.add(img); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 75, 75, 75); g2d.drawLine(75, 0, 75, 75); g2d.dispose(); } catch (DocumentException de) { de.printStackTrace(); return; } catch (IOException ioe) { ioe.printStackTrace(); return; } document.close(); }
From source file:questions.graphics2D.SplitCanvasDifficult.java
public static void main(String[] args) { Document document = new Document(); try {/*from w w w . ja v a2 s .co m*/ document.setPageSize(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // create the canvas for the complete drawing: PdfContentByte directContent = writer.getDirectContentUnder(); Graphics2D g2d; // distribute the image over 4 pages: g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 25, 25, 100); g2d.drawLine(25, 25, 100, 25); g2d.dispose(); document.newPage(); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 25, 75, 25); g2d.drawLine(75, 25, 75, 100); g2d.dispose(); document.newPage(); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(25, 0, 25, 75); g2d.drawLine(25, 75, 100, 75); g2d.dispose(); document.newPage(); g2d = directContent.createGraphicsShapes(100, 100); g2d.setPaint(new Color(255, 150, 150)); g2d.setStroke(new BasicStroke(5.0f)); g2d.drawLine(0, 75, 75, 75); g2d.drawLine(75, 0, 75, 75); g2d.dispose(); } catch (DocumentException de) { de.printStackTrace(); return; } catch (IOException ioe) { ioe.printStackTrace(); return; } document.close(); }
From source file:questions.graphics2D.SplitCanvasEasy.java
public static void main(String[] args) { Document document = new Document(); try {/*w ww.ja v a2 s .c o m*/ document.setPageSize(new Rectangle(100, 100)); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(RESULT)); document.open(); // create the canvas for the complete drawing: PdfContentByte directContent = writer.getDirectContentUnder(); PdfTemplate canvas = directContent.createTemplate(200, 200); Graphics2D g2d = canvas.createGraphicsShapes(200, 200); // draw to the complete drawing to the canvas: g2d.setPaint(new Color(150, 150, 255)); g2d.setStroke(new BasicStroke(10.0f)); g2d.drawArc(50, 50, 100, 100, 0, 360); g2d.dispose(); // wrap the canvas inside an image: Image img = Image.getInstance(canvas); // distribute the image over 4 pages: img.setAbsolutePosition(0, -100); document.add(img); document.newPage(); img.setAbsolutePosition(-100, -100); document.add(img); document.newPage(); img.setAbsolutePosition(0, 0); document.add(img); document.newPage(); img.setAbsolutePosition(-100, 0); document.add(img); } catch (DocumentException de) { de.printStackTrace(); return; } catch (IOException ioe) { ioe.printStackTrace(); return; } document.close(); }
From source file:questions.importpages.NameCards.java
public static void createSheet(int p) throws DocumentException, IOException { Rectangle rect = new Rectangle(PageSize.A4); Document document = new Document(rect); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(SHEET[p - 1])); document.open();//from ww w .j a v a 2 s . c om PdfContentByte canvas = writer.getDirectContentUnder(); PdfReader reader = new PdfReader(NameCard.CARD); PdfImportedPage front = writer.getImportedPage(reader, p); float x = rect.getWidth() / 2 - front.getWidth(); float y = (rect.getHeight() - (front.getHeight() * 5)) / 2; canvas.setLineWidth(0.5f); canvas.moveTo(x, y - 15); canvas.lineTo(x, y); canvas.lineTo(x - 15, y); canvas.moveTo(x + front.getWidth(), y - 15); canvas.lineTo(x + front.getWidth(), y); canvas.moveTo(x + front.getWidth() * 2, y - 15); canvas.lineTo(x + front.getWidth() * 2, y); canvas.lineTo(x + front.getWidth() * 2 + 15, y); canvas.stroke(); for (int i = 0; i < 5; i++) { for (int j = 0; j < 2; j++) { canvas.addTemplate(front, x, y); x += front.getWidth(); } x = rect.getWidth() / 2 - front.getWidth(); y += front.getHeight(); canvas.moveTo(x, y); canvas.lineTo(x - 15, y); canvas.moveTo(x + front.getWidth() * 2, y); canvas.lineTo(x + front.getWidth() * 2 + 15, y); canvas.stroke(); } canvas.moveTo(x, y + 15); canvas.lineTo(x, y); canvas.moveTo(x + front.getWidth(), y + 15); canvas.lineTo(x + front.getWidth(), y); canvas.moveTo(x + front.getWidth() * 2, y + 15); canvas.lineTo(x + front.getWidth() * 2, y); canvas.stroke(); document.close(); }
From source file:sms.ReportForms.java
public void utext(String query, String Name, String dob, String house, String formclass, String kcpe, String imgurl, String kcpegrade, String id) { methods nn = new methods(); String u = unig();/*from www . j a va 2 s . c o m*/ checkPreviousResults(u, kcpe, kcpegrade, id); ArrayList<ExamDbDataHolder> users = selectExamResults(u, query); if (users.size() < 2) { Form1Exams n = new Form1Exams(); String[] Subjects = n.findSubjectid(); String[] Subjectsnames = n.findSubjectname(); JFileChooser chooser = new JFileChooser(); chooser.setCurrentDirectory(new java.io.File(",")); chooser.setDialogTitle("Save at"); chooser.setApproveButtonText("save"); chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) { try { Document pdfp = new Document(); PdfWriter w = PdfWriter.getInstance(pdfp, new FileOutputStream(new File(chooser.getSelectedFile(), "" + sid.getText() + ".pdf"))); pdfp.open(); PdfContentByte canvas = w.getDirectContentUnder(); Image imgb = Image.getInstance("C:\\Users\\kimani kogi\\Pictures\\icons\\logo.png"); imgb.setAbsolutePosition(2, 2); imgb.scaleAbsoluteHeight(PageSize.A4.getHeight() / 4); imgb.scaleAbsoluteWidth(PageSize.A4.getWidth() / 4); canvas.saveState(); PdfGState state = new PdfGState(); state.setFillOpacity(0.6f); canvas.setGState(state); canvas.addImage(imgb); canvas.restoreState(); PdfPTable tbl1 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl1.setTotalWidth(575); tbl1.setLockedWidth(true); tbl1.setWidths(new int[] { 1, 4 }); if (imgurl.equals("image")) { tbl1.addCell("no image "); String img = imgurl; } else { tbl1.addCell(createImageCell(imgurl)); } tbl1.addCell(createTextCell(schooldetails)); PdfPTable tbl = new PdfPTable(8); // tbl.setWidthPercentage(100); tbl.setTotalWidth(575); tbl.setLockedWidth(true); tbl.setSpacingBefore(8); tbl.setSpacingAfter(6); tbl.getDefaultCell().setBorderWidthTop(2); tbl.getDefaultCell().setBorderWidthLeft(0); tbl.getDefaultCell().setBorderWidthRight(0); tbl.setWidths(new int[] { 1, 1, 1, 2, 1, 1, 1, 1 }); tbl.addCell("Adm No:"); tbl.addCell(sid.getText()); tbl.addCell("Name:"); tbl.addCell(Name); tbl.addCell("Form:"); tbl.addCell(formclass); tbl.addCell("Kcpe:"); tbl.addCell(kcpe); tbl.addCell("House:"); tbl.addCell(house); tbl.addCell("Term:"); tbl.addCell("Second term"); tbl.addCell("Year:"); tbl.addCell("2017"); tbl.addCell("DOB:"); tbl.addCell(dob); PdfPTable tbl2 = new PdfPTable(5); // tbl.setWidthPercentage(100); tbl2.setTotalWidth(575); tbl2.setLockedWidth(true); // tbl2.getDefaultCell().setFixedHeight(35f); tbl2.setWidths(new int[] { 2, 1, 1, 2, 2 }); tbl2.addCell(creatTextCellHeader("Subjects")); tbl2.addCell(creatTextCellHeader("Exams")); tbl2.addCell(creatTextCellHeader("Grade")); tbl2.addCell(creatTextCellHeader("Ratings")); tbl2.addCell(creatTextCellHeader("Remarks")); // String [] Subjectsnames=n.findSubjectname(); for (int i = 0; i < users.size(); i++) { for (int a = 0; a < Subjectsnames.length; a++) { tbl2.addCell(Subjectsnames[a]); String re = null; if (Subjects[a].equals("s1")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMathematics()); re = ((ExamDbDataHolder) users.get(i)).getMathematics(); // JOptionPane.showMessageDialog(null,((ExamDbDataHolder)users.get(i)).getMathematics()); // String maths = ((ExamDbDataHolder)users.get(i)).getMathematics(); } else if (Subjects[a].equals("s2")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getEnglish()); re = ((ExamDbDataHolder) users.get(i)).getEnglish(); //row[c] = ((ExamDbDataHolder)users.get(i)).getEnglish(); // c++; } else if (Subjects[a].equals("s3")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getKiswahili()); re = ((ExamDbDataHolder) users.get(i)).getKiswahili(); // row[c] = ((ExamDbDataHolder)users.get(i)).getKiswahili(); // c++; } else if (Subjects[a].equals("s4")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getPhysics()); re = ((ExamDbDataHolder) users.get(i)).getPhysics(); // row[c] = ((ExamDbDataHolder)users.get(i)).getPhysics(); // c++; } else if (Subjects[a].equals("s5")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getChemistry()); re = ((ExamDbDataHolder) users.get(i)).getChemistry(); // row[c] = ((ExamDbDataHolder)users.get(i)).getChemistry(); // c++; } else if (Subjects[a].equals("s6")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBiology()); re = ((ExamDbDataHolder) users.get(i)).getBiology(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBiology(); // c++; } else if (Subjects[a].equals("s7")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHistory()); re = ((ExamDbDataHolder) users.get(i)).getHistory(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHistory(); // c++; } else if (Subjects[a].equals("s8")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGeography()); re = ((ExamDbDataHolder) users.get(i)).getGeography(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGeography(); // c++; } else if (Subjects[a].equals("s9")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getCre()); re = ((ExamDbDataHolder) users.get(i)).getCre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getCre(); // c++; } else if (Subjects[a].equals("s10")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getIre()); re = ((ExamDbDataHolder) users.get(i)).getIre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getIre(); // c++; } else if (Subjects[a].equals("s11")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHre()); re = ((ExamDbDataHolder) users.get(i)).getHre(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHre(); // c++; } else if (Subjects[a].equals("s12")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getAgriculture()); re = ((ExamDbDataHolder) users.get(i)).getAgriculture(); // row[c] = ((ExamDbDataHolder)users.get(i)).getAgriculture(); // c++; } else if (Subjects[a].equals("s13")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getHomescience()); re = ((ExamDbDataHolder) users.get(i)).getHomescience(); // row[c] = ((ExamDbDataHolder)users.get(i)).getHomescience(); // c++; } else if (Subjects[a].equals("s14")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArtdesign()); re = ((ExamDbDataHolder) users.get(i)).getArtdesign(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArtdesign(); // c++; } else if (Subjects[a].equals("s15")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getComputer()); re = ((ExamDbDataHolder) users.get(i)).getComputer(); // row[c] = ((ExamDbDataHolder)users.get(i)).getComputer(); // c++; } else if (Subjects[a].equals("s16")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBuilding()); re = ((ExamDbDataHolder) users.get(i)).getBuilding(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBuilding(); // c++; } else if (Subjects[a].equals("s17")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getWoodwork()); re = ((ExamDbDataHolder) users.get(i)).getWoodwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getWoodwork(); // c++; } else if (Subjects[a].equals("s18")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMetalwork()); re = ((ExamDbDataHolder) users.get(i)).getMetalwork(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMetalwork(); // c++; } else if (Subjects[a].equals("s19")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getMusic()); re = ((ExamDbDataHolder) users.get(i)).getMusic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getMusic(); // c++; } else if (Subjects[a].equals("s20")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getFrench()); re = ((ExamDbDataHolder) users.get(i)).getFrench(); // row[c] = ((ExamDbDataHolder)users.get(i)).getFrench(); // c++; } else if (Subjects[a].equals("s21")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getGerman()); re = ((ExamDbDataHolder) users.get(i)).getGerman(); // row[c] = ((ExamDbDataHolder)users.get(i)).getGerman(); // c++; } else if (Subjects[a].equals("s22")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getArabic()); re = ((ExamDbDataHolder) users.get(i)).getArabic(); // row[c] = ((ExamDbDataHolder)users.get(i)).getArabic(); // c++; } else if (Subjects[a].equals("s23")) { tbl2.addCell(((ExamDbDataHolder) users.get(i)).getBusiness()); re = ((ExamDbDataHolder) users.get(i)).getBusiness(); // row[c] = ((ExamDbDataHolder)users.get(i)).getBusiness(); // c++; } String[] gr = nn.checkGrade(re, Subjects[a]); tbl2.addCell(gr[0]); tbl2.addCell(gr[1]); tbl2.addCell(""); } } //add for all other subjects PdfPTable tbl3 = new PdfPTable(4); // tbl.setWidthPercentage(100); tbl3.setTotalWidth(575); tbl3.setLockedWidth(true); tbl3.setSpacingBefore(8); tbl3.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl3.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl3.setWidths(new int[] { 1, 1, 1, 1 }); tbl3.addCell(creatTextCellHeader("CURRENT MARKS:")); tbl3.addCell(creatTextCellHeader(String.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()))); float g = Float.valueOf(((ExamDbDataHolder) users.get(0)).getTotal()); // tbl.addCell(String.format("%.1f", g)); String gr = nn.checkGrade(yearid, String.format("%.1f", g / getYear())); tbl3.addCell(creatTextCellHeader("PREVIOUS MARKS:")); tbl3.addCell(creatTextCellHeader("459")); tbl3.addCell(creatTextCellHeader("AVERAGE MARKS:")); tbl3.addCell(creatTextCellHeader(String.format("%.1f", g / getYear()))); tbl3.addCell(creatTextCellHeader("PREVIOUS AVERAGE:")); tbl3.addCell(creatTextCellHeader("50")); tbl3.addCell(creatTextCellHeader("MEAN GRADE:")); tbl3.addCell(creatTextCellHeader(gr)); tbl3.addCell(creatTextCellHeader("PREVIOUS MEAN GRADE:")); tbl3.addCell(creatTextCellHeader("B")); tbl3.addCell(creatTextCellHeader("POS")); tbl3.addCell(creatTextCellHeader("3 ")); tbl3.addCell(creatTextCellHeader("OUT OF")); tbl3.addCell(creatTextCellHeader("79")); PdfPTable tbl4 = new PdfPTable(2); // tbl.setWidthPercentage(100); tbl4.setHorizontalAlignment(0); //tbl4.HorizontalAlignment=Element.ALIGN_LEFT; tbl4.setTotalWidth(575 / 2); tbl4.setLockedWidth(true); tbl4.setSpacingBefore(8); tbl4.setSpacingAfter(6); // tbl3.getDefaultCell().setBorderWidthTop(0); tbl4.getDefaultCell().setBorder(0); // tbl3.getDefaultCell().setBorderWidthLeft(0); // tbl3.getDefaultCell().setBorderWidthRight(0); tbl4.setWidths(new int[] { 2, 1 }); PdfPCell cell = new PdfPCell(new Paragraph("REMARKS")); cell.setColspan(2); tbl4.addCell(cell); tbl4.addCell(creatTextCellHeader( "CLASS TEACHERS........................................................." + ":............................\n\n\n")); tbl4.addCell(creatTextCellChart("chart")); tbl4.addCell(creatTextCellHeader( "SIGNATURE-------------------------------------------------------------" + "-------------------------------\n\n\n")); tbl4.addCell(creatTextCellHeader( "-------------\n\n\n-----------------------------------------------------------" + "-----------------------------")); pdfp.add(tbl1); pdfp.add(tbl); pdfp.add(tbl2); pdfp.add(tbl3); pdfp.add(tbl4); // Paragraph p=new Paragraph(); // p.setAlignment(Element.ALIGN_CENTER); // p.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,18,Font.BOLD)); // Paragraph po=new Paragraph(); // po.setAlignment(Element.ALIGN_CENTER); // po.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,16,Font.BOLD)); // // Paragraph pd=new Paragraph(); // pd.setAlignment(Element.ALIGN_CENTER); // pd.setFont(FontFactory.getFont(FontFactory.TIMES_BOLD,14,Font.BOLD)); // p.add("ITHANGA SECONDARY SCHOOL"); // po.add("PO.BOX 238 ITHANGA THIKA"); // pd.add(new Date().toString()); // pdfp.add(p); // pdfp.add(po); // pdfp.add(pd); // // // // pdfp.add(new Paragraph("\n.................................................................." // + ".................................................................................\n")); // String []names= n.findSubjectname(); // PdfPTable tbl=new PdfPTable(names.length+6); // tbl.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl.setTotalWidth(575); // tbl.setLockedWidth(true); // PdfPTable tbl1=new PdfPTable(names.length+6); // tbl1.setWidths(new float[]{1,1,4,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); // // tbl.setWidthPercentage(100); // tbl1.setTotalWidth(575); // tbl1.setLockedWidth(true); // PdfPCell cell=new PdfPCell (new Paragraph("RESULTS")); // cell.setColspan((names.length+4)*2); // cell.setBackgroundColor(Color.CYAN); // tbl1.addCell(cell); // tbl1.addCell("Pos"); // tbl1.addCell("id"); // tbl1.addCell("Name"); // int a; pdfp.close(); } catch (Exception j) { j.printStackTrace(); } // Image img=new Image.getInstance("j.png"); } } }