List of usage examples for com.lowagie.text Font ITALIC
int ITALIC
To view the source code for com.lowagie.text Font ITALIC.
Click Source Link
From source file:edu.harvard.mcz.imagecapture.encoder.LabelEncoder.java
License:Open Source License
@SuppressWarnings("hiding") public static boolean printList(List<UnitTrayLabel> taxa) throws PrintFailedException { boolean result = false; UnitTrayLabel label = new UnitTrayLabel(); LabelEncoder encoder = new LabelEncoder(label); Image image = encoder.getImage(); int counter = 0; try {//from ww w. j av a 2s .co m Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("labels.pdf")); document.setPageSize(PageSize.LETTER); document.open(); PdfPTable table = new PdfPTable(4); table.setWidthPercentage(100f); //table.setHorizontalAlignment(PdfPTable.ALIGN_LEFT); float[] cellWidths = { 30f, 20f, 30f, 20f }; table.setWidths(cellWidths); UnitTrayLabelLifeCycle uls = new UnitTrayLabelLifeCycle(); if (taxa == null) { taxa = uls.findAll(); } Iterator<UnitTrayLabel> i = taxa.iterator(); PdfPCell cell = null; PdfPCell cell_barcode = null; // Create two lists of 12 cells, the first 6 of each representing // the left hand column of 6 labels, the second 6 of each // representing the right hand column. // cells holds the text for each label, cells_barcode the barcode. ArrayList<PdfPCell> cells = new ArrayList<PdfPCell>(12); ArrayList<PdfPCell> cells_barcode = new ArrayList<PdfPCell>(12); for (int x = 0; x < 12; x++) { cells.add(null); cells_barcode.add(null); } int cellCounter = 0; while (i.hasNext()) { // Loop through all of the taxa (unit tray labels) found to print label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { // For each taxon, loop through the number of requested copies // Generate a text and a barcode cell for each, and add to array for page log.debug("Label " + toPrint + " of " + label.getNumberToPrint()); cell = new PdfPCell(); cell.setBorderColor(Color.LIGHT_GRAY); cell.setVerticalAlignment(PdfPCell.ALIGN_TOP); cell.disableBorderSide(PdfPCell.RIGHT); cell.setPaddingLeft(3); String higherNames = ""; if (label.getTribe().trim().length() > 0) { higherNames = label.getFamily() + ": " + label.getSubfamily() + ": " + label.getTribe(); } else { higherNames = label.getFamily() + ": " + label.getSubfamily(); } Paragraph higher = new Paragraph(); higher.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); higher.add(new Chunk(higherNames)); cell.addElement(higher); Paragraph name = new Paragraph(); Chunk genus = new Chunk(label.getGenus().trim() + " "); genus.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); Chunk species = new Chunk(label.getSpecificEpithet().trim()); Chunk normal = null; // normal font prefix to preceed specific epithet (nr. <i>epithet</i>) if (label.getSpecificEpithet().contains(".") || label.getSpecificEpithet().contains("[")) { if (label.getSpecificEpithet().startsWith("nr. ")) { normal = new Chunk("nr. "); normal.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); species = new Chunk(label.getSpecificEpithet().trim().substring(4)); species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } } else { species.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } String s = ""; if (label.getSubspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk subspecies = new Chunk(s + label.getSubspecificEpithet().trim()); if (label.getSubspecificEpithet().contains(".") || label.getSubspecificEpithet().contains("[")) { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); } else { subspecies.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); } if (label.getInfraspecificRank().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infraRank = new Chunk(s + label.getInfraspecificRank().trim()); infraRank.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); if (label.getInfraspecificEpithet().trim().length() > 0) { s = " "; } else { s = ""; } Chunk infra = new Chunk(s + label.getInfraspecificEpithet().trim()); infra.setFont(new Font(Font.TIMES_ROMAN, 11, Font.ITALIC)); if (label.getUnNamedForm().trim().length() > 0) { s = " "; } else { s = ""; } Chunk unNamed = new Chunk(s + label.getUnNamedForm().trim()); unNamed.setFont(new Font(Font.TIMES_ROMAN, 11, Font.NORMAL)); name.add(genus); if (normal != null) { name.add(normal); } name.add(species); name.add(subspecies); name.add(infraRank); name.add(infra); name.add(unNamed); cell.addElement(name); Paragraph authorship = new Paragraph(); authorship.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); if (label.getAuthorship() != null && label.getAuthorship().length() > 0) { Chunk c_authorship = new Chunk(label.getAuthorship()); authorship.add(c_authorship); } cell.addElement(authorship); //cell.addElement(new Paragraph(" ")); if (label.getDrawerNumber() != null && label.getDrawerNumber().length() > 0) { Paragraph drawerNumber = new Paragraph(); drawerNumber.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_drawerNumber = new Chunk(label.getDrawerNumber()); drawerNumber.add(c_drawerNumber); cell.addElement(drawerNumber); } else { if (label.getCollection() != null && label.getCollection().length() > 0) { Paragraph collection = new Paragraph(); collection.setFont(new Font(Font.TIMES_ROMAN, 10, Font.NORMAL)); Chunk c_collection = new Chunk(label.getCollection()); collection.add(c_collection); cell.addElement(collection); } } cell_barcode = new PdfPCell(); cell_barcode.setBorderColor(Color.LIGHT_GRAY); cell_barcode.disableBorderSide(PdfPCell.LEFT); cell_barcode.setVerticalAlignment(PdfPCell.ALIGN_TOP); encoder = new LabelEncoder(label); image = encoder.getImage(); image.setAlignment(Image.ALIGN_TOP); cell_barcode.addElement(image); cells.add(cellCounter, cell); cells_barcode.add(cellCounter, cell_barcode); cellCounter++; // If we have hit a full set of 12 labels, add them to the document // in two columns, filling left column first, then right if (cellCounter == 12) { // add a page of 12 cells in columns of two. for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // Reset to begin next page cellCounter = 0; document.add(table); table = new PdfPTable(4); table.setWidthPercentage(100f); table.setWidths(cellWidths); for (int x = 0; x < 12; x++) { cells.set(x, null); cells_barcode.set(x, null); } } } // end loop through toPrint (for a taxon) counter++; } // end while results has next (for all taxa requested) // get any remaining cells in pairs for (int x = 0; x < 6; x++) { if (cells.get(x) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x)); table.addCell(cells_barcode.get(x)); } if (cells.get(x + 6) == null) { PdfPCell c = new PdfPCell(); c.setBorder(0); table.addCell(c); table.addCell(c); } else { table.addCell(cells.get(x + 6)); table.addCell(cells_barcode.get(x + 6)); } } // add any remaining cells document.add(table); try { document.close(); } catch (Exception e) { throw new PrintFailedException("No labels to print." + e.getMessage()); } // Check to see if there was content in the document. if (counter == 0) { result = false; } else { // Printed to pdf ok. result = true; // Increment number printed. i = taxa.iterator(); while (i.hasNext()) { label = i.next(); for (int toPrint = 0; toPrint < label.getNumberToPrint(); toPrint++) { label.setPrinted(label.getPrinted() + 1); } label.setNumberToPrint(0); try { uls.attachDirty(label); } catch (SaveFailedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("File not found."); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); throw new PrintFailedException("Error buiding PDF document."); } catch (OutOfMemoryError e) { System.out.println("Out of memory error. " + e.getMessage()); System.out.println("Failed. Too many labels."); throw new PrintFailedException("Ran out of memory, too many labels at once."); } return result; }
From source file:etc.Exporter.java
License:Open Source License
public static void saveAsPDF(File file, Task task) { try {/* www . j ava2s. c om*/ Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream(file)); document.open(); Paragraph taskid = new Paragraph("ID e Detyres: " + task.getIdentifier(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(taskid); Paragraph creator = new Paragraph("Krijuar nga " + task.getCreator().toString() + "[" + task.getCreationTime().format(DateTimeFormatter.ofPattern("dd.MM.yyyy - HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(creator); Paragraph executor = new Paragraph("Per zbatim prej: " + task.getExecutor().toString(), FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC)); document.add(executor); Paragraph title = new Paragraph(task.getTitle().toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD)); document.add(title); Paragraph description = new Paragraph(task.getDescription(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL)); document.add(description); PdfPCell cell = new PdfPCell(); cell.setBorder(Rectangle.BOTTOM); PdfPTable table = new PdfPTable(1); table.addCell(cell); table.setWidthPercentage(100f); document.add(table); if (task instanceof dc.CompletedTask) { document.add(new Paragraph( "Gjendja: Perfunduar [" + ((dc.CompletedTask) task).getCompletitionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.CompletedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else if (task instanceof dc.RejectedTask) { document.add(new Paragraph( "Gjendja: Refuzuar [" + ((dc.RejectedTask) task).getRejectionTime() .format(DateTimeFormatter.ofPattern("dd.MM.yyyy HH.mm")) + "]", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); document.add(new Paragraph("Shenimet e Zbatuesit".toUpperCase(), FontFactory.getFont(FontFactory.COURIER, 14, Font.BOLD))); document.add(new Paragraph(((dc.RejectedTask) task).getAnnotations(), FontFactory.getFont(FontFactory.COURIER, 12, Font.NORMAL))); } else { document.add(new Paragraph("Gjendja: Ne Pritje", FontFactory.getFont(FontFactory.COURIER, 10, Font.ITALIC))); } document.close(); Process p = Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + file.getAbsolutePath()); p.waitFor(); } catch (DocumentException | InterruptedException | IOException ex) { Logger.getLogger(Exporter.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public int getStyleFlag() { int style = Font.NORMAL; if (Boolean.TRUE.equals(fontItalic)) { style |= Font.ITALIC; }//from www . ja va 2 s. co m if (Boolean.TRUE.equals(fontBold)) { style |= Font.BOLD; } if (Boolean.TRUE.equals(fontUnderline)) { style |= Font.UNDERLINE; } if (Boolean.TRUE.equals(fontStrikeThru)) { style |= Font.STRIKETHRU; } return style; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public int getStyleFlagAsian() { int style = Font.NORMAL; if (Boolean.TRUE.equals(fontItalicAsian)) { style |= Font.ITALIC; }/*from ww w . ja v a 2 s .com*/ if (Boolean.TRUE.equals(fontBoldAsian)) { style |= Font.BOLD; } if (Boolean.TRUE.equals(fontUnderline)) { style |= Font.UNDERLINE; } if (Boolean.TRUE.equals(fontStrikeThru)) { style |= Font.STRIKETHRU; } return style; }
From source file:fr.opensagres.odfdom.converter.pdf.internal.styles.StyleTextProperties.java
License:Open Source License
public int getStyleFlagComplex() { int style = Font.NORMAL; if (Boolean.TRUE.equals(fontItalicComplex)) { style |= Font.ITALIC; }// ww w . j av a 2s . co m if (Boolean.TRUE.equals(fontBoldComplex)) { style |= Font.BOLD; } if (Boolean.TRUE.equals(fontUnderline)) { style |= Font.UNDERLINE; } if (Boolean.TRUE.equals(fontStrikeThru)) { style |= Font.STRIKETHRU; } return style; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.FastPdfMapper.java
License:Open Source License
@Override protected void visitRun(CTR run, CTP paragraph, boolean pageNumber, String url, IITextContainer pdfParagraphContainer) throws Exception { // Font family String fontFamilyAscii = stylesDocument.getFontFamilyAscii(run, paragraph); String fontFamilyEastAsia = stylesDocument.getFontFamilyEastAsia(run, paragraph); String fontFamilyHAnsi = stylesDocument.getFontFamilyHAnsi(run, paragraph); // Get font size Float fontSize = stylesDocument.getFontSize(run, paragraph); if (fontSize == null) { fontSize = -1f;//from ww w . j a va2s . c om } // Get font style int fontStyle = Font.NORMAL; Boolean bold = stylesDocument.getFontStyleBold(run, paragraph); if (bold != null && bold) { fontStyle |= Font.BOLD; } Boolean italic = stylesDocument.getFontStyleItalic(run, paragraph); if (italic != null && italic) { fontStyle |= Font.ITALIC; } Boolean strike = stylesDocument.getFontStyleStrike(run, paragraph); if (strike != null && strike) { fontStyle |= Font.STRIKETHRU; } // Font color Color fontColor = stylesDocument.getFontColor(run, paragraph); // Font this.currentRunFontAscii = getFont(fontFamilyAscii, fontSize, fontStyle, fontColor); this.currentRunFontEastAsia = getFont(fontFamilyEastAsia, fontSize, fontStyle, fontColor); this.currentRunFontHAnsi = getFont(fontFamilyHAnsi, fontSize, fontStyle, fontColor); // Underline patterns this.currentRunUnderlinePatterns = stylesDocument.getUnderline(run, paragraph); // background color this.currentRunBackgroundColor = stylesDocument.getBackgroundColor(run, paragraph); // highlight if (currentRunBackgroundColor == null) { this.currentRunBackgroundColor = stylesDocument.getTextHighlighting(run, paragraph); } StylableParagraph pdfParagraph = (StylableParagraph) pdfParagraphContainer; pdfParagraph.adjustMultipliedLeading(currentRunFontAscii); // addd symbol list item chunk if needed. String listItemText = pdfParagraph.getListItemText(); if (StringUtils.isNotEmpty(listItemText)) { // FIXME: add some space after the list item listItemText += " "; String listItemFontFamily = pdfParagraph.getListItemFontFamily(); Float listItemFontSize = pdfParagraph.getListItemFontSize(); int listItemFontStyle = pdfParagraph.getListItemFontStyle(); java.awt.Color listItemFontColor = pdfParagraph.getListItemFontColor(); Font listItemFont = options.getFontProvider().getFont( listItemFontFamily != null ? listItemFontFamily : fontFamilyAscii, options.getFontEncoding(), listItemFontSize != null ? listItemFontSize : fontSize, listItemFontStyle != Font.NORMAL ? listItemFontStyle : fontStyle, listItemFontColor != null ? listItemFontColor : Converter.toAwtColor(fontColor)); Chunk symbol = createTextChunk(listItemText, false, listItemFont, currentRunUnderlinePatterns, currentRunBackgroundColor); pdfParagraph.add(symbol); pdfParagraph.setListItemText(null); } IITextContainer container = pdfParagraphContainer; if (url != null) { // URL is not null, generate a PDF hyperlink. StylableAnchor pdfAnchor = new StylableAnchor(); pdfAnchor.setReference(url); pdfAnchor.setITextContainer(container); container = pdfAnchor; } super.visitRun(run, paragraph, pageNumber, url, pdfParagraphContainer); if (url != null) { // URL is not null, add the PDF hyperlink in the PDF paragraph pdfParagraphContainer.addElement((StylableAnchor) container); } this.currentRunFontAscii = null; this.currentRunFontEastAsia = null; this.currentRunFontHAnsi = null; this.currentRunUnderlinePatterns = null; this.currentRunBackgroundColor = null; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected IITextContainer startVisitParagraph(XWPFParagraph docxParagraph, ListItemContext itemContext, IITextContainer pdfParentContainer) throws Exception { this.currentRunX = null; // create PDF paragraph StylableParagraph pdfParagraph = pdfDocument.createParagraph(pdfParentContainer); // indentation left Float indentationLeft = stylesDocument.getIndentationLeft(docxParagraph); if (indentationLeft != null) { pdfParagraph.setIndentationLeft(indentationLeft); }/* www .j av a 2s . c o m*/ // indentation right Float indentationRight = stylesDocument.getIndentationRight(docxParagraph); if (indentationRight != null) { pdfParagraph.setIndentationRight(indentationRight); } // indentation first line Float indentationFirstLine = stylesDocument.getIndentationFirstLine(docxParagraph); if (indentationFirstLine != null) { pdfParagraph.setFirstLineIndent(indentationFirstLine); } // indentation hanging (remove first line) Float indentationHanging = stylesDocument.getIndentationHanging(docxParagraph); if (indentationHanging != null) { pdfParagraph.setFirstLineIndent(-indentationHanging); } // // spacing before Float spacingBefore = stylesDocument.getSpacingBefore(docxParagraph); if (spacingBefore != null) { pdfParagraph.setSpacingBefore(spacingBefore); } // spacing after Float spacingAfter = stylesDocument.getSpacingAfter(docxParagraph); if (spacingAfter != null) { pdfParagraph.setSpacingAfter(spacingAfter); } ParagraphLineSpacing lineSpacing = stylesDocument.getParagraphSpacing(docxParagraph); if (lineSpacing != null) { if (lineSpacing.getLeading() != null && lineSpacing.getMultipleLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading(), lineSpacing.getMultipleLeading()); } else { if (lineSpacing.getLeading() != null) { pdfParagraph.setLeading(lineSpacing.getLeading()); } if (lineSpacing.getMultipleLeading() != null) { pdfParagraph.setMultipliedLeading(lineSpacing.getMultipleLeading()); } } } // text-align ParagraphAlignment alignment = stylesDocument.getParagraphAlignment(docxParagraph); if (alignment != null) { switch (alignment) { case LEFT: pdfParagraph.setAlignment(Element.ALIGN_LEFT); break; case RIGHT: pdfParagraph.setAlignment(Element.ALIGN_RIGHT); break; case CENTER: pdfParagraph.setAlignment(Element.ALIGN_CENTER); break; case BOTH: pdfParagraph.setAlignment(Element.ALIGN_JUSTIFIED); break; default: break; } } // background-color Color backgroundColor = stylesDocument.getBackgroundColor(docxParagraph); if (backgroundColor != null) { pdfParagraph.setBackgroundColor(Converter.toAwtColor(backgroundColor)); } // border CTBorder borderTop = stylesDocument.getBorderTop(docxParagraph); pdfParagraph.setBorder(borderTop, Rectangle.TOP); CTBorder borderBottom = stylesDocument.getBorderBottom(docxParagraph); pdfParagraph.setBorder(borderBottom, Rectangle.BOTTOM); CTBorder borderLeft = stylesDocument.getBorderLeft(docxParagraph); pdfParagraph.setBorder(borderLeft, Rectangle.LEFT); CTBorder borderRight = stylesDocument.getBorderRight(docxParagraph); pdfParagraph.setBorder(borderRight, Rectangle.RIGHT); if (itemContext != null) { CTLvl lvl = itemContext.getLvl(); CTPPr lvlPPr = lvl.getPPr(); if (lvlPPr != null) { if (ParagraphIndentationLeftValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the indentation from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float indLeft = ParagraphIndentationLeftValueProvider.INSTANCE.getValue(lvlPPr); if (indLeft != null) { pdfParagraph.setIndentationLeft(indLeft); } } if (ParagraphIndentationHangingValueProvider.INSTANCE .getValue(docxParagraph.getCTP().getPPr()) == null) { // search the hanging from the level properties only if // paragraph has not override it // see // https://code.google.com/p/xdocreport/issues/detail?id=239 Float hanging = stylesDocument.getIndentationHanging(lvlPPr); if (hanging != null) { pdfParagraph.setFirstLineIndent(-hanging); } } } CTRPr lvlRPr = lvl.getRPr(); if (lvlRPr != null) { // Font family String listItemFontFamily = stylesDocument.getFontFamilyAscii(lvlRPr); // Get font size Float listItemFontSize = stylesDocument.getFontSize(lvlRPr); // Get font style int listItemFontStyle = Font.NORMAL; Boolean bold = stylesDocument.getFontStyleBold(lvlRPr); if (bold != null && bold) { listItemFontStyle |= Font.BOLD; } Boolean italic = stylesDocument.getFontStyleItalic(lvlRPr); if (italic != null && italic) { listItemFontStyle |= Font.ITALIC; } Boolean strike = stylesDocument.getFontStyleStrike(lvlRPr); if (strike != null && strike) { listItemFontStyle |= Font.STRIKETHRU; } // Font color Color listItemFontColor = stylesDocument.getFontColor(lvlRPr); pdfParagraph.setListItemFontFamily(listItemFontFamily); pdfParagraph.setListItemFontSize(listItemFontSize); pdfParagraph.setListItemFontStyle(listItemFontStyle); pdfParagraph.setListItemFontColor(Converter.toAwtColor(listItemFontColor)); } pdfParagraph.setListItemText(itemContext.getText()); } return pdfParagraph; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.PdfMapper.java
License:Open Source License
@Override protected void visitRun(XWPFRun docxRun, boolean pageNumber, String url, IITextContainer pdfParagraphContainer) throws Exception { // Font family String fontFamilyAscii = stylesDocument.getFontFamilyAscii(docxRun); String fontFamilyEastAsia = stylesDocument.getFontFamilyEastAsia(docxRun); String fontFamilyHAnsi = stylesDocument.getFontFamilyHAnsi(docxRun); // Get font size Float fontSize = stylesDocument.getFontSize(docxRun); if (fontSize == null) { fontSize = -1f;/* w w w .j ava2 s .co m*/ } // Get font style int fontStyle = Font.NORMAL; Boolean bold = stylesDocument.getFontStyleBold(docxRun); if (bold != null && bold) { fontStyle |= Font.BOLD; } Boolean italic = stylesDocument.getFontStyleItalic(docxRun); if (italic != null && italic) { fontStyle |= Font.ITALIC; } Boolean strike = stylesDocument.getFontStyleStrike(docxRun); if (strike != null && strike) { fontStyle |= Font.STRIKETHRU; } // Font color Color fontColor = stylesDocument.getFontColor(docxRun); // Font this.currentRunFontAscii = getFont(fontFamilyAscii, fontSize, fontStyle, fontColor); this.currentRunFontEastAsia = getFont(fontFamilyEastAsia, fontSize, fontStyle, fontColor); this.currentRunFontHAnsi = getFont(fontFamilyHAnsi, fontSize, fontStyle, fontColor); // Underline patterns this.currentRunUnderlinePatterns = stylesDocument.getUnderline(docxRun); // background color this.currentRunBackgroundColor = stylesDocument.getBackgroundColor(docxRun); // highlight if (currentRunBackgroundColor == null) { this.currentRunBackgroundColor = stylesDocument.getTextHighlighting(docxRun); } StylableParagraph pdfParagraph = (StylableParagraph) pdfParagraphContainer; pdfParagraph.adjustMultipliedLeading(currentRunFontAscii); // addd symbol list item chunk if needed. String listItemText = pdfParagraph.getListItemText(); if (StringUtils.isNotEmpty(listItemText)) { // FIXME: add some space after the list item listItemText += " "; String listItemFontFamily = pdfParagraph.getListItemFontFamily(); Float listItemFontSize = pdfParagraph.getListItemFontSize(); int listItemFontStyle = pdfParagraph.getListItemFontStyle(); java.awt.Color listItemFontColor = pdfParagraph.getListItemFontColor(); Font listItemFont = options.getFontProvider().getFont( listItemFontFamily != null ? listItemFontFamily : fontFamilyAscii, options.getFontEncoding(), listItemFontSize != null ? listItemFontSize : fontSize, listItemFontStyle != Font.NORMAL ? listItemFontStyle : fontStyle, listItemFontColor != null ? listItemFontColor : Converter.toAwtColor(fontColor)); Chunk symbol = createTextChunk(listItemText, false, listItemFont, currentRunUnderlinePatterns, currentRunBackgroundColor); pdfParagraph.add(symbol); pdfParagraph.setListItemText(null); } IITextContainer container = pdfParagraphContainer; if (url != null) { // URL is not null, generate a PDF hyperlink. StylableAnchor pdfAnchor = new StylableAnchor(); pdfAnchor.setReference(url); pdfAnchor.setITextContainer(container); container = pdfAnchor; } super.visitRun(docxRun, pageNumber, url, container); if (url != null) { // URL is not null, add the PDF hyperlink in the PDF paragraph pdfParagraphContainer.addElement((StylableAnchor) container); } this.currentRunFontAscii = null; this.currentRunFontEastAsia = null; this.currentRunFontHAnsi = null; this.currentRunUnderlinePatterns = null; this.currentRunBackgroundColor = null; }
From source file:fr.opensagres.xdocreport.itext.extension.font.AbstractFontRegistry.java
License:Open Source License
/** * checks if this font is Bold./*from w w w.java 2 s .com*/ * * @return a <CODE>boolean</CODE> */ public boolean isItalic(int style) { if (style == Font.UNDEFINED) { return false; } return (style & Font.ITALIC) == Font.ITALIC; }
From source file:fr.univlorraine.mondossierweb.controllers.CalendrierController.java
License:Apache License
/** * //from w w w. j a v a 2 s . co m * @param document pdf */ public void creerPdfCalendrier(final Document document, Etudiant etudiant) { //configuration des fonts Font normal = FontFactory.getFont(FontFactory.TIMES_ROMAN, 10, Font.NORMAL); Font normalbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 11, Font.BOLD); Font legerita = FontFactory.getFont(FontFactory.TIMES_ROMAN, 9, Font.ITALIC); Font headerbig = FontFactory.getFont(FontFactory.TIMES_ROMAN, 16, Font.BOLD); Font header = FontFactory.getFont(FontFactory.TIMES_ROMAN, 12, Font.BOLD); //pieds de pages: Date d = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); String date = dateFormat.format(d); //alignement des libells du pied de page: String partie1 = applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()); String partie2 = applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date; if (partie1.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie1.length(); for (int i = 0; i < diff; i++) { partie1 = partie1 + " "; } } if (partie2.length() < ECARTEMENT_PIED_PAGE_PDF) { int diff = ECARTEMENT_PIED_PAGE_PDF - partie2.length(); for (int i = 0; i < diff; i++) { partie2 = " " + partie2; } } //cration du pied de page: Phrase phra = new Phrase( partie1 + " -" + applicationContext.getMessage("pdf.page", null, Locale.getDefault()), legerita); Phrase phra2 = new Phrase("- " + partie2, legerita); HeaderFooter hf = new HeaderFooter(phra, phra2); hf.setAlignment(HeaderFooter.ALIGN_CENTER); document.setFooter(hf); //ouverte du document. document.open(); try { //ajout image test if (configController.getLogoUniversitePdf() != null && !configController.getLogoUniversitePdf().equals("")) { Image image1 = Image.getInstance(configController.getLogoUniversitePdf()); float scaleRatio = 40 / image1.getHeight(); float newWidth = scaleRatio * image1.getWidth(); image1.scaleAbsolute(newWidth, 40); image1.setAbsolutePosition(800 - newWidth, 528); document.add(image1); } //nouveau paragraphe Paragraph p = new Paragraph( applicationContext.getMessage("pdf.calendrier.title", null, Locale.getDefault()).toUpperCase() + "\n\n", headerbig); p.setIndentationLeft(15); document.add(p); if (etudiant.getNom() != null) { Paragraph p0 = new Paragraph(etudiant.getNom(), normal); p0.setIndentationLeft(15); document.add(p0); } if (etudiant.getCod_etu() != null) { Paragraph p01 = new Paragraph(applicationContext.getMessage("pdf.folder", null, Locale.getDefault()) + " : " + etudiant.getCod_etu(), normal); p01.setIndentationLeft(15); document.add(p01); } if (etudiant.getCod_nne() != null) { Paragraph p02 = new Paragraph(applicationContext.getMessage("pdf.nne", null, Locale.getDefault()) + " : " + etudiant.getCod_nne(), normal); p02.setIndentationLeft(15); document.add(p02); } if (etudiant.getEmail() != null) { Paragraph p03 = new Paragraph(applicationContext.getMessage("pdf.mail", null, Locale.getDefault()) + " : " + etudiant.getEmail(), normal); p03.setIndentationLeft(15); document.add(p03); } Paragraph p03 = new Paragraph( applicationContext.getMessage("pdf.edition.date", null, Locale.getDefault()) + " : " + date, normal); p03.setIndentationLeft(15); document.add(p03); document.add(new Paragraph("\n")); //Partie Calendrier PdfPTable table = new PdfPTable(1); table.setWidthPercentage(98); PdfPCell cell = new PdfPCell(new Paragraph(applicationContext .getMessage("pdf.calendrier.subtitle", null, Locale.getDefault()).toUpperCase() + " ", header)); cell.setBorder(Rectangle.NO_BORDER); cell.setBackgroundColor(new Color(153, 153, 255)); table.addCell(cell); PdfPTable table2; boolean affNumPlaceExamen = configController.isAffNumPlaceExamen(); if (affNumPlaceExamen) { table2 = new PdfPTable(7); table2.setWidthPercentage(98); int[] tabWidth = { 15, 10, 10, 40, 30, 10, 60 }; table2.setWidths(tabWidth); } else { table2 = new PdfPTable(6); table2.setWidthPercentage(98); int[] tabWidth = { 15, 10, 10, 45, 30, 65 }; table2.setWidths(tabWidth); } Paragraph p1 = new Paragraph(applicationContext.getMessage("pdf.date", null, Locale.getDefault()), normalbig); Paragraph p2 = new Paragraph(applicationContext.getMessage("pdf.heure", null, Locale.getDefault()), normalbig); Paragraph p3 = new Paragraph(applicationContext.getMessage("pdf.duree", null, Locale.getDefault()), normalbig); Paragraph p4 = new Paragraph(applicationContext.getMessage("pdf.batiment", null, Locale.getDefault()), normalbig); Paragraph p5 = new Paragraph(applicationContext.getMessage("pdf.salle", null, Locale.getDefault()), normalbig); Paragraph p6 = new Paragraph(applicationContext.getMessage("pdf.place", null, Locale.getDefault()), normalbig); Paragraph p7 = new Paragraph(applicationContext.getMessage("pdf.examen", null, Locale.getDefault()), normalbig); PdfPCell ct1 = new PdfPCell(p1); PdfPCell ct2 = new PdfPCell(p2); PdfPCell ct3 = new PdfPCell(p3); PdfPCell ct4 = new PdfPCell(p4); PdfPCell ct5 = new PdfPCell(p5); PdfPCell ct6 = new PdfPCell(p6); PdfPCell ct7 = new PdfPCell(p7); ct1.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct2.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct3.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct4.setBorder(Rectangle.BOTTOM); ct1.setBorderColorBottom(Color.black); ct5.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct6.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); ct7.setBorder(Rectangle.BOTTOM); ct2.setBorderColorBottom(Color.black); table2.addCell(ct1); table2.addCell(ct2); table2.addCell(ct3); table2.addCell(ct4); table2.addCell(ct5); if (affNumPlaceExamen) table2.addCell(ct6); table2.addCell(ct7); for (int i = 0; i < etudiant.getCalendrier().size(); i++) { Paragraph pa = new Paragraph(etudiant.getCalendrier().get(i).getDatedeb(), normal); PdfPCell celltext = new PdfPCell(pa); celltext.setBorder(Rectangle.NO_BORDER); Paragraph pa2 = new Paragraph(etudiant.getCalendrier().get(i).getHeure(), normal); PdfPCell celltext2 = new PdfPCell(pa2); celltext2.setBorder(Rectangle.NO_BORDER); Paragraph pa3 = new Paragraph(etudiant.getCalendrier().get(i).getDuree(), normal); PdfPCell celltext3 = new PdfPCell(pa3); celltext3.setBorder(Rectangle.NO_BORDER); Paragraph pa4 = new Paragraph(etudiant.getCalendrier().get(i).getBatiment(), normal); PdfPCell celltext4 = new PdfPCell(pa4); celltext4.setBorder(Rectangle.NO_BORDER); Paragraph pa5 = new Paragraph(etudiant.getCalendrier().get(i).getSalle(), normal); PdfPCell celltext5 = new PdfPCell(pa5); celltext5.setBorder(Rectangle.NO_BORDER); Paragraph pa6 = new Paragraph(etudiant.getCalendrier().get(i).getPlace(), normal); PdfPCell celltext6 = new PdfPCell(pa6); celltext6.setBorder(Rectangle.NO_BORDER); Paragraph pa7 = new Paragraph(etudiant.getCalendrier().get(i).getEpreuve(), normal); PdfPCell celltext7 = new PdfPCell(pa7); celltext7.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext); table2.addCell(celltext2); table2.addCell(celltext3); table2.addCell(celltext4); table2.addCell(celltext5); if (affNumPlaceExamen) table2.addCell(celltext6); table2.addCell(celltext7); /*PdfPCell celltext4 = new PdfPCell(table3); celltext4.setBorder(Rectangle.NO_BORDER); table2.addCell(celltext4);*/ } document.add(table); document.add(table2); document.add(new Paragraph("\n")); } catch (BadElementException e) { LOG.error("Erreur la gnration du calendrier des examens : BadElementException ", e); } catch (MalformedURLException e) { LOG.error("Erreur la gnration du calendrier des examens : MalformedURLException ", e); } catch (IOException e) { LOG.error("Erreur la gnration du calendrier des examens : IOException ", e); } catch (DocumentException e) { LOG.error("Erreur la gnration du calendrier des examens : DocumentException ", e); } // step 6: fermeture du document. document.close(); }