List of usage examples for com.lowagie.text.pdf BaseFont HELVETICA_OBLIQUE
String HELVETICA_OBLIQUE
To view the source code for com.lowagie.text.pdf BaseFont HELVETICA_OBLIQUE.
Click Source Link
From source file:com.actelion.research.spiritapp.print.CagePrinterPDF.java
License:Open Source License
public static void printCages(List<Container> cages, boolean printGroupsTreatments, boolean printTreatmentDesc, boolean whiteBackground) throws Exception { final int margin = 15; File f = File.createTempFile("cages__", ".pdf"); Document doc = new Document(PageSize.A4.rotate()); Image maleImg, femaleImg, nosexImg; try {/*from w ww . java 2s .co m*/ maleImg = Image.getInstance(CagePrinterPDF.class.getResource("male.png")); femaleImg = Image.getInstance(CagePrinterPDF.class.getResource("female.png")); nosexImg = Image.getInstance(CagePrinterPDF.class.getResource("nosex.png")); } catch (Exception e) { throw new Exception("Could not find images in the classpath: " + e); } FileOutputStream os = new FileOutputStream(f); PdfWriter writer = PdfWriter.getInstance(doc, os); doc.open(); PdfContentByte canvas = writer.getDirectContentUnder(); float tileW = (doc.getPageSize().getWidth()) / 4; float tileH = (doc.getPageSize().getHeight()) / 2; for (int i = 0; i < cages.size(); i++) { Container cage = cages.get(i); Study study = cage.getStudy(); Set<Group> groups = cage.getGroups(); Group group = cage.getGroup(); Set<Biosample> animals = new TreeSet<>(Biosample.COMPARATOR_NAME); animals.addAll(cage.getBiosamples()); //Find the treatments applied to this group Set<NamedTreatment> allTreatments = new LinkedHashSet<>(); for (Group gr : groups) { allTreatments.addAll(gr.getAllTreatments(-1)); } //Draw if (i % 8 == 0) { if (i > 0) doc.newPage(); drawCageSeparation(doc, canvas); } int col = (i % 8) % 4; int row = (i % 8) / 4; float x = margin + tileW * col; float x2 = x + tileW - margin; float baseY = tileH * row; float y; //Display Sex canvas.moveTo(tileW * col - 50, doc.getPageSize().getHeight() - (tileH * row + 50)); Image img = null; String sex = getMetadata(animals, "Sex"); if (study.isBlindAll()) { img = nosexImg; } else if (sex.equals("M")) { img = maleImg; } else if (sex.equals("F")) { img = femaleImg; } else if (sex.length() > 0) { img = nosexImg; } if (img != null) { img.scaleToFit(20, 20); img.setAbsolutePosition(tileW * (col + 1) - 33, doc.getPageSize().getHeight() - (tileH * row + 12 + margin)); doc.add(img); } if (group != null && group.getColor() != null && (study != null && !study.isBlind()) && !whiteBackground) { Color c = group.getColor(); canvas.saveState(); canvas.setRGBColorFill(c.getRed() / 3 + 170, c.getGreen() / 3 + 170, c.getBlue() / 3 + 170); canvas.rectangle(x - margin + 1, doc.getPageSize().getHeight() - baseY - tileH + 1, tileW - 2, tileH - 2); canvas.fill(); canvas.restoreState(); } Color treatmentColor = Color.BLACK; if (allTreatments.size() > 0 && !study.isBlind() && printGroupsTreatments) { int offset = 0; for (NamedTreatment t : allTreatments) { if (t.getColor() != null) { if (allTreatments.size() == 1) treatmentColor = new Color(t.getColor().getRed() / 2, t.getColor().getGreen() / 2, t.getColor().getBlue() / 2); canvas.saveState(); canvas.setColorStroke(Color.BLACK); canvas.setRGBColorFill(t.getColor().getRed(), t.getColor().getGreen(), t.getColor().getBlue()); y = baseY + 42 + 15 + 86 + 13 + 22 + 14 + 23 + 28; canvas.rectangle(x + 20 + offset * 5, doc.getPageSize().getHeight() - y - (offset % 2) * 4, 22, 22); canvas.fillStroke(); canvas.restoreState(); offset++; } } } canvas.beginText(); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_BOLD, "Cp1252", false), 16f); canvas.showTextAligned(Element.ALIGN_LEFT, cage.getContainerId(), x, doc.getPageSize().getHeight() - (baseY + 23), 0); canvas.setFontAndSize(BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, "Cp1252", false), 11f); y = 42 + baseY; canvas.showTextAligned(Element.ALIGN_LEFT, "Type: ", x, doc.getPageSize().getHeight() - y, 0); y += 15; canvas.showTextAligned(Element.ALIGN_LEFT, "Animals_ID: ", x, doc.getPageSize().getHeight() - y, 0); y += 86; canvas.showTextAligned(Element.ALIGN_LEFT, "Delivery date: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "PO Number: ", x, doc.getPageSize().getHeight() - y, 0); y += 22; canvas.showTextAligned(Element.ALIGN_LEFT, "Study: ", x, doc.getPageSize().getHeight() - y, 0); y += 14; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Group: ", x, doc.getPageSize().getHeight() - y, 0); y += 23; if (study != null && !study.isBlind() && printGroupsTreatments) canvas.showTextAligned(Element.ALIGN_LEFT, "Treatment: ", x, doc.getPageSize().getHeight() - y, 0); y += 50; canvas.showTextAligned(Element.ALIGN_LEFT, "License: ", x, doc.getPageSize().getHeight() - y, 0); y += 13; canvas.showTextAligned(Element.ALIGN_LEFT, "Experimenter: ", x, doc.getPageSize().getHeight() - y, 0); canvas.endText(); y = 42 + baseY; print(canvas, study.isBlindAll() ? "Blinded" : getMetadata(animals, "Type"), x + 65, doc.getPageSize().getHeight() - y, x2, 11, 11, FontFactory.HELVETICA, Color.BLACK, 11f); y += 15; if (animals.size() <= 6) { int n = 0; for (Biosample animal : animals) { print(canvas, animal.getSampleId(), x + 75, doc.getPageSize().getHeight() - y - 12 * n, x2 - 50, 12, 12, FontFactory.HELVETICA, Color.BLACK, 11f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x2 - 60, doc.getPageSize().getHeight() - y - 12 * n, x2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 11f); } n++; } } else { int nPerRow = animals.size() / 2; int n = 0; for (Biosample animal : animals) { int nx = n / nPerRow; int ny = n % nPerRow; print(canvas, animal.getSampleId(), x + nx * (x2 - x) / 2, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA, Color.BLACK, 10f); if (animal.getSampleName() != null && animal.getSampleName().length() > 0) { print(canvas, "[ " + animal.getSampleName() + " ]", x + (1 + nx) * (x2 - x) / 2 - 35, doc.getPageSize().getHeight() - y - 12 * ny - 12, x + (1 + nx) * (x2 - x) / 2, 12, 12, FontFactory.HELVETICA_BOLD, Color.BLACK, 10f); } n++; } } y += 86; print(canvas, getMetadata(animals, "Delivery Date"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, getMetadata(animals, "PO Number"), x + 75, doc.getPageSize().getHeight() - y, x2, 0, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 22; print(canvas, study.getStudyIdAndInternalId(), x + 40, doc.getPageSize().getHeight() - y, x2, 0, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 14; if (!study.isBlind() && printGroupsTreatments) print(canvas, getGroups(animals), x + 40, doc.getPageSize().getHeight() - y, x2, 22, 11, BaseFont.HELVETICA_BOLD, Color.BLACK, 11f); y += 23; if (!study.isBlind() && printGroupsTreatments) print(canvas, getTreatments(animals, printTreatmentDesc), x + 62, doc.getPageSize().getHeight() - y, x2, 50, printTreatmentDesc ? 9 : 12, FontFactory.HELVETICA, treatmentColor, printTreatmentDesc ? 9f : 10f); y += 50; print(canvas, study.getMetadataMap().get("LICENSENO"), x + 74, doc.getPageSize().getHeight() - y, x2, 15, 10, FontFactory.HELVETICA, Color.BLACK, 10f); y += 13; print(canvas, study.getMetadataMap().get("EXPERIMENTER"), x + 74, doc.getPageSize().getHeight() - y, x2, 20, 10, FontFactory.HELVETICA, Color.BLACK, 10f); } doc.close(); os.close(); Desktop.getDesktop().open(f); try { Thread.sleep(500); } catch (Exception e) { } }
From source file:com.moss.pdf.template.core.Renderer.java
License:Open Source License
public void render(InputStream in, List<? extends PropertyMapping> fields, OutputStream out) throws Exception { PdfReader reader = new PdfReader(in); Document document = new Document(reader.getPageSizeWithRotation(1)); PdfWriter writer = PdfWriter.getInstance(document, out); document.open();/*from ww w. j a v a 2s . c o m*/ for (int i = 1; i <= reader.getNumberOfPages(); i++) { PdfContentByte cb = writer.getDirectContent(); PdfImportedPage customPage = writer.getImportedPage(reader, i); /* * add the page to our new document, turning this page to its * original rotation */ int pageRotation = reader.getPageRotation(i); if (pageRotation > 0) { System.out.println("page rotation found: " + pageRotation); double angle = -((2 * Math.PI) * pageRotation / 360); // double angle = -(Math.PI / 2); cb.addTemplate(customPage, (float) Math.cos(angle), (float) Math.sin(angle), (float) -Math.sin(angle), (float) Math.cos(angle), 0f, // x document.top() + document.topMargin() // y ); } else { cb.addTemplate(customPage, 0f, 0f); } Map<FontName, BaseFont> fonts = new HashMap<FontName, BaseFont>(); for (PropertyMapping field : fields) { if (field.getPageNumber() != i) { continue; } /* * Only builtin fonts are supported at the moment */ BaseFont font; int fontSize; int alignment; String text; float x, y; float rotation; { font = fonts.get(field.getFontName()); if (font == null) { FontName e = field.getFontName(); String name = null; if (FontName.COURIER == e) { name = BaseFont.COURIER; } else if (FontName.COURIER_BOLD == e) { name = BaseFont.COURIER_BOLD; } else if (FontName.COURIER_BOLD_OBLIQUE == e) { name = BaseFont.COURIER_BOLDOBLIQUE; } else if (FontName.COURIER_OBLIQUE == e) { name = BaseFont.COURIER_OBLIQUE; } else if (FontName.HELVETICA == e) { name = BaseFont.HELVETICA; } else if (FontName.HELVETICA_BOLD == e) { name = BaseFont.HELVETICA_BOLD; } else if (FontName.HELVETICA_BOLD_OBLIQUE == e) { name = BaseFont.HELVETICA_BOLDOBLIQUE; } else if (FontName.HELVETICA_OBLIQUE == e) { name = BaseFont.HELVETICA_OBLIQUE; } else if (FontName.TIMES_BOLD == e) { name = BaseFont.TIMES_BOLD; } else if (FontName.TIMES_BOLD_ITALIC == e) { name = BaseFont.TIMES_BOLDITALIC; } else if (FontName.TIMES_ITALIC == e) { name = BaseFont.TIMES_ITALIC; } else if (FontName.TIMES_ROMAN == e) { name = BaseFont.TIMES_ROMAN; } if (name == null) { throw new RuntimeException("Unknown font type: " + e); } font = BaseFont.createFont(name, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED); fonts.put(field.getFontName(), font); } fontSize = field.getFontSize(); if (TextAlignment.LEFT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_LEFT; } else if (TextAlignment.CENTER == field.getAlignment()) { alignment = PdfContentByte.ALIGN_CENTER; } else if (TextAlignment.RIGHT == field.getAlignment()) { alignment = PdfContentByte.ALIGN_RIGHT; } else { alignment = PdfContentByte.ALIGN_LEFT; } Object value = p.eval(field.getExpr()); if (value == null) { text = ""; } else { text = value.toString(); } x = field.getX() * POINTS_IN_A_CM; y = field.getY() * POINTS_IN_A_CM; rotation = 0; } cb.beginText(); cb.setFontAndSize(font, fontSize); cb.showTextAligned(alignment, text, x, y, rotation); cb.endText(); } document.newPage(); } reader.close(); document.close(); }
From source file:org.oscarehr.phr.web.PHRUserManagementAction.java
License:Open Source License
public ByteArrayOutputStream generateUserRegistrationLetter(String demographicNo, String username, String password) throws Exception { log.debug("Demographic " + demographicNo + " username " + username + " password " + password); DemographicDao demographicDao = (DemographicDao) SpringUtils.getBean("demographicDao"); Demographic demographic = demographicDao.getDemographic(demographicNo); final String PAGESIZE = "printPageSize"; Document document = new Document(); ByteArrayOutputStream baosPDF = new ByteArrayOutputStream(); PdfWriter writer = null;/*from www .j av a2 s. co m*/ try { writer = PdfWriter.getInstance(document, baosPDF); String title = "TITLE"; String template = "MyOscarLetterHead.pdf"; Properties printCfg = getCfgProp(); String[] cfgVal = null; StringBuilder tempName = null; // get the print prop values Properties props = new Properties(); props.setProperty("letterDate", UtilDateUtilities.getToday("yyyy-MM-dd")); props.setProperty("name", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("dearname", demographic.getFirstName() + " " + demographic.getLastName()); props.setProperty("address", demographic.getAddress()); props.setProperty("city", demographic.getCity() + ", " + demographic.getProvince()); props.setProperty("postalCode", demographic.getPostal()); props.setProperty("credHeading", "MyOscar User Account Details"); props.setProperty("username", "Username: " + username); props.setProperty("password", "Password: " + password); //Temporary - the intro will change to be dynamic props.setProperty("intro", "We are pleased to provide you with a log in and password for your new MyOSCAR Personal Health Record. This account will allow you to connect electronically with our clinic. Please take a few minutes to review the accompanying literature for further information.We look forward to you benefiting from this service."); document.addTitle(title); document.addSubject(""); document.addKeywords("pdf, itext"); document.addCreator("OSCAR"); document.addAuthor(""); document.addHeader("Expires", "0"); Rectangle pageSize = PageSize.LETTER; document.setPageSize(pageSize); document.open(); // create a reader for a certain document String propFilename = oscar.OscarProperties.getInstance().getProperty("pdfFORMDIR", "") + "/" + template; PdfReader reader = null; try { reader = new PdfReader(propFilename); log.debug("Found template at " + propFilename); } catch (Exception dex) { log.debug("change path to inside oscar from :" + propFilename); reader = new PdfReader("/oscar/form/prop/" + template); log.debug("Found template at /oscar/form/prop/" + template); } // retrieve the total number of pages int n = reader.getNumberOfPages(); // retrieve the size of the first page Rectangle pSize = reader.getPageSize(1); float width = pSize.getWidth(); float height = pSize.getHeight(); log.debug("Width :" + width + " Height: " + height); PdfContentByte cb = writer.getDirectContent(); ColumnText ct = new ColumnText(cb); int fontFlags = 0; document.newPage(); PdfImportedPage page1 = writer.getImportedPage(reader, 1); cb.addTemplate(page1, 1, 0, 0, 1, 0, 0); BaseFont bf; // = normFont; String encoding; cb.setRGBColorStroke(0, 0, 255); String[] fontType; for (Enumeration e = printCfg.propertyNames(); e.hasMoreElements();) { tempName = new StringBuilder(e.nextElement().toString()); cfgVal = printCfg.getProperty(tempName.toString()).split(" *, *"); if (cfgVal[4].indexOf(";") > -1) { fontType = cfgVal[4].split(";"); if (fontType[1].trim().equals("italic")) fontFlags = Font.ITALIC; else if (fontType[1].trim().equals("bold")) fontFlags = Font.BOLD; else if (fontType[1].trim().equals("bolditalic")) fontFlags = Font.BOLDITALIC; else fontFlags = Font.NORMAL; } else { fontFlags = Font.NORMAL; fontType = new String[] { cfgVal[4].trim() }; } if (fontType[0].trim().equals("BaseFont.HELVETICA")) { fontType[0] = BaseFont.HELVETICA; encoding = BaseFont.CP1252; //latin1 encoding } else if (fontType[0].trim().equals("BaseFont.HELVETICA_OBLIQUE")) { fontType[0] = BaseFont.HELVETICA_OBLIQUE; encoding = BaseFont.CP1252; } else if (fontType[0].trim().equals("BaseFont.ZAPFDINGBATS")) { fontType[0] = BaseFont.ZAPFDINGBATS; encoding = BaseFont.ZAPFDINGBATS; } else { fontType[0] = BaseFont.COURIER; encoding = BaseFont.CP1252; } bf = BaseFont.createFont(fontType[0], encoding, BaseFont.NOT_EMBEDDED); // write in a rectangle area if (cfgVal.length >= 9) { Font font = new Font(bf, Integer.parseInt(cfgVal[5].trim()), fontFlags); ct.setSimpleColumn(Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), Integer.parseInt(cfgVal[7].trim()), (height - Integer.parseInt(cfgVal[8].trim())), Integer.parseInt(cfgVal[9].trim()), (cfgVal[0].trim().equals("left") ? Element.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? Element.ALIGN_RIGHT : Element.ALIGN_CENTER))); ct.setText(new Phrase(12, props.getProperty(tempName.toString(), ""), font)); ct.go(); continue; } // draw line directly if (tempName.toString().startsWith("__$line")) { cb.setRGBColorStrokeF(0f, 0f, 0f); cb.setLineWidth(Float.parseFloat(cfgVal[4].trim())); cb.moveTo(Float.parseFloat(cfgVal[0].trim()), Float.parseFloat(cfgVal[1].trim())); cb.lineTo(Float.parseFloat(cfgVal[2].trim()), Float.parseFloat(cfgVal[3].trim())); // stroke the lines cb.stroke(); // write text directly } else if (tempName.toString().startsWith("__")) { cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? (cfgVal[6].trim()) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } else if (tempName.toString().equals("forms_promotext")) { if (OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT") != null) { cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), OscarProperties.getInstance().getProperty("FORMS_PROMOTEXT"), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } else { // write prop text cb.beginText(); cb.setFontAndSize(bf, Integer.parseInt(cfgVal[5].trim())); cb.showTextAligned( (cfgVal[0].trim().equals("left") ? PdfContentByte.ALIGN_LEFT : (cfgVal[0].trim().equals("right") ? PdfContentByte.ALIGN_RIGHT : PdfContentByte.ALIGN_CENTER)), (cfgVal.length >= 7 ? ((props.getProperty(tempName.toString(), "").equals("") ? "" : cfgVal[6].trim())) : props.getProperty(tempName.toString(), "")), Integer.parseInt(cfgVal[1].trim()), (height - Integer.parseInt(cfgVal[2].trim())), 0); cb.endText(); } } } catch (DocumentException dex) { baosPDF.reset(); throw dex; } finally { if (document != null) document.close(); if (writer != null) writer.close(); } return baosPDF; }
From source file:org.pentaho.reporting.libraries.fonts.itext.ITextBuiltInFontRegistry.java
License:Open Source License
private FontFamily createHelveticaFamily() { final DefaultFontFamily fontFamily = new DefaultFontFamily("Helvetica"); fontFamily.addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA, false, false, false)); fontFamily//from w w w . j a v a 2s . c om .addFontRecord(new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLD, true, false, false)); fontFamily.addFontRecord( new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_OBLIQUE, false, true, true)); fontFamily.addFontRecord( new ITextBuiltInFontRecord(fontFamily, BaseFont.HELVETICA_BOLDOBLIQUE, true, true, true)); return fontFamily; }
From source file:org.pz.platypus.plugin.html.HtmlFont.java
License:Open Source License
/** * Get the name by which iText refers to this font. This routine is mostly occupied * with the special handling of the base14 fonts. For all other fonts, this routine * simply returns its existing name./* www . j a v a 2 s . c o m*/ * * @param f PdfFont whose iText name we're getting * @return a string containing the iText usable name for this font. */ String createItextFontName(final HtmlFont f) { String iTextFontName; String typefaceName = f.typeface; // handle the different versions of base14 fonts if (typefaceName.equals("COURIER")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; else iTextFontName = BaseFont.COURIER_BOLD; } else if (f.italics) iTextFontName = BaseFont.COURIER_OBLIQUE; else iTextFontName = BaseFont.COURIER; } else if (typefaceName.equals("HELVETICA")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; else iTextFontName = BaseFont.HELVETICA_BOLD; } else if (f.italics) iTextFontName = BaseFont.HELVETICA_OBLIQUE; else iTextFontName = BaseFont.HELVETICA; } else if (typefaceName.equals("TIMES_ROMAN")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.italics) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; } else if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; } else if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; } else // not a base14 font. So make sure we've loaded the font files for Platypus // then look up this font among them. If it's still not there, then return // a TIMES_ROMAN and note the error. { // if( htmlData.getTypefaceMap() == null ) { // TypefaceMap typefaceMap = new TypefaceMap( htmlData.getGdd() ); // typefaceMap.loadFamilies(); // htmlData.setTypefaceMap( typefaceMap ); // } // if the font files for this typeface/font family have not been previously registered, // then get the filenames from the typefaceMap and register them in iText's FontFactory if (!FontFactory.isRegistered(typefaceName)) { String[] fontFiles = pdfData.getTypefaceMap().getFamilyFilenames(typefaceName); for (String fontFile : fontFiles) { FontFactory.register(fontFile); } gdd.log("Registered fonts for " + typefaceName + " in iText"); } if (FontFactory.isRegistered(typefaceName)) { iTextFontName = typefaceName; } else { // the filename does not exist on the system, so substitute TIMES_ROMAN iTextFontName = BaseFont.TIMES_ROMAN; } // } // else { // gdd.logInfo( // gdd.getLit( "FILE#" ) + " " + source.getFileNumber() + " " + // gdd.getLit( "LINE#" ) + " " + source.getLineNumber() + ": " + // gdd.getLit( "ERROR.INVALID_FONT_TYPEFACE" ) + " " + // f.typeface + " " + // gdd.getLit( "IGNORED" )); // iTextFontName = typeface; } return (iTextFontName); }
From source file:org.pz.platypus.plugin.pdf.PdfFontFactory.java
License:Open Source License
/** * Gets the iText font name for any of the Base14 fonts. * * @param font the PdfFont whose name we're looking up. * @return the iText name or null if an error has occured *///from w w w. j av a2 s. co m String computeBase14ItextFontName(final PdfFont font) { final String typefaceName; String iTextFontName = null; PdfFont f; // in the impossible event this gets passed a null, then // replace it with the default font. It might be better // to just throw an exception. Should revisit this later. if (font == null) { f = new PdfFont(pdfData); } else { f = font; } typefaceName = f.getFace(); if (typefaceName.equals("COURIER")) { if (f.getBold()) { if (f.getItalics()) { iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; } else { iTextFontName = BaseFont.COURIER_BOLD; } } else if (f.getItalics()) { iTextFontName = BaseFont.COURIER_OBLIQUE; } else iTextFontName = BaseFont.COURIER; return (iTextFontName); } if (typefaceName.equals("HELVETICA")) { if (f.getBold()) { if (f.getItalics()) { iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; } else { iTextFontName = BaseFont.HELVETICA_BOLD; } } else if (f.getItalics()) { iTextFontName = BaseFont.HELVETICA_OBLIQUE; } else { iTextFontName = BaseFont.HELVETICA; } return (iTextFontName); } if (typefaceName.equals("TIMES_ROMAN")) { if (f.getBold()) { if (f.getItalics()) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.getItalics()) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; return (iTextFontName); } if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; return (iTextFontName); } if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; return (iTextFontName); } // in theory, impossible, since the font is validated before the function is called. return (iTextFontName); }
From source file:org.pz.platypus.plugin.rtf.RtfFont.java
License:Open Source License
/** * Get the name by which iText refers to this font. This routine is mostly occupied * with the special handling of the base14 fonts. * * For all other fonts, this method makes sure the font is registered with iText and * returns its name as registered by iText (which is the family name for the font). * * @param f PdfFont whose iText name we're getting * @return a string containing the iText usable name for this font. *///from ww w.j av a2 s . c o m String createItextFontName(final RtfFont f) { String iTextFontName; String typefaceName = f.typeface; // handle the different versions of base14 fonts if (typefaceName.equals("COURIER")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.COURIER_BOLDOBLIQUE; else iTextFontName = BaseFont.COURIER_BOLD; } else if (f.italics) iTextFontName = BaseFont.COURIER_OBLIQUE; else iTextFontName = BaseFont.COURIER; } else if (typefaceName.equals("HELVETICA")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.HELVETICA_BOLDOBLIQUE; else iTextFontName = BaseFont.HELVETICA_BOLD; } else if (f.italics) iTextFontName = BaseFont.HELVETICA_OBLIQUE; else iTextFontName = BaseFont.HELVETICA; } else if (typefaceName.equals("TIMES_ROMAN")) { if (f.bold) { if (f.italics) iTextFontName = BaseFont.TIMES_BOLDITALIC; else iTextFontName = BaseFont.TIMES_BOLD; } else if (f.italics) iTextFontName = BaseFont.TIMES_ITALIC; else iTextFontName = BaseFont.TIMES_ROMAN; } else if (typefaceName.equals("SYMBOL")) { iTextFontName = BaseFont.SYMBOL; } else if (typefaceName.equals("DINGBATS")) { iTextFontName = BaseFont.ZAPFDINGBATS; } else // It's not a base14 font. So make sure we've loaded the font files for Platypus // then look up this font among them. If it's still not there, then return // a TIMES_ROMAN and note the error. { if (!FontFactory.isRegistered(typefaceName)) { if (!findAndRegisterFont(typefaceName)) { return (null); } } if (FontFactory.isRegistered(typefaceName)) { iTextFontName = typefaceName; } else { // in theory, cannot get here. gdd.logWarning(gdd.getLit("COULD_NOT_FIND") + " " + typefaceName + " " + gdd.getLit("IN_FONT_REGISTER") + ". " + gdd.getLit("USING_TIMES_ROMAN") + "."); iTextFontName = null; } } return (iTextFontName); }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the title page of the PDF document. * /*from ww w . j a v a 2s . c om*/ * @throws ExportException * If an error occurs while creating the title page */ private void writeTitlePage() throws ExportException { try { Font plainFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font boldItalicFontTitle = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 12); Font plainFont = new Font(BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font boldItalicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLDOBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font italicFontSmall = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading); /* * date and time of the meeting */ String meetingDate = sdfDate.format(meeting.getPlannedDate().getTime()); String meetingTime = sdfTime.format(meeting.getPlannedStart().getTime()) + " - " + sdfTime.format(meeting.getPlannedEnd().getTime()) + " [" + meeting.getPlannedEnd().getTimeZone().getDisplayName() + "]"; ; /* * Base table */ PdfPTable table = new PdfPTable(new float[] { 0.04f, 0.96f }); table.setWidthPercentage(100); table.setSplitRows(false); table.getDefaultCell().setBorderWidth(0); table.getDefaultCell().setPadding(0); /* * recipient of the invitation */ PdfPCell cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); PdfPTable tableRecipient = new PdfPTable(2); tableRecipient.setWidthPercentage(100); tableRecipient.setSplitRows(false); tableRecipient.getDefaultCell().setBorderWidth(0); tableRecipient.getDefaultCell().setPadding(0); PdfPCell cellRecipient = new PdfPCell(); cellRecipient.setBorder(0); cellRecipient.setPadding(0); cellRecipient.addElement(new Phrase(translate("To:"), plainFontTitle)); cellRecipient.addElement(new Phrase(attendee.getName(), boldFontTitle)); tableRecipient.addCell(cellRecipient); PdfPCell cellDate = new PdfPCell(new Phrase(sdfDate.format(new Date().getTime()), plainFont)); cellDate.setHorizontalAlignment(Element.ALIGN_RIGHT); cellDate.setBorder(0); cellDate.setPadding(0); cellDate.setPaddingTop(7); tableRecipient.addCell(cellDate); cell.addElement(tableRecipient); cell.addElement(phraseStrut); cell.addElement(phraseStrut); cell.addElement(phraseStrut); /* * subject */ cell.addElement(new Phrase(translate("Invitation for the Meeting on") + " " + meetingDate, boldItalicFontTitle)); cell.addElement(phraseStrut); /* * invitation text */ Phrase phrase = new Phrase( Data.getInstance().getAppData().getSetting(AppSettingKey.PDF_INVITATION_TEXT), plainFont); phrase.setLeading(leading); cell.addElement(phrase); cell.addElement(phraseStrut); table.addCell(cell); /* * meeting date, time and location */ cell = new PdfPCell(new Phrase(meetingDate, boldItalicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); cell = new PdfPCell(new Phrase(meetingTime, italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); if (!meeting.getPlannedLocation().equals("")) { cell = new PdfPCell( new Phrase(translate("Location") + ": " + meeting.getPlannedLocation(), italicFont)); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.setPaddingBottom(0); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } /* * role; review title and description */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); cell.addElement(phraseStrut); cell.addElement(phraseStrut); phrase = new Phrase(); phrase.setLeading(leading); phrase.add(new Chunk(MessageFormat.format(translate("You are invited as {0} to this review ({1})."), translate(attendee.getRole().toString()), getReviewTitle()), boldFont)); cell.addElement(phrase); cell.addElement(phraseStrut); cell.addElement(new Phrase(resiData.getReview().getDescription(), italicFont)); cell.addElement(phraseStrut); /* * Predecessor meeting */ if (meetMgmt.getPredecessorMeeting(meeting) != null) { String preMeetingDate = sdfDate .format(meetMgmt.getPredecessorMeeting(meeting).getProtocol().getDate().getTime()); cell.addElement(new Phrase(MessageFormat .format(translate("This meeting ties up to the review meeting of {0}."), preMeetingDate), plainFont)); cell.addElement(phraseStrut); } /* * If there is a product name defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getName().trim().equals("")) { /* * the product of this review */ cell.addElement(new Phrase(translate("The following product will be reviewed:"), plainFont)); cell.addElement(phraseStrut); table.addCell(cell); /* * Write name and version of the reviewed product */ Phrase phrName = new Phrase(Data.getInstance().getResiData().getReview().getProduct().getName(), boldItalicFont); phrName.setLeading(leading); PdfPCell cellName = new PdfPCell(phrName); cellName.setColspan(2); cellName.setBorderWidth(0); cellName.setPadding(padding); cellName.setPaddingBottom(0); cellName.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellName); /* * If there is a product version defined */ if (!Data.getInstance().getResiData().getReview().getProduct().getVersion().trim().equals("")) { Phrase phrVersion = new Phrase( translate("Product Version") + ": " + Data.getInstance().getResiData().getReview().getProduct().getVersion(), italicFont); phrVersion.setLeading(leading); PdfPCell cellVersion = new PdfPCell(phrVersion); cellVersion.setColspan(2); cellVersion.setBorderWidth(0); cellVersion.setPadding(padding); cellVersion.setPaddingBottom(0); cellVersion.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cellVersion); } table.addCell(createVerticalStrut(PDFTools.cmToPt(0.7f), 2)); } else { table.addCell(cell); } boolean showBottomStrut = false; /* * List point used for lists */ Phrase phraseListPoint = new Phrase("", boldFont); phraseListPoint.setLeading(leading); PdfPCell cellListPoint = new PdfPCell(); cellListPoint.addElement(phraseListPoint); cellListPoint.setBorderWidth(0); cellListPoint.setPadding(padding); cellListPoint.setPaddingLeft(padding * 2); cellListPoint.setPaddingBottom(0); /* * Textual references */ for (String ref : Application.getInstance().getReviewMgmt().getProductReferences()) { Phrase phraseRef = new Phrase(ref, italicFontSmall); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); table.addCell(cellRef); showBottomStrut = true; } /* * External file references */ for (File ref : Application.getInstance().getReviewMgmt().getExtProdReferences()) { Phrase phraseRef = new Phrase(); phraseRef.add(new Chunk(ref.getName(), italicFontSmall)); phraseRef.add(new Chunk(" (" + translate("File Attachment") + ")", italicFontSmall)); phraseRef.setFont(plainFont); phraseRef.setLeading(leading); PdfPCell cellRef = new PdfPCell(); cellRef.addElement(phraseRef); cellRef.setBorderWidth(0); cellRef.setPadding(padding); cellRef.setPaddingBottom(0); table.addCell(cellListPoint); if (attachProdExtRefs) { cellRef.setCellEvent(new PDFCellEventExtRef(pdfWriter, ref)); } table.addCell(cellRef); showBottomStrut = true; } if (showBottomStrut) { table.addCell(createVerticalStrut(PDFTools.cmToPt(0.4f), 2)); } /* * "please prepare" for the reviwers; on questions ask moderators */ cell = new PdfPCell(); cell.setBorder(0); cell.setColspan(2); cell.setPadding(padding); phrase = new Phrase(); phrase.setLeading(leading); if (attendee.getAspects() != null) { phrase.add(new Chunk(translate( "Please prepare for the review meeting by checking the product for the aspects which are associated to you.") + " ", plainFont)); } List<Attendee> moderators = new ArrayList<Attendee>(); for (Attendee a : Application.getInstance().getAttendeeMgmt().getAttendees()) { if (a.getRole() == Role.MODERATOR) { moderators.add(a); } } if (moderators.size() == 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact the review moderator if you have any questions:") + " ", plainFont)); } else if (moderators.size() > 1 && attendee.getRole() != Role.MODERATOR) { phrase.add(new Chunk(translate( "Please do not hesitate to contact one of the review moderators if you have any questions:") + " ", plainFont)); } cell.addElement(phrase); Phrase phraseStrutSmall = new Phrase(" "); phraseStrutSmall.setLeading(leading / 2); if (moderators.size() > 0 && attendee.getRole() != Role.MODERATOR) { for (Attendee mod : moderators) { cell.addElement(phraseStrutSmall); cell.addElement(new Phrase(mod.getName(), boldFont)); cell.addElement(new Phrase(mod.getContact(), italicFont)); } } table.addCell(cell); pdfDoc.add(table); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot generate front page of the PDF document.")); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
/** * Write the aspects.//from ww w . java2 s. com * * @throws ExportException * If an error occurs while writing the aspects */ private void writeAspects() throws ExportException { /* * If the role of the attendee is not reviewer show all aspects */ List<Aspect> aspects = null; if (attendee.getRole() == Role.REVIEWER) { aspects = attMgmt.getAspects(attendee); } else { aspects = aspMgmt.getAspects(); } if (aspects.size() == 0) { return; } try { Font descriptionFont = new Font( BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font directiveFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font categoryFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); Font reviewerFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 9); /* * Build base table for all attendees */ PdfPTable tableAspects = new PdfPTable(1); tableAspects.setWidthPercentage(100); tableAspects.setSplitRows(false); tableAspects.getDefaultCell().setBorderWidth(0); tableAspects.getDefaultCell().setPadding(0); boolean grayBackground = true; for (Aspect asp : aspects) { /* * Build table for one aspect */ PdfPTable tableAspect = new PdfPTable(new float[] { 0.70f, 0.30f }); tableAspect.setWidthPercentage(100); tableAspect.getDefaultCell().setBorderWidth(0); tableAspect.getDefaultCell().setPadding(0); PdfPCell cellAspect = new PdfPCell(); cellAspect.setPadding(0); cellAspect.setBorder(0); Phrase phraseStrut = new Phrase(" "); phraseStrut.setLeading(leading * 0.4f); /* * directive and description of the aspect */ PdfPCell cell = new PdfPCell(); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingBottom(padding * 1.5f); cell.addElement(new Phrase(asp.getDirective(), directiveFont)); cell.addElement(phraseStrut); cell.addElement(new Phrase(asp.getDescription(), descriptionFont)); /* * the reviewers of this aspect (moderator only) */ if (attendee.getRole() == Role.MODERATOR) { cell.addElement(phraseStrut); cell.addElement(phraseStrut); String separator = ""; Phrase phraseReviewers = new Phrase(); phraseReviewers.setLeading(leading); phraseReviewers.setFont(reviewerFont); for (Attendee att : attMgmt.getAttendees()) { if (attMgmt.hasAspect(asp, att)) { phraseReviewers.add(new Chunk(separator + att.getName(), reviewerFont)); separator = " "; } } cell.addElement(phraseReviewers); } tableAspect.addCell(cell); /* * category of the aspect */ cell = new PdfPCell(new Phrase(asp.getCategory(), categoryFont)); cell.setBorderWidth(0); cell.setPadding(padding * 0.4f); cell.setPaddingTop(padding * 1.1f); cell.setHorizontalAlignment(Element.ALIGN_RIGHT); tableAspect.addCell(cell); cellAspect.addElement(tableAspect); cellAspect.setPadding(0); cellAspect.setPaddingLeft(padding); cellAspect.setPaddingRight(padding); if (grayBackground == true) { grayBackground = false; cellAspect.setBackgroundColor(cellBackground); } else { grayBackground = true; } /* * Add aspect to the list */ tableAspects.addCell(cellAspect); } PdfPCell cellBottomLine = new PdfPCell(); cellBottomLine.setPadding(0); cellBottomLine.setBorderWidth(0); cellBottomLine.setBorderWidthBottom(1); cellBottomLine.setBorderColor(cellBackground); tableAspects.addCell(cellBottomLine); /* * Add the attendee base table to the document */ pdfDoc.add(tableAspects); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException(translate("Cannot put aspects into the PDF document.")); } }
From source file:org.revager.export.InvitationPDFExporter.java
License:Open Source License
@Override protected void writeContent() throws ExportException { try {/* ww w . j ava 2 s. c o m*/ writeTitlePage(); Font italicFont = new Font( BaseFont.createFont(BaseFont.HELVETICA_OBLIQUE, BaseFont.CP1252, BaseFont.EMBEDDED), 10); PdfPTable tableAspIntro = new PdfPTable(1); tableAspIntro.setWidthPercentage(100); Phrase phraseAspIntro; PdfPCell cellAspIntro = new PdfPCell(); cellAspIntro.setBorderWidth(0); cellAspIntro.setPadding(0); cellAspIntro.setPaddingBottom(PDFTools.cmToPt(0.8f)); if (attendee.getAspects() != null) { pdfDoc.newPage(); phraseAspIntro = new Phrase(translate( "Please prepare for the review meeting by checking the product for the following aspects step by step:"), italicFont); cellAspIntro.addElement(phraseAspIntro); tableAspIntro.addCell(cellAspIntro); pdfDoc.add(tableAspIntro); } else if (attendee.getRole() != Role.REVIEWER) { pdfDoc.newPage(); phraseAspIntro = new Phrase(translate("The product will be checked for the following aspects:"), italicFont); cellAspIntro.addElement(phraseAspIntro); tableAspIntro.addCell(cellAspIntro); pdfDoc.add(tableAspIntro); } writeAspects(); } catch (Exception e) { /* * Not part of unit testing because this exception is only thrown if * an internal error occurs. */ throw new ExportException( translate("Cannot create invitation for the review meeting.") + "\n\n" + e.getMessage()); } }