Search in sources :

Example 1 with BaseColor

use of com.itextpdf.text.BaseColor in project gephi by gephi.

the class PDFExporter method execute.

@Override
public boolean execute() {
    Progress.start(progress);
    PreviewController controller = Lookup.getDefault().lookup(PreviewController.class);
    controller.getModel(workspace).getProperties().putValue(PreviewProperty.VISIBILITY_RATIO, 1.0);
    controller.refreshPreview(workspace);
    PreviewProperties props = controller.getModel(workspace).getProperties();
    Rectangle size = new Rectangle(pageSize);
    if (landscape) {
        size = new Rectangle(pageSize.rotate());
    }
    Color col = props.getColorValue(PreviewProperty.BACKGROUND_COLOR);
    size.setBackgroundColor(new BaseColor(col.getRed(), col.getGreen(), col.getBlue()));
    Document document = new Document(size);
    PdfWriter pdfWriter = null;
    try {
        pdfWriter = PdfWriter.getInstance(document, stream);
        pdfWriter.setPdfVersion(PdfWriter.PDF_VERSION_1_5);
        pdfWriter.setFullCompression();
    } catch (DocumentException ex) {
        Exceptions.printStackTrace(ex);
    }
    document.open();
    PdfContentByte cb = pdfWriter.getDirectContent();
    cb.saveState();
    props.putValue(PDFTarget.LANDSCAPE, landscape);
    props.putValue(PDFTarget.PAGESIZE, size);
    props.putValue(PDFTarget.MARGIN_TOP, new Float((float) marginTop));
    props.putValue(PDFTarget.MARGIN_LEFT, new Float((float) marginLeft));
    props.putValue(PDFTarget.MARGIN_BOTTOM, new Float((float) marginBottom));
    props.putValue(PDFTarget.MARGIN_RIGHT, new Float((float) marginRight));
    props.putValue(PDFTarget.PDF_CONTENT_BYTE, cb);
    target = (PDFTarget) controller.getRenderTarget(RenderTarget.PDF_TARGET, workspace);
    if (target instanceof LongTask) {
        ((LongTask) target).setProgressTicket(progress);
    }
    try {
        controller.render(target, workspace);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    cb.restoreState();
    document.close();
    Progress.finish(progress);
    props.putValue(PDFTarget.PDF_CONTENT_BYTE, null);
    props.putValue(PDFTarget.PAGESIZE, null);
    return !cancel;
}
Also used : PreviewProperties(org.gephi.preview.api.PreviewProperties) PdfWriter(com.itextpdf.text.pdf.PdfWriter) Color(java.awt.Color) BaseColor(com.itextpdf.text.BaseColor) Rectangle(com.itextpdf.text.Rectangle) Document(com.itextpdf.text.Document) PreviewController(org.gephi.preview.api.PreviewController) DocumentException(com.itextpdf.text.DocumentException) BaseColor(com.itextpdf.text.BaseColor) LongTask(org.gephi.utils.longtask.spi.LongTask) DocumentException(com.itextpdf.text.DocumentException) PdfContentByte(com.itextpdf.text.pdf.PdfContentByte)

Example 2 with BaseColor

use of com.itextpdf.text.BaseColor in project summer-bean by cn-cerc.

the class InvoiceTemplate method output.

@Override
public void output(Document document, PdfWriter writer) throws DocumentException, IOException {
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 设置中文字体和字体样式
    Font f8 = new Font(bfChinese, 8, Font.NORMAL);
    Font f18 = new Font(bfChinese, 18, Font.NORMAL);
    document.addTitle(this.getFileName());
    // 页标题
    Paragraph title = new Paragraph(this.getFileName(), f18);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);
    // 空一行
    document.add(new Paragraph(" ", f18));
    // 创建一个N列的表格控件
    PdfPTable pdfTable = new PdfPTable(2);
    // 设置报表为无边框
    pdfTable.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
    // 设置表格占PDF文档100%宽度
    pdfTable.setWidthPercentage(100);
    // 水平方向表格控件左对齐
    pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    // 创建一个表格的表头单元格
    PdfPCell pdfTableHeaderCell = new PdfPCell();
    // 设置表格的表头单元格颜色
    pdfTableHeaderCell.setBackgroundColor(new BaseColor(240, 240, 240));
    pdfTableHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    // 设置表头栏位
    pdfTableHeaderCell.setPhrase(new Paragraph("名称", f8));
    pdfTable.addCell(pdfTableHeaderCell);
    pdfTableHeaderCell.setPhrase(new Paragraph("信息", f8));
    pdfTable.addCell(pdfTableHeaderCell);
    // 创建一个表格的正文内容单元格
    PdfPCell pdfTableContentCell_1 = new PdfPCell();
    pdfTableContentCell_1.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell_1.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    PdfPCell pdfTableContentCell_2 = new PdfPCell();
    pdfTableContentCell_2.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell_2.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    // 表格内容行数的填充
    dataSet.first();
    while (dataSet.fetch()) {
        Record record = dataSet.getCurrent();
        for (Column column : this.getColumns()) {
            pdfTableContentCell_1.setPhrase(new Phrase(column.getName(), f8));
            pdfTable.addCell(pdfTableContentCell_1);
            String field = column.getCode();
            pdfTableContentCell_2.setPhrase(new Paragraph(record.getString(field), f8));
            pdfTable.addCell(pdfTableContentCell_2);
        }
    }
    document.add(pdfTable);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) BaseColor(com.itextpdf.text.BaseColor) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Column(cn.cerc.jexport.excel.Column) BaseFont(com.itextpdf.text.pdf.BaseFont) Record(cn.cerc.jdb.core.Record) Phrase(com.itextpdf.text.Phrase) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Paragraph(com.itextpdf.text.Paragraph)

Example 3 with BaseColor

use of com.itextpdf.text.BaseColor in project summer-bean by cn-cerc.

the class Template method output.

public void output(Document document, PdfWriter writer) throws DocumentException, IOException {
    BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
    // 设置中文字体和字体样式
    Font f8 = new Font(bfChinese, 8, Font.NORMAL);
    Font f18 = new Font(bfChinese, 18, Font.NORMAL);
    document.addTitle(this.getFileName());
    // 页标题
    Paragraph title = new Paragraph(this.getFileName(), f18);
    title.setAlignment(Element.ALIGN_CENTER);
    document.add(title);
    // 空一行
    document.add(new Paragraph(" ", f18));
    // 创建一个N列的表格控件
    PdfPTable pdfTable = new PdfPTable(this.getColumns().size());
    // 设置表格占PDF文档100%宽度
    pdfTable.setWidthPercentage(100);
    // 水平方向表格控件左对齐
    pdfTable.setHorizontalAlignment(PdfPTable.ALIGN_LEFT);
    // 创建一个表格的表头单元格
    PdfPCell pdfTableHeaderCell = new PdfPCell();
    // 设置表格的表头单元格颜色
    pdfTableHeaderCell.setBackgroundColor(new BaseColor(240, 240, 240));
    pdfTableHeaderCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    for (Column column : this.getColumns()) {
        Paragraph item = new Paragraph(column.getName(), f8);
        pdfTableHeaderCell.setPhrase(item);
        pdfTable.addCell(pdfTableHeaderCell);
    }
    // 创建一个表格的正文内容单元格
    PdfPCell pdfTableContentCell = new PdfPCell();
    pdfTableContentCell.setHorizontalAlignment(PdfPCell.ALIGN_CENTER);
    pdfTableContentCell.setVerticalAlignment(PdfPCell.ALIGN_MIDDLE);
    // 表格内容行数的填充
    dataSet.first();
    while (dataSet.fetch()) {
        Record record = dataSet.getCurrent();
        for (Column column : this.getColumns()) {
            String field = column.getCode();
            pdfTableContentCell.setPhrase(new Paragraph(record.getString(field), f8));
            pdfTable.addCell(pdfTableContentCell);
        }
    }
    document.add(pdfTable);
// //将表格添加到新的文档
// doc.add(table);
// //创建新的一页
// doc.newPage();
// //添加图片
// Image image = Image.getInstance(
// "https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo/bd_logo1_31bdc765.png");
// //添加到文档
// doc.add(image);
// //设置对象方式
// image.setAlignment(Element.ALIGN_CENTER);
}
Also used : PdfPCell(com.itextpdf.text.pdf.PdfPCell) BaseColor(com.itextpdf.text.BaseColor) PdfPTable(com.itextpdf.text.pdf.PdfPTable) Column(cn.cerc.jexport.excel.Column) BaseFont(com.itextpdf.text.pdf.BaseFont) Record(cn.cerc.jdb.core.Record) Font(com.itextpdf.text.Font) BaseFont(com.itextpdf.text.pdf.BaseFont) Paragraph(com.itextpdf.text.Paragraph)

Example 4 with BaseColor

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

the class OrganizationReportPdfCommand 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 5 with BaseColor

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

the class Pdf method convert.

/* M e t h o d s */
public void convert(File pdfOut, float fontSize, boolean append) throws IOException, DocumentException, InvalidColourException {
    // First we write to tmp file then we copy to given destination, possibly appending
    File tmpPdf = Utils.createTempFile(pdfOut.getName(), ".pdf");
    tmpPdf.deleteOnExit();
    List<Paragraph> pdfLines = this.ansiFileToPdfParagraphs(fontSize);
    Rectangle pageSize = new Rectangle((float) (this.getMaxWidth() * 1.01), (float) (this.getMaxHeight()));
    int background256 = Config.get256Color(ConfigKey.background);
    Color pageColor = Xterm256.xterm256ToColor(background256);
    pageSize.setBackgroundColor(new BaseColor(pageColor.getRed(), pageColor.getGreen(), pageColor.getBlue()));
    Document document = new Document(pageSize, 5f, 0f, 0f, 0f);
    // Document document = new Document(new Rectangle((float) (this.getMaxWidth() * 1.01), (float) (this.getMaxHeight())), 5f, 0f, 0f, 0f);
    PdfWriter.getInstance(document, new FileOutputStream(tmpPdf));
    document.open();
    for (Paragraph line : pdfLines) {
        document.add(line);
    }
    document.close();
    if (append) {
        this.appendPdf(tmpPdf, pdfOut);
    } else {
        Files.move(Paths.get(tmpPdf.getAbsolutePath()), Paths.get(pdfOut.getAbsolutePath()), StandardCopyOption.REPLACE_EXISTING);
    }
}
Also used : BaseColor(com.itextpdf.text.BaseColor) Color(java.awt.Color) BaseColor(com.itextpdf.text.BaseColor) FileOutputStream(java.io.FileOutputStream) Rectangle(com.itextpdf.text.Rectangle) Document(com.itextpdf.text.Document) File(java.io.File) Paragraph(com.itextpdf.text.Paragraph)

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