List of usage examples for com.itextpdf.text Document Document
public Document()
Document
-object. From source file:be.kcbj.placemat.Placemat.java
License:Open Source License
private void createPdf(File file, List<Sponsor> sponsors) throws IOException, DocumentException { System.out.println("Generating PDF file " + file.getAbsolutePath()); Layout layout = new Layout(sponsors); System.out.println("Layout = " + layout); Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.setPageSize(PageSize.A4.rotate()); document.setMargins(PADDING_DOC, PADDING_DOC, PADDING_DOC, PADDING_DOC); document.open();/* w ww . j av a 2s .c o m*/ PdfPTable table = new PdfPTable(layout.getColumnCount()); table.setWidthPercentage(100); table.setSpacingBefore(0f); table.setSpacingAfter(0f); for (int i = 0; i < sponsors.size(); i++) { table.addCell(generateCell(sponsors.get(i), layout.getCellHeight())); } for (int i = 0; i < layout.getEmptyCellCount(); i++) { table.addCell(generateCell(new Sponsor(), layout.getCellHeight())); } document.add(table); document.close(); }
From source file:be.mxs.common.util.pdf.general.chuk.GeneralPDFCreator.java
public GeneralPDFCreator(SessionContainerWO sessionContainerWO, User user, AdminPerson patient, String sProject, String sProjectDir, Date dateFrom, Date dateTo, String sPrintLanguage) { this.user = user; this.patient = patient; this.sProject = sProject; this.sProjectPath = sProjectDir; this.dateFrom = dateFrom; this.dateTo = dateTo; this.sessionContainerWO = sessionContainerWO; this.sPrintLanguage = sPrintLanguage; doc = new Document(); dateFormat = ScreenHelper.stdDateFormat; }
From source file:be.mxs.common.util.pdf.general.dossierCreators.StaffDossierPDFCreator.java
public StaffDossierPDFCreator(SessionContainerWO sessionContainerWO, User user, AdminPerson patient, String sProject, String sProjectDir, String sPrintLanguage) { this.user = user; this.patient = patient; this.sProject = sProject; this.sProjectPath = sProjectDir; this.sessionContainerWO = sessionContainerWO; this.sPrintLanguage = sPrintLanguage; doc = new Document(); dateFormat = ScreenHelper.stdDateFormat; }
From source file:be.rheynaerde.pufmanager.gui.workers.ExportFullPdfWorker.java
License:Open Source License
@Override protected byte[] doInBackground() throws Exception { ByteArrayOutputStream largeBaos = new ByteArrayOutputStream(); Document document = new Document(); PdfCopy copy = new PdfCopy(document, largeBaos); document.open();//from ww w . j a v a 2s .c o m String stampText = ResourceBundle .getBundle("be.rheynaerde.pufmanager.gui.export", competition.getSettings().getLocale()) .getString("ExportFullPdf.poolsheet.stamp"); for (int i = 0; i < competition.getRoundCount(); i++) { publish(i); Round round = competition.getRound(i); int piste = 1; for (Match match : round.getMatches()) { final Match currentMatch = match; ByteArrayOutputStream baos = new ByteArrayOutputStream(); if (match.getRound().includeInternalBouts()) { PufCompletePoolSheetConfiguration config = new NamedPufCompletePoolSheetConfiguration( match.getFirstTeam().getFencerNames(), match.getSecondTeam().getFencerNames(), 20f, competition.getSettings().getImage(), competition.getSettings().getLocale(), competition.getSettings().getTitle(), competition.getSettings().getSubtitle()) { @Override public String getResult(int team1, int player1, int team2, int player2) { Fencer player = (team1 == 0 ? currentMatch.getFirstTeam() : currentMatch.getSecondTeam()).getFencer(player1); Fencer opponent = (team2 == 0 ? currentMatch.getFirstTeam() : currentMatch.getSecondTeam()).getFencer(player2); PoolResult result = competition.getCompetitionPool().getResult(player, opponent); return result == null ? null : result.toString(); } }; PufCompletePoolSheet sheet = new PufCompletePoolSheet(config); sheet.export(baos); } else { PufTeamPoolSheetConfiguration config = new NamedPufTeamPoolSheetConfiguration( match.getFirstTeam().getFencerNames(), match.getSecondTeam().getFencerNames(), 20f, competition.getSettings().getImage(), competition.getSettings().getLocale(), competition.getSettings().getTitle(), competition.getSettings().getSubtitle()) { @Override public String getResult(int team1, int player1, int team2, int player2) { Fencer player = (team1 == 0 ? currentMatch.getFirstTeam() : currentMatch.getSecondTeam()).getFencer(player1); Fencer opponent = (team2 == 0 ? currentMatch.getFirstTeam() : currentMatch.getSecondTeam()).getFencer(player2); PoolResult result = competition.getCompetitionPool().getResult(player, opponent); return result == null ? null : result.toString(); } }; PufTeamPoolSheet sheet = new PufTeamPoolSheet(config); sheet.export(baos); } addPdfToDocument(baos, copy, String.format(stampText, i + 1, piste)); piste++; } if (i == 0) { for (Team team : round.getRestingTeams()) { final Team currentTeam = team; ByteArrayOutputStream baos = new ByteArrayOutputStream(); PufSingleTeamPoolSheetConfiguration config = new NamedPufSingleTeamPoolSheetConfiguration( team.getFencerNames(), 20f, competition.getSettings().getImage(), competition.getSettings().getLocale(), competition.getSettings().getTitle(), competition.getSettings().getSubtitle()) { @Override public String getResult(int player, int opponent) { Fencer playerFencer = currentTeam.getFencer(player); Fencer opponentFencer = currentTeam.getFencer(opponent); PoolResult result = competition.getCompetitionPool().getResult(playerFencer, opponentFencer); return result == null ? null : result.toString(); } }; PufSingleTeamPoolSheet sheet = new PufSingleTeamPoolSheet(config); sheet.export(baos); addPdfToDocument(baos, copy, String.format(stampText, i + 1, piste)); piste++; } } } document.close(); publish(competition.getRoundCount()); return largeBaos.toByteArray(); }
From source file:be.roots.taconic.pricingguide.util.iTextUtil.java
License:Open Source License
public static byte[] merge(byte[]... pdfAsBytes) throws DocumentException, IOException { try (final ByteArrayOutputStream copyBaos = new ByteArrayOutputStream()) { final Document doc = new Document(); final PdfCopy copy = new PdfSmartCopy(doc, copyBaos); doc.open();//from ww w. j a v a 2s . c o m int numberOfPages = 0; final java.util.List<HashMap<String, Object>> bookmarks = new ArrayList<>(); PdfReader pdf = null; for (byte[] pdfAsByte : pdfAsBytes) { if (pdfAsByte != null && pdfAsByte.length > 0) { pdf = new PdfReader(pdfAsByte); pdf.consolidateNamedDestinations(); final List<HashMap<String, Object>> pdfBookmarks = SimpleBookmark.getBookmark(pdf); if (!CollectionUtils.isEmpty(pdfBookmarks)) { SimpleBookmark.shiftPageNumbers(pdfBookmarks, numberOfPages, null); bookmarks.addAll(pdfBookmarks); } for (int i = 1; i <= pdf.getNumberOfPages(); i++) { copy.addPage(copy.getImportedPage(pdf, i)); } numberOfPages += pdf.getNumberOfPages(); } } if (pdf != null) { SimpleNamedDestination.getNamedDestination(pdf, false); } if (!CollectionUtils.isEmpty(bookmarks)) { copy.setOutlines(bookmarks); } copy.close(); return copyBaos.toByteArray(); } }
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();// w ww .j av a 2s .c o m for (int i = 1; i <= reader.getNumberOfPages(); i++) { copy.addPage(copy.getImportedPage(reader, i)); } reader.close(); copy.close(); return copyBaos.toByteArray(); } }
From source file:be.roots.taconic.pricingguide.util.iTextUtil.java
License:Open Source License
public static Document createNewDocument() { final Document document = new Document(); document.setPageSize(PAGE_SIZE);/*from w w w .j a va2s . c om*/ document.setMargins(-10, -10, PAGE_MARGIN_TOP, PAGE_MARGIN_TOP); return document; }
From source file:be.thomasmore.controller.InputBean.java
public void createPdf(String filename) throws DocumentException, IOException { // step 1//from w ww. java2 s . 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 ww . j a v 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();// www .j ava 2s . c om 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) { } }