use of com.itextpdf.text.Paragraph 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.Paragraph 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.Paragraph in project summer-bean by cn-cerc.
the class BarcodeDemo2 method createPdf.
public void createPdf(String filename) throws IOException, DocumentException {
BaseFont bf = null;
Font fontChinese = null;
try {
// 使用iTextAsian.jar中的字体
bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
// 使用Windows系统字体(TrueType)
// BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF",
// BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
// 使用资源字体(ClassPath)
// BaseFont.createFont("/SIMYOU.TTF",
// BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
fontChinese = new Font(bf, 12, Font.NORMAL);
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
// step 1
Document document = new Document(new Rectangle(340, 842));
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(filename));
// step 3
document.open();
// step 4
PdfContentByte cb = writer.getDirectContent();
document.add(new Paragraph("各类条码生成范例:", fontChinese));
// EAN 13
document.add(new Paragraph("Barcode EAN.UCC-13"));
BarcodeEAN codeEAN = new BarcodeEAN();
codeEAN.setCode("4512345678906");
document.add(new Paragraph("default:"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setGuardBars(false);
document.add(new Paragraph("without guard bars"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBaseline(-1f);
codeEAN.setGuardBars(true);
document.add(new Paragraph("text above:"));
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBaseline(codeEAN.getSize());
// UPC A
document.add(new Paragraph("Barcode UCC-12 (UPC-A)"));
codeEAN.setCodeType(Barcode.UPCA);
codeEAN.setCode("785342304749");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// EAN 8
document.add(new Paragraph("Barcode EAN.UCC-8"));
codeEAN.setCodeType(Barcode.EAN8);
codeEAN.setBarHeight(codeEAN.getSize() * 1.5f);
codeEAN.setCode("34569870");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
// UPC E
document.add(new Paragraph("Barcode UPC-E"));
codeEAN.setCodeType(Barcode.UPCE);
codeEAN.setCode("03456781");
document.add(codeEAN.createImageWithBarcode(cb, null, null));
codeEAN.setBarHeight(codeEAN.getSize() * 3f);
// EANSUPP
document.add(new Paragraph("Bookland"));
document.add(new Paragraph("ISBN 0-321-30474-8"));
codeEAN.setCodeType(Barcode.EAN13);
codeEAN.setCode("9781935182610");
BarcodeEAN codeSUPP = new BarcodeEAN();
codeSUPP.setCodeType(Barcode.SUPP5);
codeSUPP.setCode("55999");
codeSUPP.setBaseline(-2);
BarcodeEANSUPP eanSupp = new BarcodeEANSUPP(codeEAN, codeSUPP);
document.add(eanSupp.createImageWithBarcode(cb, null, BaseColor.BLUE));
// CODE 128
document.add(new Paragraph("Barcode 128"));
Barcode128 code128 = new Barcode128();
code128.setCode("0123456789 hello");
document.add(code128.createImageWithBarcode(cb, null, null));
code128.setCode("0123456789\uffffMy Raw Barcode (0 - 9)");
code128.setCodeType(Barcode.CODE128_RAW);
document.add(code128.createImageWithBarcode(cb, null, null));
// Data for the barcode :
String code402 = "24132399420058289";
String code90 = "3700000050";
String code421 = "422356";
StringBuffer data = new StringBuffer(code402);
data.append(Barcode128.FNC1);
data.append(code90);
data.append(Barcode128.FNC1);
data.append(code421);
Barcode128 shipBarCode = new Barcode128();
shipBarCode.setX(0.75f);
shipBarCode.setN(1.5f);
shipBarCode.setSize(10f);
shipBarCode.setTextAlignment(Element.ALIGN_CENTER);
shipBarCode.setBaseline(10f);
shipBarCode.setBarHeight(50f);
shipBarCode.setCode(data.toString());
document.add(shipBarCode.createImageWithBarcode(cb, BaseColor.BLACK, BaseColor.BLUE));
// it is composed of 3 blocks whith AI 01, 3101 and 10
Barcode128 uccEan128 = new Barcode128();
uccEan128.setCodeType(Barcode.CODE128_UCC);
uccEan128.setCode("(01)00000090311314(10)ABC123(15)060916");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));
uccEan128.setCode("0191234567890121310100035510ABC123");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.RED));
uccEan128.setCode("(01)28880123456788");
document.add(uccEan128.createImageWithBarcode(cb, BaseColor.BLUE, BaseColor.BLACK));
// INTER25
document.add(new Paragraph("Barcode Interleaved 2 of 5"));
BarcodeInter25 code25 = new BarcodeInter25();
code25.setGenerateChecksum(true);
code25.setCode("41-1200076041-001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("411200076041001");
document.add(code25.createImageWithBarcode(cb, null, null));
code25.setCode("0611012345678");
code25.setChecksumText(true);
document.add(code25.createImageWithBarcode(cb, null, null));
// POSTNET
document.add(new Paragraph("Barcode Postnet"));
BarcodePostnet codePost = new BarcodePostnet();
document.add(new Paragraph("ZIP"));
codePost.setCode("01234");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4"));
codePost.setCode("012345678");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("ZIP+4 and dp"));
codePost.setCode("01234567890");
document.add(codePost.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode Planet"));
BarcodePostnet codePlanet = new BarcodePostnet();
codePlanet.setCode("01234567890");
codePlanet.setCodeType(Barcode.PLANET);
document.add(codePlanet.createImageWithBarcode(cb, null, null));
// CODE 39
document.add(new Paragraph("Barcode 3 of 9"));
Barcode39 code39 = new Barcode39();
code39.setCode("ITEXT IN ACTION");
document.add(code39.createImageWithBarcode(cb, null, null));
document.add(new Paragraph("Barcode 3 of 9 extended"));
Barcode39 code39ext = new Barcode39();
code39ext.setCode("iText in Action");
code39ext.setStartStopText(false);
code39ext.setExtended(true);
document.add(code39ext.createImageWithBarcode(cb, null, null));
// CODABAR
document.add(new Paragraph("Codabar"));
BarcodeCodabar codabar = new BarcodeCodabar();
codabar.setCode("A123A");
codabar.setStartStopText(true);
document.add(codabar.createImageWithBarcode(cb, null, null));
// PDF417
document.add(new Paragraph("Barcode PDF417"));
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "Call me Ishmael. Some years ago--never mind how long " + "precisely --having little or no money in my purse, and nothing " + "particular to interest me on shore, I thought I would sail about " + "a little and see the watery part of the world.";
pdf417.setText(text);
Image img = pdf417.getImage();
img.scalePercent(50, 50 * pdf417.getYHeight());
document.add(img);
document.add(new Paragraph("Barcode Datamatrix"));
BarcodeDatamatrix datamatrix = new BarcodeDatamatrix();
datamatrix.generate(text);
img = datamatrix.createImage();
document.add(img);
document.add(new Paragraph("Barcode QRCode"));
BarcodeQRCode qrcode = new BarcodeQRCode("http://www.mimrc.com", 1, 1, null);
img = qrcode.getImage();
document.add(img);
// step 5
document.close();
}
use of com.itextpdf.text.Paragraph 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);
}
}
use of com.itextpdf.text.Paragraph in project specify by rhebecaabreu.
the class CartaoEstoria method criaPDF.
public void criaPDF(JTable table_1, java.util.List<Integer> codigosReq) throws FileNotFoundException, DocumentException {
Document document = new Document();
try {
document.setPageSize(PageSize.A4);
document.setMargins(50, 50, 50, 50);
nomepdf = MeusProjetos.getNome_pdf() + ".pdf";
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(nomepdf));
ModelPDFRodape mf = new ModelPDFRodape();
mf.setTopo("Specify");
writer.setPageEvent(mf);
document.open();
DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date date = new Date();
String data = dateFormat.format(date);
RequisitoDAO rdao = new RequisitoDAO();
Font f = FontFactory.getFont(FontFactory.HELVETICA, 13, Font.NORMAL);
Font ff = FontFactory.getFont(FontFactory.HELVETICA, 13, Font.BOLD);
Paragraph title2 = new Paragraph("Cartões de Estória", FontFactory.getFont(FontFactory.HELVETICA, 18, Font.BOLD));
title2.setAlignment(Element.ALIGN_CENTER);
Chapter chapter2 = new Chapter(title2, 2);
chapter2.setNumberDepth(0);
ProjetoDAO pread = new ProjetoDAO();
for (Requisito r : rdao.readOrderBy()) {
for (Projeto p : pread.read()) {
for (int i = 0; i < codigosReq.size(); i++) {
if (r.getProjcodigo() == p.getCodigo() && r.getCodigo() == codigosReq.get(0)) {
Paragraph title_project2 = new Paragraph("Projeto: " + p.getNome(), FontFactory.getFont(FontFactory.HELVETICA, 16, Font.BOLD));
title_project2.setAlignment(Element.ALIGN_CENTER);
chapter2.add(title_project2);
break;
}
}
}
}
Paragraph data_hora2 = new Paragraph("Gerado em " + data, FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL));
data_hora2.setAlignment(Element.ALIGN_CENTER);
chapter2.add(data_hora2);
Paragraph listUserStories = new Paragraph("Lista de Cartões de Estória", FontFactory.getFont(FontFactory.HELVETICA, 14, Font.NORMAL));
Section section2 = chapter2.addSection(listUserStories);
for (Requisito r : rdao.readOrderBy()) {
if (table_1.getSelectedRow() != -1) {
for (int j = 0; j < (codigosReq.size()); j++) {
if (r.getCodigo() == codigosReq.get(j)) {
Paragraph p = new Paragraph();
Paragraph q = new Paragraph();
Paragraph rr = new Paragraph();
Paragraph s = new Paragraph();
Paragraph t = new Paragraph();
p.setFont(ff);
p.add("Identificador: ");
p.setFont(f);
p.add(r.getId());
p.setFont(ff);
p.add(" Código: ");
p.setFont(f);
p.add(String.valueOf(r.getCodigo()));
q.setFont(ff);
q.add("Como um " + r.getSujeito() + " eu quero " + r.getAcaoRestricao() + " a fim de " + r.getValorRazao());
Paragraph qq = new Paragraph();
qq.setFont(ff);
qq.add("Estimativa: ");
qq.setFont(f);
qq.add(r.getEstimativa() + " hora(s)");
rr.setFont(ff);
rr.add("Grau Prioridade: ");
rr.setFont(f);
rr.add(r.getGrauPrioridade().toString());
s.setFont(ff);
s.add("Grau Dificuldade: ");
s.setFont(f);
s.add(r.getGrauDificuldade().toString());
t = new Paragraph(" ");
section2.add(p);
section2.add(q);
section2.add(rr);
section2.add(s);
section2.add(t);
}
}
}
}
document.add(chapter2);
document.add(Chunk.NEXTPAGE);
} catch (DocumentException ex) {
System.out.println("Error:" + ex);
} catch (FileNotFoundException ex) {
System.out.println("Error:" + ex);
} finally {
document.close();
}
try {
Desktop.getDesktop().open(new File(nomepdf));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Aggregations