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;
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations