List of usage examples for com.itextpdf.text BaseColor BaseColor
public BaseColor(final int argb)
From source file:fr.opensagres.odfdom.converter.pdf.Converter.java
License:Open Source License
public static BaseColor toBaseColor(Color color) { if (color == null) return null; return new BaseColor(color.getRGB()); }
From source file:fr.opensagres.odfdom.converter.pdf.internal.ColorRegistry.java
License:Open Source License
@Override protected BaseColor createColor(String hexColor) { if (hexColor != null && !"auto".equals(hexColor) && !"transparent".equals(hexColor)) { return new BaseColor(Color.decode(hexColor).getRGB()); }// w ww. j a v a2s .com return null; }
From source file:fr.opensagres.poi.xwpf.converter.pdf.internal.Converter.java
License:Open Source License
public static BaseColor toBaseColor(Color color) { if (color == null) { return null; }//w w w. j a v a 2 s . co m return new BaseColor(color.getRGB()); }
From source file:htmlparser.pdf.PDFFile.java
public void createScoreTable(Color oddrow_color, Color title_bg_color, Color title_font_color, int highlight) { if (this.opened) { int columnNumber = 0; for (String s : this.parser.getTeams().get(0).getData()) { columnNumber++;//from w ww . j a v a 2 s . c o m } PdfPTable table = new PdfPTable(columnNumber + 1); Font f = new Font(this.fonttype, 13); int row = 1; Font headline = new Font(f); headline.setStyle("bold"); headline.setSize(16); headline.setColor(new BaseColor(title_bg_color.getRGB())); PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getCompetitionName(), headline)); headcell.setColspan(columnNumber + 1); headcell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(headcell); Font title = new Font(f); title.setStyle("bold"); title.setColor(new BaseColor(title_font_color.getRGB())); for (String s : this.shColNms) { PdfPCell cell = new PdfPCell(new Paragraph(s, title)); cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } row++; int order = 1; Font tfont = f; Font bold = new Font(f); bold.setStyle("bold"); for (Team t : this.parser.getTeams()) { if (highlight >= 0) { if (order == highlight + 1) { tfont = bold; } else { tfont = f; } } PdfPCell ordercell = new PdfPCell(new Paragraph(Integer.toString(order), tfont)); ordercell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { ordercell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(ordercell); for (String s : t.getData()) { PdfPCell cell = new PdfPCell(new Paragraph(s, tfont)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(cell); } order++; row++; } try { float[] widths = { 12f, 40f, 13f, 5f, 5f, 5f, 10f, 10f }; table.setWidths(widths); this.document.add(table); } catch (DocumentException ex) { System.out.println("Content exception"); } } }
From source file:htmlparser.pdf.PDFFile.java
public void createMatchTable(Color oddrow_color, Color title_bg_color, Color title_font_color) { if (this.opened) { this.document.newPage(); int columnNumber = 0; for (String s : this.parser.getMatches().get(0).getData()) { columnNumber++;// w w w. jav a2 s .c o m } PdfPTable table = new PdfPTable(columnNumber); Font f = new Font(this.fonttype, 13); int row = 1; Font headline = new Font(f); headline.setStyle("bold"); headline.setSize(16); headline.setColor(new BaseColor(title_bg_color.getRGB())); PdfPCell headcell = new PdfPCell(new Paragraph(this.parser.getTeamName(), headline)); headcell.setColspan(columnNumber); headcell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(headcell); Font title = new Font(f); title.setStyle("bold"); title.setColor(new BaseColor(title_font_color.getRGB())); for (String s : this.mhColNms) { PdfPCell cell = new PdfPCell(new Paragraph(s, title)); cell.setBackgroundColor(new BaseColor(title_bg_color.getRGB())); cell.setHorizontalAlignment(Element.ALIGN_CENTER); table.addCell(cell); } row++; for (Match t : this.parser.getMatches()) { for (String s : t.getData()) { PdfPCell cell = new PdfPCell(new Paragraph(s, f)); cell.setHorizontalAlignment(Element.ALIGN_CENTER); if (row % 2 == 0) { cell.setBackgroundColor(new BaseColor(oddrow_color.getRGB())); } table.addCell(cell); } row++; } try { float[] widths = { 26f, 26f, 20f, 8f, 20f }; table.setWidths(widths); this.document.add(table); } catch (DocumentException ex) { } } }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private void assignBorders(CellStyle style, PdfPCell pdfCell) { pdfCell.setBorderWidth(0);/* ww w.ja v a 2 s.c o m*/ Border border = style.getBorders(Border.LINE_LEFT); if (border != null) { pdfCell.setBorderWidthLeft(border.getLineWidth()); pdfCell.setBorderColorLeft(new BaseColor(border.getColor().getRGB())); } border = style.getBorders(Border.LINE_RIGHT); if (border != null) { pdfCell.setBorderWidthRight(border.getLineWidth()); pdfCell.setBorderColorRight(new BaseColor(border.getColor().getRGB())); } border = style.getBorders(Border.LINE_TOP); if (border != null) { pdfCell.setBorderWidthTop(border.getLineWidth()); pdfCell.setBorderColorTop(new BaseColor(border.getColor().getRGB())); } border = style.getBorders(Border.LINE_BOTTOM); if (border != null) { pdfCell.setBorderWidthBottom(border.getLineWidth()); pdfCell.setBorderColorBottom(new BaseColor(border.getColor().getRGB())); } }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
private PdfPCell writeCell(ReportModel model, jdbreport.model.Cell srcCell, int row, int col) throws BadElementException, IOException, SaveReportException { CellStyle style = model.getStyles(srcCell.getStyleId()); java.awt.Rectangle rect = model.getCellRect(row, col, true, true); float h = (float) Units.PT.setYPixels((int) rect.getHeight()); float w = (float) Units.PT.setXPixels((int) rect.getWidth()); PdfPCell pdfCell;/*w w w .j a v a2 s . com*/ if (srcCell.getPicture() != null) { Icon icon = srcCell.getPicture().getIcon(); java.awt.Image awtImage = ((ImageIcon) icon).getImage(); com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell = new PdfPCell(image); } else { pdfCell = new PdfPCell(); String text = null; if (srcCell.getValue() instanceof CellValue<?>) { StringWriter strWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(strWriter); if (!((CellValue<?>) srcCell.getValue()).write(printWriter, model, row, col, this, ReportBook.PDF)) { java.awt.Image awtImage = ((CellValue<?>) srcCell.getValue()).getAsImage(model, row, col); if (awtImage != null) { com.itextpdf.text.Image image = awtImageToImage(awtImage, srcCell, w, h); pdfCell.setImage(image); } } else { text = strWriter.getBuffer().toString(); } } else { if (jdbreport.model.Cell.TEXT_HTML.equals(srcCell.getContentType())) { writeHTMLText(model.getStyles(srcCell.getStyleId()), srcCell, pdfCell); } else { text = model.getCellText(srcCell); } } if (text != null && text.length() > 0) { com.itextpdf.text.Font font; if (fonts.containsKey(style.getId())) { font = fonts.get(style.getId()); } else { font = getFontMapper().styleToPdf(style); fonts.put(style.getId(), font); } Paragraph p; if (font != null) { p = new Paragraph(text, font); } else { p = new Paragraph(text); } pdfCell.setPhrase(p); } } pdfCell.setFixedHeight(h); pdfCell.setPadding(1); pdfCell.setBackgroundColor(new BaseColor(style.getBackground().getRGB())); pdfCell.setHorizontalAlignment(toPdfHAlignment(style.getHorizontalAlignment())); pdfCell.setVerticalAlignment(toPdfVAlignment(style.getVerticalAlignment())); if (style.getAngle() != 0) { pdfCell.setRotation(roundAngle(style.getAngle())); } assignBorders(style, pdfCell); pdfCell.setNoWrap(!style.isWrapLine()); if (srcCell.getColSpan() > 0) { pdfCell.setColspan(srcCell.getColSpan() + 1); } if (srcCell.getRowSpan() > 0) { pdfCell.setRowspan(srcCell.getRowSpan() + 1); } return pdfCell; }
From source file:jdbreport.model.io.pdf.itext5.PdfWriter.java
License:Apache License
protected void writeHTMLText(CellStyle parentStyle, jdbreport.model.Cell cell, PdfPCell pdfCell) { if (cell.isNull() || cell.isChild()) return;//from w w w .j a v a 2 s. c om JTextComponent tc = getHTMLReportRenderer(); tc.setText(cell.getText()); List<Content> contentList = Content.getHTMLContentList((HTMLDocument) tc.getDocument()); if (contentList != null) { Phrase phrase = new Phrase(); for (Content content : contentList) { CellStyle newStyle = content.createTextStyle(parentStyle, parentStyle); if (newStyle == null) { newStyle = parentStyle; } if (newStyle != null) { if (newStyle.getTypeOffset() == CellStyle.SS_SUPER || newStyle.getTypeOffset() == CellStyle.SS_SUB) { newStyle = newStyle.deriveFont((float) newStyle.getSize() / 2); } int i = textStyles.indexOf(newStyle); if (i < 0) { textStyles.add(newStyle); i = textStyles.size() - 1; } Font font; String styleId = "T" + (i + 1); if (fonts.containsKey(styleId)) { font = fonts.get(styleId); } else { font = getFontMapper().styleToPdf(newStyle); fonts.put(styleId, font); } Chunk chunk = new Chunk(content.getText(), font); chunk.setBackground(new BaseColor(newStyle.getBackground().getRGB())); if (newStyle.getTypeOffset() == CellStyle.SS_SUPER) { chunk.setTextRise(newStyle.getSize() / 2); } else if (newStyle.getTypeOffset() == CellStyle.SS_SUB) { chunk.setTextRise(-newStyle.getSize() / 2); } phrase.add(chunk); } else { phrase.add(new Chunk(content.getText())); } } pdfCell.setPhrase(phrase); } }
From source file:jdbreport.model.io.pdf.itext5.ReportFontMapper.java
License:Apache License
public com.itextpdf.text.Font styleToPdf(CellStyle style) { try {/*w w w . j av a 2s . c o m*/ java.awt.Font font = new java.awt.Font(style.getFamily(), style.getStyle(), style.getSize()); BaseFont baseFont = awtToPdf(font); if (baseFont != null) { return new com.itextpdf.text.Font(baseFont, (float) style.getSize(), style.getStyle(), new BaseColor(style.getForegroundColor().getRGB())); } } catch (Exception e) { throw new ExceptionConverter(e); } return null; }
From source file:nz.ac.waikato.cms.doc.SimplePDFOverlay.java
License:Open Source License
/** * Applies the instructions to the input PDF. * * @return null if successful, otherwise error message *//*from w w w. ja v a 2s . co m*/ public String execute() { String result; String line; BufferedReader breader; FileReader freader; int i; int lineNo; String units; int pageNo; PdfReader reader; PdfStamper stamper; PdfContentByte cb; ColumnText ct; Font font; String[] parts; StringBuilder text; result = null; freader = null; breader = null; try { reader = new PdfReader(new FileInputStream(m_Pdf.getAbsolutePath())); stamper = new PdfStamper(reader, new FileOutputStream(m_Output.getAbsolutePath())); freader = new FileReader(m_Instructions); breader = new BufferedReader(freader); lineNo = 0; units = "pt"; pageNo = 1; cb = stamper.getOverContent(pageNo); font = null; while ((line = breader.readLine()) != null) { lineNo++; if (line.trim().startsWith(PREFIX_COMMENT)) continue; if (line.trim().length() == 0) continue; if (line.startsWith(PREFIX_UNITS)) { units = line.substring(PREFIX_UNITS.length()).trim().toLowerCase(); } else if (line.startsWith(PREFIX_PAGE)) { pageNo = Integer.parseInt(line.substring(PREFIX_PAGE.length()).trim()); cb = stamper.getOverContent(pageNo); } else if (line.startsWith(PREFIX_FONT)) { parts = line.substring(PREFIX_FONT.length()).trim().split(" "); if (parts.length == 3) font = FontFactory.getFont(parts[0], Float.parseFloat(parts[1]), new BaseColor(parseColor(parts[2]).getRGB())); else m_Logger.warning("Font instruction not in expected format (" + FORMAT_FONT + "):\n" + line); } else if (line.startsWith(PREFIX_TEXT)) { parts = line.substring(PREFIX_TEXT.length()).trim().split(" "); if (parts.length >= 7) { ct = new ColumnText(cb); ct.setSimpleColumn(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // llx parseLocation(parts[1], reader.getPageSize(pageNo).getHeight(), units), // lly parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // urx parseLocation(parts[3], reader.getPageSize(pageNo).getHeight(), units), // ury Float.parseFloat(parts[4]), // leading parseAlignment(parts[5])); // alignment text = new StringBuilder(); for (i = 6; i < parts.length; i++) { if (text.length() > 0) text.append(" "); text.append(parts[i]); } if (font == null) ct.setText(new Phrase(text.toString())); else ct.setText(new Phrase(text.toString(), font)); ct.go(); } else { m_Logger.warning("Text instruction not in expected format (" + FORMAT_TEXT + "):\n" + line); } } else if (line.startsWith(PREFIX_LINE)) { parts = line.substring(PREFIX_LINE.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // color cb.moveTo(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units)); // y cb.lineTo(parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units)); // h cb.stroke(); cb.restoreState(); } else { m_Logger.warning("Line instruction not in expected format (" + FORMAT_LINE + "):\n" + line); } } else if (line.startsWith(PREFIX_RECT)) { parts = line.substring(PREFIX_RECT.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.rectangle(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // w parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // h ); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke if (parts.length >= 7) { cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill cb.fillStroke(); } else { cb.stroke(); } cb.restoreState(); } else { m_Logger.warning( "Rectangle instruction not in expected format (" + FORMAT_RECT + "):\n" + line); } } else if (line.startsWith(PREFIX_OVAL)) { parts = line.substring(PREFIX_OVAL.length()).trim().split(" "); if (parts.length >= 6) { cb.saveState(); cb.ellipse(parseLocation(parts[0], reader.getPageSize(pageNo).getWidth(), units), // x1 parseLocation(parts[1], reader.getPageSize(pageNo).getWidth(), units), // y1 parseLocation(parts[2], reader.getPageSize(pageNo).getWidth(), units), // x2 parseLocation(parts[3], reader.getPageSize(pageNo).getWidth(), units) // y2 ); cb.setLineWidth(Float.parseFloat(parts[4])); // line width cb.setColorStroke(new BaseColor(parseColor(parts[5]).getRGB())); // stroke if (parts.length >= 7) { cb.setColorFill(new BaseColor(parseColor(parts[6]).getRGB())); // fill cb.fillStroke(); } else { cb.stroke(); } cb.restoreState(); } else { m_Logger.warning("Oval instruction not in expected format (" + FORMAT_OVAL + "):\n" + line); } } else { m_Logger.warning("Unknown command on line #" + lineNo + ":\n" + line); } } stamper.close(); } catch (Exception e) { result = "Failed to process!\n" + Utils.throwableToString(e); } finally { FileUtils.closeQuietly(breader); FileUtils.closeQuietly(freader); } return result; }