List of usage examples for com.itextpdf.text ListItem ListItem
public ListItem(final float leading, final String string)
ListItem
with a certain String
and a certain leading. From source file:com.athena.chameleon.engine.utils.PDFWriterUtil.java
License:Apache License
/** * /*from w ww. ja va2 s . c om*/ * list * * @param section list section ? * @param e list element * @throws Exception */ public static void setList(Section section, Element e) throws Exception { List list = new List(false, 15); list.setIndentationLeft(23); for (Element e1 : e.getChildren()) { ListItem item = new ListItem(e1.getText(), fnNormal); if (e1.getChild("url") != null) { item.add(getUrl(e1.getChild("url"))); } item.setMultipliedLeading(1.8F); list.add(item); } list.getFirstItem().setSpacingBefore(-14); list.getLastItem().setSpacingAfter(14); section.add(list); }
From source file:com.biblio.web.rest.PdfResources.java
@RequestMapping(value = "livre", method = RequestMethod.GET) public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, WriterException { response.setContentType("application/pdf"); GenerateQRCode ge = new GenerateQRCode(); try {//from w ww. j ava2 s .c o m Document document = new Document(); String param = request.getParameter("isbn"); Livre livre = livreRepository.findOneByIsbn(param).get(); PdfWriter e = PdfWriter.getInstance(document, response.getOutputStream()); document.open(); Font font = new Font(); font.setStyle(Font.BOLD); font.setSize(12); List list = new List(15); // document.left(12); list.add(new ListItem("Titre :" + livre.getTitre(), font)); list.add(new ListItem("Categorie :" + livre.getCategorie().getDescription(), font)); list.add(new ListItem("Auteurs :" + livre.getAuteurs(), font)); list.add(new ListItem("Edition :" + livre.getEdition(), font)); list.add(new ListItem("Editeur :" + livre.getEditeur(), font)); list.add(new ListItem("Collection :" + livre.getCollection(), font)); list.add(new ListItem("Date parution :" + livre.getDateParution(), font)); list.add(new ListItem("Isbn " + livre.getIsbn(), font)); list.add(new ListItem("Resume : " + livre.getResume(), font)); document.add(list); document.addTitle(livre.getTitre()); document.setMargins(100, 20, 0, 0); document.addCreationDate(); System.out.println("TTT v " + document.addTitle(param)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ImageIO.write(ge.createQRImage(param, 125), "jpg", baos); Image image = Image.getInstance(baos.toByteArray()); document.add(image); document.close(); } catch (DocumentException de) { throw new IOException(de.getMessage()); } }
From source file:com.poscoict.license.service.CertificateService.java
public Map<String, Object> getLicenseCertification(String userNo, String licenseFileName, HttpServletRequest req) throws Exception { logger.info("_________getLicenseCertification: " + userNo + " " + licenseFileName); String PDFFileName = userNo + licenseFileName; String PDFFilePath = Consts.PDF_PATH + PDFFileName + ".pdf"; String ImgFilePath = Consts.IMG_PATH + PDFFileName + "1." + Consts.IMG_FORMAT; Map<String, Object> map = new HashMap<String, Object>(); map.put("PDFFileName", PDFFileName + ".pdf"); map.put("ImgFileName", PDFFileName + "1." + Consts.IMG_FORMAT); Map<String, Object> licenseInfo = (Map<String, Object>) managementDao.getLicenseCertification(userNo, licenseFileName);/*from ww w . j a va2s . c o m*/ Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(PDFFilePath)); document.open(); Paragraph p0 = new Paragraph(" "); Paragraph p1 = null; p1 = setParagraph("License Certificate", Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(p0); document.add(p0); document.add( setParagraph("? End User (?) : " + licenseInfo.get("USER_NAME"), Fonts.FONT12BOLD)); document.add( setParagraph("? Address (): " + licenseInfo.get("USER_ADDRESS"), Fonts.FONT12BOLD)); document.add( setParagraph("? Project (): " + licenseInfo.get("PROJECT_NAME"), Fonts.FONT12BOLD)); document.add(p0); PdfPTable table = new PdfPTable(2); table.setWidthPercentage(100); PdfPCell cell; cell = new PdfPCell(new Phrase(" Product Description", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" " + licenseInfo.get("PRODUCT_FILE_NAME"), getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" License Number", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" " + licenseInfo.get("LICENSE_KEY"), getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell(new Phrase(" Quantity", getFont(Fonts.FONT12BOLD))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); cell = new PdfPCell( new Phrase(" " + licenseInfo.get("LICENSE_QUANTITY") + " EA", getFont(Fonts.FONT12NOAML))); cell.setFixedHeight(30); cell.setPaddingTop(8f); table.addCell(cell); document.add(table); document.add(p0); List list = new List(false, 20); list.add(new ListItem( " License Certificate ?? ? ? ? ? ?? ??.", getFont(Fonts.FONT12NOAML))); list.add(new ListItem( "License Certificate ? ?? ? ? ? ? ?.", getFont(Fonts.FONT12NOAML))); list.add(new ListItem(", ? ?? .", getFont(Fonts.FONT12NOAML))); document.add(list); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph(licenseInfo.get("USER_START_DATE").toString(), Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); p1 = setParagraph(licenseInfo.get("COMPANY_NAME").toString(), Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); // Image img = Image.getInstance(Consts.SIGNET_IMG_PATH); // img.setAbsolutePosition(350f, 390f); // document.add(img); document.close(); } catch (DocumentException de) { logger.error(ImgFilePath, de); } catch (IOException ioe) { logger.error(ImgFilePath, ioe); } String temp = req.getSession().getServletContext().getRealPath(Consts.IMG_TEMP_FOLDER); System.out.println("________________________________________________" + temp); if (extractPagesAsImage(PDFFilePath, PDFFileName, 100, "")) { fileCopy(ImgFilePath, temp + File.separator + map.get("ImgFileName")); } return map; }
From source file:com.poscoict.license.service.CertificateService.java
public Map<String, Object> getTechSupportCertificationInfo(String userNo, String productFileId, HttpServletRequest req) throws Exception { logger.info("_________getTechSupportCertificationInfo: " + userNo + " " + productFileId); String PDFFileName = userNo + "_TechSupportCertification"; String PDFFilePath = Consts.PDF_PATH + PDFFileName + ".pdf"; String ImgFilePath = Consts.IMG_PATH + PDFFileName + "1." + Consts.IMG_FORMAT; Map<String, Object> map = new HashMap<String, Object>(); map.put("PDFFileName", PDFFileName + ".pdf"); map.put("ImgFileName", PDFFileName + "1." + Consts.IMG_FORMAT); Map<String, Object> productInfo = managementDao.getTechSupportCertificationInfo(userNo, productFileId); if (productInfo.get("TECH_SUPPORT_DATE").equals("0")) { throw new UserException( "? ? . ?? ?."); }/*from w w w . jav a2 s . c om*/ Document document = new Document(); try { PdfWriter.getInstance(document, new FileOutputStream(PDFFilePath)); document.open(); Paragraph p0 = new Paragraph(" "); Paragraph p1 = null; Paragraph header = new Paragraph("? ", getFont(Fonts.FONT20BOLD)); header.setAlignment(Paragraph.ALIGN_CENTER); document.add(header); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph("POSCO ICT ? ? " + productInfo.get("PRODUCT_FILE_NAME") + " ? ," + " ? ? ?? ? ? ?" + " ? .", Fonts.FONT18NOAML); document.add(p1); document.add(p0); document.add(p0); p1 = setParagraph("- -", Fonts.FONT18NOAML); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); document.add(p0); document.add(p0); List list = new List(false, 30); list.add(new ListItem("? ? ? : " + productInfo.get("USER_START_DATE"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("PRODUCT_FILE_NAME") + " (" + productInfo.get("LICENSE_QUANTITY") + "?)", getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? ? : POSCO ICT", getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("PROJECT_NAME"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? : " + productInfo.get("COMPANY_NAME"), getFont(Fonts.FONT18NOAML))); list.add(new ListItem("? ? : " + productInfo.get("TECH_SUPPORT_DATE"), getFont(Fonts.FONT18NOAML))); document.add(list); document.add(p0); document.add(p0); document.add(p0); p1 = setParagraph("POSCO ICT", Fonts.FONT20BOLD); p1.setAlignment(Paragraph.ALIGN_CENTER); document.add(p1); // Image img = Image.getInstance(Consts.SIGNET_IMG_PATH); // img.setAbsolutePosition(350f, 260f); // document.add(img); document.close(); } catch (DocumentException de) { logger.error(ImgFilePath, de); } catch (IOException ioe) { logger.error(ImgFilePath, ioe); } String temp = req.getSession().getServletContext().getRealPath(Consts.IMG_TEMP_FOLDER); if (extractPagesAsImage(PDFFilePath, PDFFileName, 100, "")) { fileCopy(ImgFilePath, temp + File.separator + map.get("ImgFileName")); } return map; }
From source file:edu.clemson.lph.pdfgen.PDFGen.java
License:Open Source License
private void printDoc() { if (sSourceFile == null || osDest == null) { logger.error("Cannot print nothing"); return;//from w w w.j av a 2 s. c om } boolean bBold = false; boolean bCenter = false; boolean bItalic = false; boolean bSmallItalic = false; boolean bUnderline = false; try { Document doc = new Document(); float fCorr = doc.getPageSize().getWidth() / 8.5f; doc.setMargins(1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr, 1.0f * fCorr); PdfWriter.getInstance(doc, osDest); doc.open(); BufferedReader br = new BufferedReader(new FileReader(sSourceFile)); String sLine = br.readLine(); while (sLine != null) { bBold = false; bCenter = false; if (sLine.startsWith(".")) { String sRest = sLine.substring(1); String sCodes = sRest.substring(0, sRest.indexOf('.')); sLine = sRest.substring(sRest.indexOf('.') + 1); if ("image".equals(sCodes)) { String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); sLine = br.readLine(); continue; } else if ("himage".equals(sCodes)) { String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.scaleToFit(500, 40); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); Paragraph p = new Paragraph(" "); doc.add(p); sLine = br.readLine(); continue; } else if ("fimage".equals(sCodes)) { int iBlanks = 9; // How do I figure out how many to get to end? for (int i = 0; i < iBlanks; i++) { Paragraph p = new Paragraph(" "); doc.add(p); } String sFileName = sLine; com.itextpdf.text.Image image = com.itextpdf.text.Image.getInstance(sFileName); image.scaleToFit(500, 40); image.setAlignment(Element.ALIGN_CENTER); doc.add(image); sLine = br.readLine(); continue; } else if ("list".equals(sCodes)) { String sFullLine = doSub(sLine); StringTokenizer tok = new StringTokenizer(sFullLine, "\n"); List list = new List(List.UNORDERED); while (tok.hasMoreTokens()) { String sNextLine = tok.nextToken(); ListItem listItem = new ListItem(sNextLine, fNormal); list.add(listItem); } doc.add(list); sLine = br.readLine(); continue; } if (sCodes.contains("b")) bBold = true; if (sCodes.contains("c")) bCenter = true; if (sCodes.contains("i")) bItalic = true; if (sCodes.contains("si")) bSmallItalic = true; if (sCodes.contains("u")) bUnderline = true; } if (sLine.trim().length() == 0) sLine = " "; String sFullLine = doSub(sLine); Paragraph p = new Paragraph(); if (bBold) p.setFont(fBold); else if (bSmallItalic) p.setFont(fSmallItalic); else if (bItalic) p.setFont(fItalic); else if (bUnderline) p.setFont(fUnderline); else p.setFont(fNormal); if (bCenter) { p.setAlignment(Element.ALIGN_CENTER); } else { p.setAlignment(Element.ALIGN_LEFT); } p.add(sFullLine); doc.add(p); sLine = br.readLine(); } br.close(); doc.close(); } catch (FileNotFoundException e) { logger.error("Could not find source file " + sSourceFile + " or destination", e); } catch (IOException e) { logger.error("Could not read file " + sSourceFile, e); } catch (DocumentException e) { logger.error("Error creating iText Document", e); } }
From source file:org.smap.sdal.managers.PDFSurveyManager.java
License:Open Source License
private void processSelect(Parser parser, String remoteUser, PdfPCell cell, DisplayItem di, boolean generateBlank, GlobalVariables gv, int oId) throws Exception { Font f = null;/*from w w w . ja v a 2s . c o m*/ boolean isRtl = false; // If generating blank template List list = new List(); list.setAutoindent(false); list.setSymbolIndent(24); String lang; boolean isSelectMultiple = di.type.equals("select") ? true : false; // Questions that append their values to this question ArrayList<String> deps = gv.addToList.get(di.fIdx + "_" + di.rec_number + "_" + di.name); /* * Add the value of this question unless * The form is not blank and the value is "other" and their are 1 or more dependent questions * In this case we assume that its only the values of the dependent questions that are needed */ if (generateBlank) { // TODO get real choices using choice manager Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); OptionList ol = survey.optionLists.get(question.list_name); for (Option o : ol.options) { String text = null; if (o.display_name != null && o.display_name.trim().length() > 0) { text = o.display_name; } else { text = o.labels.get(languageIdx).text; } lang = GeneralUtilityMethods.getLanguage(text); f = getFont(lang); isRtl = isRtl(lang); ListItem item = new ListItem(GeneralUtilityMethods.unesc(text), f); if (isSelectMultiple) { item.setListSymbol(new Chunk("\uf096", Symbols)); list.add(item); } else { item.setListSymbol(new Chunk("\uf10c", Symbols)); list.add(item); } } if (isRtl) { cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); } cell.addElement(list); } else { if (deps == null || (di.value != null && !di.value.trim().toLowerCase().equals("other"))) { String value = di.value; if (di.type.equals("select1")) { Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); ArrayList<String> matches = new ArrayList<String>(); matches.add(di.value); value = choiceManager.getLabel(sd, cResults, user, oId, survey.id, question.id, question.l_id, question.external_choices, question.external_table, survey.languages.get(languageIdx).name, languageIdx, matches, survey.ident); } else if (di.type.equals("select")) { String nameValue = value; if (nameValue != null) { String vArray[] = nameValue.split(" "); ArrayList<String> matches = new ArrayList<String>(); if (vArray != null) { for (String v : vArray) { matches.add(v); } } Form form = survey.forms.get(di.fIdx); Question question = form.questions.get(di.qIdx); value = choiceManager.getLabel(sd, cResults, user, oId, survey.id, question.id, question.l_id, question.external_choices, question.external_table, survey.languages.get(languageIdx).name, languageIdx, matches, survey.ident); } } if (GeneralUtilityMethods.isRtlLanguage(di.value)) { cell.setRunDirection(PdfWriter.RUN_DIRECTION_RTL); } parser.elements.clear(); String html = getHtml(value, di, gv, deps); try { parser.xmlParser.parse(new StringReader(html)); } catch (Exception e) { log.info("Error parsing: " + html.toString() + " : " + e.getMessage()); lm.writeLog(sd, survey.getId(), remoteUser, LogManager.ERROR, e.getMessage() + " for: " + html.toString()); cell.addElement(getPara(html.toString(), di, gv, null, null)); } for (Element element : parser.elements) { cell.addElement(element); } //cell.addElement(getPara(value, di, gv, deps, null)); } } }
From source file:se.inera.intyg.rehabstod.service.export.pdf.PdfExportServiceImpl.java
License:Open Source License
private Element getFilterDesc(PrintSjukfallRequest printRequest, RehabstodUser user) { // Fritext/*w w w .j a v a 2 s .c om*/ Paragraph valdFritext = new Paragraph(FILTER_TITLE_FRITEXTFILTER, PdfExportConstants.FRONTPAGE_H3); valdFritext.add( new Paragraph(StringUtil.isNullOrEmpty(printRequest.getFritext()) ? "-" : printRequest.getFritext(), PdfExportConstants.FRONTPAGE_NORMAL)); // Visa Patientuppgifter Paragraph visaPatientUppgifter = new Paragraph(FILTER_TITLE_VISAPATIENTUPPGIFTER, PdfExportConstants.FRONTPAGE_H3); visaPatientUppgifter.add( new Phrase(printRequest.isShowPatientId() ? " Ja" : " Nej", PdfExportConstants.FRONTPAGE_NORMAL)); // lder Paragraph valdAlder = new Paragraph(FILTER_TITLE_VALD_ALDER, PdfExportConstants.FRONTPAGE_H3); Paragraph alderVarden = new Paragraph(); alderVarden.add(new Chunk("Mellan ", PdfExportConstants.FRONTPAGE_NORMAL)); alderVarden.add(new Chunk(String.valueOf(printRequest.getAldersIntervall().getMin()), PdfExportConstants.FRONTPAGE_NORMAL_BOLD)); alderVarden.add(new Chunk(" och ", PdfExportConstants.FRONTPAGE_NORMAL)); alderVarden.add(new Chunk(String.valueOf(printRequest.getAldersIntervall().getMax()), PdfExportConstants.FRONTPAGE_NORMAL_BOLD)); alderVarden.add(new Chunk(" r.", PdfExportConstants.FRONTPAGE_NORMAL)); valdAlder.add(alderVarden); // Diagnoser Paragraph valdaDiagnoser = new Paragraph(FILTER_TITLE_VALDA_DIAGNOSER, PdfExportConstants.FRONTPAGE_H3); com.itextpdf.text.List diagnosLista = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); if (printRequest.getDiagnosGrupper() != null) { printRequest.getDiagnosGrupper().forEach(dg -> diagnosLista .add(new ListItem(getDiagnosKapitelDisplayValue(dg), PdfExportConstants.FRONTPAGE_NORMAL))); } else { diagnosLista.add(new ListItem(SELECTION_VALUE_ALLA, PdfExportConstants.FRONTPAGE_NORMAL)); } valdaDiagnoser.add(diagnosLista); // Slutdddatum Paragraph valdSlutdatum = new Paragraph(FILTER_TITLE_VALD_SLUTDATUM, PdfExportConstants.FRONTPAGE_H3); Paragraph slutdatumVarden = new Paragraph(getFilterDate(printRequest.getSlutdatumIntervall()), PdfExportConstants.FRONTPAGE_NORMAL); valdSlutdatum.add(slutdatumVarden); // Sjukskrivningslangd Paragraph valdSjukskrivninglangd = new Paragraph(FILTER_TITLE_VALD_SJUKSKRIVNINGSLANGD, PdfExportConstants.FRONTPAGE_H3); Paragraph sjukskrivningslangdVarden = new Paragraph(); sjukskrivningslangdVarden.add(new Chunk("Mellan ", PdfExportConstants.FRONTPAGE_NORMAL)); sjukskrivningslangdVarden.add(new Chunk(String.valueOf(printRequest.getLangdIntervall().getMin()), PdfExportConstants.FRONTPAGE_NORMAL_BOLD)); sjukskrivningslangdVarden.add(new Chunk(" och ", PdfExportConstants.FRONTPAGE_NORMAL)); sjukskrivningslangdVarden.add(new Chunk(String.valueOf(printRequest.getLangdIntervall().getMax()), PdfExportConstants.FRONTPAGE_NORMAL_BOLD)); sjukskrivningslangdVarden.add(new Chunk(" dagar.", PdfExportConstants.FRONTPAGE_NORMAL)); valdSjukskrivninglangd.add(sjukskrivningslangdVarden); // Lakare Paragraph valdaLakare = new Paragraph(FILTER_TITLE_VALDA_LAKARE, PdfExportConstants.FRONTPAGE_H3); com.itextpdf.text.List lakarLista = new com.itextpdf.text.List(com.itextpdf.text.List.UNORDERED); if (printRequest.getLakare() != null) { printRequest.getLakare() .forEach(dg -> lakarLista.add(new ListItem(dg, PdfExportConstants.FRONTPAGE_NORMAL))); } else { lakarLista .add(new ListItem(user.getUrval() == Urval.ISSUED_BY_ME ? user.getNamn() : SELECTION_VALUE_ALLA, PdfExportConstants.FRONTPAGE_NORMAL)); } valdaLakare.add(lakarLista); // Lagg ihop undergrupperna till filter Paragraph filter = new Paragraph(VALDA_FILTER, PdfExportConstants.FRONTPAGE_H2); filter.add(valdFritext); filter.add(visaPatientUppgifter); filter.add(valdAlder); filter.add(valdaDiagnoser); filter.add(valdSlutdatum); filter.add(valdSjukskrivninglangd); filter.add(valdaLakare); return filter; }