List of usage examples for com.itextpdf.text Document open
boolean open
To view the source code for com.itextpdf.text Document open.
Click Source Link
From source file:be.roots.taconic.pricingguide.util.iTextUtil.java
License:Open Source License
public static byte[] organize(byte[] pdf, Toc tableOfContents) throws IOException, DocumentException { try (final ByteArrayOutputStream copyBaos = new ByteArrayOutputStream()) { final Document doc = new Document(); final PdfCopy copy = new PdfSmartCopy(doc, copyBaos); final PdfReader reader = new PdfReader(pdf); reader.selectPages(tableOfContents.getPageSequence()); doc.open(); for (int i = 1; i <= reader.getNumberOfPages(); i++) { copy.addPage(copy.getImportedPage(reader, i)); }// w w w.j ava2s .c om reader.close(); copy.close(); return copyBaos.toByteArray(); } }
From source file:be.roots.taconic.pricingguide.util.iTextUtil.java
License:Open Source License
public static byte[] emptyPage() throws DocumentException, IOException { try (final ByteArrayOutputStream baos = new ByteArrayOutputStream()) { final Document document = createNewDocument(); final PdfWriter pdfWriter = PdfWriter.getInstance(document, baos); document.open(); document.newPage();/*from w w w . ja v a 2s. c om*/ pdfWriter.setPageEmpty(false); document.close(); return baos.toByteArray(); } }
From source file:be.thomasmore.controller.InputBean.java
public void createPdf(String filename) throws DocumentException, IOException { // step 1//from w ww.jav a 2s . c o m Document document = new Document(); // step 2 PdfWriter.getInstance(document, new FileOutputStream(filename)); // step 3 document.open(); // step 4 document.add(new Paragraph("Hello World!")); // step 5 document.close(); }
From source file:be.thomasmore.controller.PdfController.java
public void createPdfKlas() { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();// w w w. j av a 2s. c o m String KlasId = params.get("klasId"); int id = Integer.parseInt(KlasId); Document document = new Document(); Klas klas = service.getKlas(id); List<Klastest> klastesten = klas.getKlastestList(); List<Test> testen = new ArrayList<Test>(); HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext() .getResponse(); res.setHeader("Content-Disposition", "attachement; filename=" + klas.getNummer() + "-resultaten.pdf"); res.setContentType("application/pdf"); try { PdfWriter.getInstance(document, res.getOutputStream()); document.open(); Font font = FontFactory.getFont("Calibri"); Font fontbold = FontFactory.getFont("Calibri", Font.BOLD); PdfPTable table = new PdfPTable(3); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Vak", font)); PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font)); PdfPCell cell3 = new PdfPCell(new Paragraph("Behaald", font)); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); for (Klastest klastest : klastesten) { Test test = klastest.getTestId(); testen.add(service.getTest(test.getId())); } for (Test test : testen) { List<Score> scores = test.getScoreList(); Vak vak = test.getVakId(); for (Score score : scores) { Student student = score.getStudentId(); PdfPCell cellVak = new PdfPCell(new Paragraph(vak.getNaam(), font)); PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font)); PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString(), font)); table.addCell(cellVak); table.addCell(cellStudent); table.addCell(cellScore); } } document.add(new Phrase("Klas: ", font)); document.add(new Phrase(klas.getNummer(), font)); document.add(table); document.close(); } catch (Exception e) { } }
From source file:be.thomasmore.controller.PdfController.java
public void createPdfTest() { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();//from w ww . j av a 2 s .c o m String KlasId = params.get("klasId3"); String TestId = params.get("testId"); int klasId = Integer.parseInt(KlasId); int id = Integer.parseInt(TestId); Document document = new Document(); Test test = service.getTest(id); List<Score> scores = test.getScoreList(); Klas klas = service.getKlas(klasId); Vak vak = test.getVakId(); HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext() .getResponse(); res.setHeader("Content-Disposition", "attachement; filename=" + test.getBeschrijving() + "-resultaten.pdf"); res.setContentType("application/pdf"); try { PdfWriter.getInstance(document, res.getOutputStream()); document.open(); Font font = FontFactory.getFont("Calibri"); Font fontbold = FontFactory.getFont("Calibri", Font.BOLD); PdfPTable table = new PdfPTable(3); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Test", font)); PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font)); PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font)); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); for (Score score : scores) { Student student = score.getStudentId(); PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font)); PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font)); PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString())); table.addCell(cellTest); table.addCell(cellStudent); table.addCell(cellScore); } document.add(new Phrase("Klas: ", font)); document.add(new Phrase(klas.getNummer(), font)); document.add(new Phrase(" Vak: ", font)); document.add(new Phrase(vak.getNaam(), font)); document.add(table); document.close(); } catch (Exception e) { } }
From source file:be.thomasmore.controller.PdfController.java
public void createPdfVak() { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();/*from w ww . j a v a 2 s . c om*/ String KlasId = params.get("klasId2"); String VakId = params.get("vakId"); int klasId = Integer.parseInt(KlasId); int id = Integer.parseInt(VakId); Document document = new Document(); Vak vak = service.getVak(id); List<Test> testen = vak.getTestList(); Klas klas = service.getKlas(klasId); HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext() .getResponse(); res.setHeader("Content-Disposition", "attachement; filename=" + vak.getNaam() + "-resultaten.pdf"); res.setContentType("application/pdf"); try { PdfWriter.getInstance(document, res.getOutputStream()); document.open(); Font font = FontFactory.getFont("Calibri"); Font fontbold = FontFactory.getFont("Calibri", Font.BOLD); PdfPTable table = new PdfPTable(3); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Test", font)); PdfPCell cell2 = new PdfPCell(new Paragraph("Student", font)); PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font)); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); for (Test test : testen) { List<Score> scores = test.getScoreList(); for (Score score : scores) { Student student = score.getStudentId(); PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font)); PdfPCell cellStudent = new PdfPCell(new Paragraph(student.getVoornaam(), font)); PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString())); table.addCell(cellTest); table.addCell(cellStudent); table.addCell(cellScore); } } document.add(new Phrase("Klas: ", font)); document.add(new Phrase(klas.getNummer(), font)); document.add(new Phrase(" Vak: ", font)); document.add(new Phrase(vak.getNaam(), font)); document.add(table); document.close(); } catch (Exception e) { } }
From source file:be.thomasmore.controller.PdfController.java
public void createPdfStudent() { Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext() .getRequestParameterMap();/*from w w w.j a va2 s . c om*/ String StudentId = params.get("studentId"); int id = Integer.parseInt(StudentId); Document document = new Document(); Student student = service.getStudent(id); List<Score> scores = student.getScoreList(); Klas klas = student.getKlasId(); HttpServletResponse res = (HttpServletResponse) FacesContext.getCurrentInstance().getExternalContext() .getResponse(); res.setHeader("Content-Disposition", "attachement; filename=" + student.getNaam() + student.getVoornaam() + "-resultaten.pdf"); res.setContentType("application/pdf"); try { PdfWriter.getInstance(document, res.getOutputStream()); document.open(); Font font = FontFactory.getFont("Calibri"); PdfPTable table = new PdfPTable(3); // 3 columns. PdfPCell cell1 = new PdfPCell(new Paragraph("Vak", font)); PdfPCell cell2 = new PdfPCell(new Paragraph("Test", font)); PdfPCell cell3 = new PdfPCell(new Paragraph("Score", font)); table.addCell(cell1); table.addCell(cell2); table.addCell(cell3); for (Score score : scores) { Test test = score.getTestId(); PdfPCell cellVak = new PdfPCell(new Paragraph(test.getVakId().getNaam(), font)); PdfPCell cellTest = new PdfPCell(new Paragraph(test.getBeschrijving(), font)); PdfPCell cellScore = new PdfPCell(new Paragraph(score.getScore().toString())); table.addCell(cellVak); table.addCell(cellTest); table.addCell(cellScore); } document.add(new Phrase("Student: ", font)); document.add(new Phrase((student.getNaam() + " " + student.getVoornaam()), font)); document.add(new Phrase("Klas: ", font)); document.add(new Phrase(klas.getNummer(), font)); document.add(table); document.close(); } catch (Exception e) { } }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDF(List<Score> scores) { try {/*from ww w . ja va 2 s. co m*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); //Create a table in PDF PdfPTable pdftabel = new PdfPTable(4); PdfPCell cell1 = new PdfPCell(new Phrase("Student")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Vak")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : scores) { pdftabel.addCell(score.getStudent().getNaam()); pdftabel.addCell(score.getTest().getVak().getNaam()); pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:be.thomasmore.service.CreatePDFServiceImp.java
@Override public void createPDFVoorStudent(ArrayList<ArrayList<Score>> puntenlijst, List<Double> gemiddeldelijst, Double totaalGemiddelde) { try {/*w w w .j av a 2 s .c om*/ OutputStream file = new FileOutputStream(new File("D:\\Desktop\\Scores.pdf")); Document document = new Document(); PdfWriter.getInstance(document, file); document.open(); document.add(new Paragraph("Scores")); document.add(new Paragraph(puntenlijst.get(0).get(0).getStudent().getNaam())); document.add(new Paragraph(new Date().toString())); document.addAuthor("Projectgroep 4"); document.addCreator("Projectgroep 4"); document.addTitle("ScoreTracker"); //Create Paragraph Paragraph paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); //New line paragraph.add(new Paragraph(" ")); paragraph.add("Scores"); paragraph.add(new Paragraph(" ")); document.add(paragraph); for (int i = 0; i < puntenlijst.size(); i++) { //Create a table in PDF PdfPTable pdftabel = new PdfPTable(2); //vak invullen paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph(puntenlijst.get(i).get(0).getTest().getVak().getNaam())); document.add(paragraph); PdfPCell cell1 = new PdfPCell(new Phrase("Test")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); cell1 = new PdfPCell(new Phrase("Score")); cell1.setHorizontalAlignment(Element.ALIGN_CENTER); pdftabel.addCell(cell1); pdftabel.setHeaderRows(1); for (Score score : puntenlijst.get(i)) { pdftabel.addCell(score.getTest().getNaam()); int resultaat = score.getScore(); pdftabel.addCell(resultaat + " / " + score.getTest().getTotaal()); } document.add(pdftabel); //gemmidelde per vak invoeren paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Gemiddelde: " + gemiddeldelijst.get(i).toString())); document.add(paragraph); } paragraph = new Paragraph("", new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD)); paragraph.add(new Paragraph("Algemeen gemiddelde: " + totaalGemiddelde)); document.add(paragraph); document.addCreationDate(); document.close(); file.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:be.zenodotus.creatie.GeneratePDF.java
License:Open Source License
public String vakantieAfdruk(Context context, String name, int jaar) { this.context = context; PdfWriter w = null;/* ww w . j a v a 2 s . c o m*/ Document d = new Document(PageSize.A4.rotate(), 5, 5, 10, 10); d.setPageCount(3); String fileName = name; String file = name; GregorianCalendar datum = new GregorianCalendar(); datum.set(GregorianCalendar.YEAR, jaar); String[] maanden = { "Januari", "Februari", "Maart", "April", "Mei", "Juni", "Juli", "Augustus", "September", "Oktober", "November", "December" }; int[] dagen = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; VerlofDao dao = new VerlofDao(context); FeestdagDao feestdagDao = new FeestdagDao(context); WerkdagDao werkdagDao = new WerkdagDao(context); File folder = new File(context.getFilesDir(), "pdfs"); folder.mkdirs(); if (datum.isLeapYear(jaar)) { dagen[1] = 29; } File temp = null; temp = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "Jacqueline" + jaar + ".pdf"); fileName = temp.toString(); try { dao.open(); ArrayList<Verlof> verloflijst = dao.getAlleVerlovenPerJaar(jaar); w = PdfWriter.getInstance(d, new FileOutputStream(temp)); d.open(); d.addAuthor("Jacqueline Vandenbroecke"); d.addCreationDate(); d.addCreator("Verlofplanner"); d.addTitle("Vakantie " + jaar + " van Jacqueline Vandenbroecke"); Font standaard = FontFactory.getFont(FontFactory.HELVETICA, 8); Font standaardBold = FontFactory.getFont(FontFactory.HELVETICA, 8, Font.BOLD); Paragraph gegeven = new Paragraph("Jacqueline Vandenbroecke Verlof " + jaar + "\n", standaardBold); gegeven.setAlignment(Paragraph.ALIGN_CENTER); d.add(gegeven); for (int paginas = 0; paginas < 2; paginas++) { int aantal = 0; if (paginas == 1) { d.newPage(); aantal = 6; } PdfPTable table = new PdfPTable(6); for (int i = aantal; i < (aantal + 6); i++) { PdfPCell cell = new PdfPCell(new Paragraph(maanden[i], standaardBold)); cell.setBorder(1); table.addCell(cell); } int dag = 1; int k = aantal; for (int i = aantal; i < (aantal + 6); i++) { for (int j = 0; j < 32; j++) { if (k > ((aantal + 6) - 1)) { k = aantal; dag++; } if (dag > dagen[k]) { PdfPCell cell = new PdfPCell(new Paragraph("", standaard)); table.addCell(cell); k++; } else { SimpleDateFormat formatterDag = new SimpleDateFormat("dd"); SimpleDateFormat formatterWeek = new SimpleDateFormat("EEE"); datum.set(jaar, k, dag); PdfPTable dagTabel = new PdfPTable(4); PdfPCell cellDag = new PdfPCell( new Paragraph(formatterDag.format(datum.getTime()), standaard)); PdfPCell cellWeek = new PdfPCell( new Paragraph(formatterWeek.format(datum.getTime()), standaard)); ArrayList<Verlof> verlof = new ArrayList<Verlof>(); for (int z = 0; z < verloflijst.size(); z++) { if (((verloflijst.get(z).getDag() + 1) == dag) && (verloflijst.get(z).getMaand() == k)) { verlof.add(verloflijst.get(z)); } } feestdagDao.open(); Feestdag feestdag = feestdagDao.getFeestdag(jaar, datum.get(GregorianCalendar.MONTH), datum.get(GregorianCalendar.DATE)); feestdagDao.close(); werkdagDao.open(); java.util.List<Werkdag> weekend = werkdagDao.getWeekend(); werkdagDao.close(); String Verlof = ""; String uur = ""; if (verlof.size() > 0) { if (verlof.size() > 1) { Verlof = verlof.get(0).getVerlofsoort() + "\n" + verlof.get(1).getVerlofsoort(); uur = verlof.get(0).getUrental() + "\n" + verlof.get(1).getUrental(); } else { Verlof = verlof.get(0).getVerlofsoort(); uur = verlof.get(0).getUrental(); } } PdfPCell cellVerlof = new PdfPCell(new Paragraph(Verlof, standaard)); PdfPCell uren = new PdfPCell(new Paragraph(uur, standaard)); if (verlof.size() > 0) { BaseColor kleur = new BaseColor(Color.GRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } for (int z = 0; z < weekend.size(); z++) { if ((formatterWeek.format(datum.getTime())).equals(weekend.get(z).getDag())) { BaseColor kleur = new BaseColor(Color.LTGRAY); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } } if (feestdag != null) { BaseColor kleur = new BaseColor(Color.GREEN); uren.setBackgroundColor(kleur); cellVerlof.setBackgroundColor(kleur); uren.setBackgroundColor(kleur); cellDag.setBackgroundColor(kleur); cellWeek.setBackgroundColor(kleur); } dagTabel.addCell(cellDag); dagTabel.addCell(cellWeek); dagTabel.addCell(cellVerlof); dagTabel.addCell(uren); table.addCell(dagTabel); k++; } } } d.add(table); dao.close(); } } catch (Exception ex) { ex.printStackTrace(); } finally { d.close(); w.close(); } return fileName; }