Search in sources :

Example 11 with BaseColor

use of com.itextpdf.text.BaseColor in project bamboobsc by billchen198318.

the class PersonalReportPdfCommand method setCellBackgroundColor.

private void setCellBackgroundColor(PdfPCell cell, String color) throws Exception {
    int[] rgb = SimpleUtils.getColorRGB2(color);
    cell.setBackgroundColor(new BaseColor(rgb[0], rgb[1], rgb[2]));
}
Also used : BaseColor(com.itextpdf.text.BaseColor)

Example 12 with BaseColor

use of com.itextpdf.text.BaseColor in project bamboobsc by billchen198318.

the class PersonalReportPdfCommand method getFont.

private Font getFont(String color, boolean bold) throws Exception {
    Font font = FontFactory.getFont(BscConstants.PDF_ITEXT_FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
    int[] rgb = SimpleUtils.getColorRGB2(color);
    BaseColor baseColor = new BaseColor(rgb[0], rgb[1], rgb[2]);
    font.setSize(9);
    font.setColor(baseColor);
    return font;
}
Also used : BaseColor(com.itextpdf.text.BaseColor) BaseFont(com.itextpdf.text.pdf.BaseFont) Font(com.itextpdf.text.Font)

Example 13 with BaseColor

use of com.itextpdf.text.BaseColor in project ASCIIGenome by dariober.

the class Pdf method ansiFileToPdfParagraphs.

/**
 * Read ansi formatted file line by lone and convert each line to
 * a iText paragraph.
 * @throws IOException
 * @throws InvalidColourException
 */
private List<Paragraph> ansiFileToPdfParagraphs(float fontSize) throws IOException, InvalidColourException {
    List<Paragraph> paraList = new ArrayList<Paragraph>();
    // Files.readAllBytes(Paths.get(this.ansiInput.toURI()));
    byte[] encoded = this.ansiInput.getBytes();
    String str = new String(encoded);
    // Each string in this list is a sequence of a characters sharing the same formatting.
    List<String> ansiList = Splitter.on("\033").splitToList(str);
    Paragraph pdfLine = new Paragraph();
    int nChars = 0;
    int currentMax = 0;
    for (String xv : ansiList) {
        // if(xv.equals("[48;5;231m")){
        // continue;
        // }
        BaseColor fgBaseCol = new BaseColor(this.xterm256ToColor(xv, false).getRGB());
        BaseColor bgBaseCol = new BaseColor(this.xterm256ToColor(xv, true).getRGB());
        if (this.extractAnsiCodes(xv).size() != 0) {
            // This string begins with ansi sequence and the color has been extracted.
            // So remove the ansi sequence at the beginnig and the end, we don't need them anymore
            xv = xv.replaceAll("^.+?m", "");
        }
        for (int i = 0; i < xv.length(); i++) {
            char c = xv.charAt(i);
            nChars += 1;
            Chunk chunk = new Chunk(c, new Font(Font.FontFamily.COURIER, fontSize, Font.NORMAL, fgBaseCol));
            chunk.setBackground(bgBaseCol);
            pdfLine.add(chunk);
            if (c == '\n') {
                // Newline found: Start a new parapgrah
                paraList.add(pdfLine);
                if (nChars > currentMax) {
                    currentMax = nChars;
                }
                nChars = 0;
                pdfLine = new Paragraph();
            }
        }
    }
    Font f = new Font(Font.FontFamily.COURIER, fontSize);
    Chunk chunk = new Chunk("X", f);
    this.setMaxWidth((int) ((currentMax) * chunk.getWidthPoint()));
    for (Paragraph p : paraList) {
        p.setSpacingBefore(-3);
        p.setSpacingAfter(-3);
    }
    this.setMaxHeight((int) Math.rint((paraList.size() + 1) * fontSize));
    return paraList;
}
Also used : BaseColor(com.itextpdf.text.BaseColor) ArrayList(java.util.ArrayList) Chunk(com.itextpdf.text.Chunk) Font(com.itextpdf.text.Font) Paragraph(com.itextpdf.text.Paragraph)

Example 14 with BaseColor

use of com.itextpdf.text.BaseColor in project ASCIIGenome by dariober.

the class Pdf method xterm256ToColor.

/**
 * Parse the string x to get the colour for foreground or background.
 * If the inout string doesn't contain the escape sequence for fore or back ground,
 * use the colour from Config.
 * This method should be private. It is protected only for unit test.
 */
protected Color xterm256ToColor(String x, boolean isBackground) throws InvalidColourException {
    List<Integer> ansiCodes = this.extractAnsiCodes(x);
    Color configBg = Xterm256.xterm256ToColor(Config.get256Color(ConfigKey.background));
    Color configFg = Xterm256.xterm256ToColor(Config.get256Color(ConfigKey.foreground));
    // BaseColor bgBaseCol= new BaseColor(configBg.getRed(), configBg.getGreen(), configBg.getBlue());
    Color col = null;
    int xtag = -1;
    if (isBackground) {
        // Color.WHITE; // Default background
        col = configBg;
        xtag = Collections.indexOfSubList(ansiCodes, Arrays.asList(new Integer[] { 48, 5 }));
    } else {
        // Color.BLACK; // Default foreground
        col = configFg;
        xtag = Collections.indexOfSubList(ansiCodes, Arrays.asList(new Integer[] { 38, 5 }));
    }
    if (xtag != -1 && ansiCodes.size() > 2) {
        col = Xterm256.xterm256ToColor(ansiCodes.get(xtag + 2));
    }
    return col;
}
Also used : Color(java.awt.Color) BaseColor(com.itextpdf.text.BaseColor)

Example 15 with BaseColor

use of com.itextpdf.text.BaseColor in project saga by timurstrekalov.

the class PdfReporter method addFileStatsRows.

private void addFileStatsRows(final TestRunCoverageStatistics runStats, final PdfPTable table) {
    final List<ScriptCoverageStatistics> allFileStats = runStats.getFileStats();
    for (int i = 0; i < allFileStats.size(); i++) {
        final ScriptCoverageStatistics scriptCoverageStatistics = allFileStats.get(i);
        final boolean hasStatements = scriptCoverageStatistics.getHasStatements();
        final Phrase fileName = new Phrase();
        if (scriptCoverageStatistics.getParentName() != null) {
            fileName.add(new Chunk(scriptCoverageStatistics.getParentName() + "/", hasStatements ? FONT_TD : FONT_TD_EMPTY_FILE));
            fileName.add(new Chunk(scriptCoverageStatistics.getFileName(), hasStatements ? FONT_TD_BOLD : FONT_TD_BOLD_EMPTY_FILE));
        } else {
            fileName.add(new Chunk(scriptCoverageStatistics.getFileName(), hasStatements ? FONT_TD : FONT_TD_EMPTY_FILE));
        }
        final BaseColor bgColor = (i % 2 == 1) ? COLOR_ROW_ODD : COLOR_ROW_EVEN;
        final Font font = FONT_TD;
        table.addCell(createCell(fileName, 0, bgColor));
        table.addCell(createCell(String.valueOf(scriptCoverageStatistics.getStatements()), font, 1, bgColor));
        table.addCell(createCell(String.valueOf(scriptCoverageStatistics.getExecuted()), font, 2, bgColor));
        table.addCell(createCell(scriptCoverageStatistics.getCoverage() + "%", FONT_TD, 3, bgColor));
    }
}
Also used : BaseColor(com.itextpdf.text.BaseColor) Phrase(com.itextpdf.text.Phrase) Chunk(com.itextpdf.text.Chunk) Font(com.itextpdf.text.Font) ScriptCoverageStatistics(com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)

Aggregations

BaseColor (com.itextpdf.text.BaseColor)15 Font (com.itextpdf.text.Font)8 BaseFont (com.itextpdf.text.pdf.BaseFont)5 Paragraph (com.itextpdf.text.Paragraph)4 Chunk (com.itextpdf.text.Chunk)3 Phrase (com.itextpdf.text.Phrase)3 PdfPCell (com.itextpdf.text.pdf.PdfPCell)3 PdfPTable (com.itextpdf.text.pdf.PdfPTable)3 Color (java.awt.Color)3 Record (cn.cerc.jdb.core.Record)2 Column (cn.cerc.jexport.excel.Column)2 Document (com.itextpdf.text.Document)2 DocumentException (com.itextpdf.text.DocumentException)2 Rectangle (com.itextpdf.text.Rectangle)2 PdfContentByte (com.itextpdf.text.pdf.PdfContentByte)2 ScriptCoverageStatistics (com.github.timurstrekalov.saga.core.model.ScriptCoverageStatistics)1 BadElementException (com.itextpdf.text.BadElementException)1 Image (com.itextpdf.text.Image)1 PdfWriter (com.itextpdf.text.pdf.PdfWriter)1 CustomTag (eu.transkribus.core.model.beans.customtags.CustomTag)1