/*
package com.com.itext.day3;
*/
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2018 iText Group NV
Authors: iText Software.
For more information, please contact iText Software at this address:
sales@itextpdf.com
*//*
*/
/*
* This example is part of the iText 7 tutorial.
*//*
import com.itextpdf.io.font.FontRegisterProvider;
import com.itextpdf.kernel.color.Color;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.color.DeviceCmyk;
import com.itextpdf.kernel.events.Event;
import com.itextpdf.kernel.events.IEventHandler;
import com.itextpdf.kernel.events.PdfDocumentEvent;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.geom.Rectangle;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.Canvas;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.border.SolidBorder;
import com.itextpdf.layout.element.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.property.Property;
import com.itextpdf.layout.property.TextAlignment;
import com.itextpdf.layout.property.UnitValue;
import com.itextpdf.layout.property.VerticalAlignment;
import com.itextpdf.test.annotations.WrapToTest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.StringTokenizer;
*/
/**
* Simple event handler example.
*//*
@WrapToTest
public class C03E03_UFO {
public static final String DATA = "src/main/resources/data/ufo.csv";
public static final String DEST = "results/chapter03/ufo.pdf";
static PdfFont helvetica = null;
static PdfFont helveticaBold = null;
public static void main(String[] args) throws Exception {
helvetica = PdfFontFactory.createFont(StandardFonts.HELVETICA);
helveticaBold = PdfFontFactory.createFont(StandardFonts.HELVETICA_BOLD);
File file = new File(DEST);
file.getParentFile().mkdirs();
new C03E03_UFO().createPdf(DEST);
}
protected void createPdf(String dest) throws Exception {
//Initialize PDF document
PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
pdf.addEventHandler(PdfDocumentEvent.END_PAGE, new MyEventHandler());
// Initialize document
Document document = new Document(pdf);
Paragraph p = new Paragraph("List of reported UFO sightings in 20th century")
.setTextAlignment(TextAlignment.CENTER).setFont(helveticaBold).setFontSize(14);
document.add(p);
Table table = new Table(UnitValue.createPercentArray(new float[]{3, 5, 7, 4}));
BufferedReader br = new BufferedReader(new FileReader(DATA));
String line = br.readLine();
process(table, line, helveticaBold, true);
while ((line = br.readLine()) != null) {
process(table, line, helvetica, false);
}
br.close();
document.add(table);
document.close();
}
public void process(Table table, String line, PdfFont font, boolean isHeader) {
StringTokenizer tokenizer = new StringTokenizer(line, ";");
while (tokenizer.hasMoreTokens()) {
if (isHeader) {
table.addHeaderCell(new Cell().add(new Paragraph(tokenizer.nextToken()).setFont(font)).setFontSize(9).setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f)));
} else {
table.addCell(new Cell().add(new Paragraph(tokenizer.nextToken()).setFont(font)).setFontSize(9).setBorder(new SolidBorder(ColorConstants.BLACK, 0.5f)));
}
}
}
protected class MyEventHandler implements IEventHandler {
public void handleEvent(Event event) {
PdfDocumentEvent docEvent = (PdfDocumentEvent) event;
PdfDocument pdfDoc = docEvent.getDocument();
PdfPage page = docEvent.getPage();
int pageNumber = pdfDoc.getPageNumber(page);
Rectangle pageSize = page.getPageSize();
PdfCanvas pdfCanvas = new PdfCanvas(page.newContentStreamBefore(), page.getResources(), pdfDoc);
//Set background
Color limeColor = new DeviceCmyk(0.208f, 0, 0.584f, 0);
Color blueColor = new DeviceCmyk(0.445f, 0.0546f, 0, 0.0667f);
pdfCanvas.saveState()
.setFillColor(pageNumber % 2 == 1 ? limeColor : blueColor)
.rectangle(pageSize.getLeft(), pageSize.getBottom(), pageSize.getWidth(), pageSize.getHeight())
.fill().restoreState();
//Add header and footer
pdfCanvas.beginText()
.setFontAndSize(helvetica, 9)
.moveText(pageSize.getWidth() / 2 - 60, pageSize.getTop() - 20)
.showText("THE TRUTH IS OUT THERE")
.moveText(60, -pageSize.getTop() + 30)
.showText(String.valueOf(pageNumber))
.endText();
//Add watermark
Canvas canvas = new Canvas(pdfCanvas, pdfDoc, page.getPageSize());
canvas.setFontColor(ColorConstants.WHITE);
canvas.setProperty(Property.FONT_SIZE, UnitValue.createPointValue(60));
canvas.setProperty(Property.FONT, helveticaBold);
canvas.showTextAligned(new Paragraph("CONFIDENTIAL"), 298, 421, pdfDoc.getPageNumber(page),
TextAlignment.CENTER, VerticalAlignment.MIDDLE, 45);
pdfCanvas.release();
}
}
}*/
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
Java和itext7实现的pdf文件签章 (194个子文件)
C06E06_88th_Oscar_Combine_AddTOC.class 7KB
SignPDF.class 6KB
demo3.class 6KB
demo1.class 5KB
C06E08_FillOutAndMergeForms.class 4KB
C05E03_AddContent.class 4KB
C05E01_AddAnnotationsAndContent.class 4KB
C06E09_FillOutFlattenAndMergeForms.class 4KB
C05E02_FillAndModifyForm.class 3KB
demo2.class 3KB
C06E01_TheGoldenGateBridge_Scale_Shrink.class 3KB
C06E02_TheGoldenGateBridge_Tiles.class 3KB
C06E03_TheGoldenGateBridge_N_up.class 3KB
demo1.class 3KB
C05E04_ChangePage.class 2KB
C06E05_88th_Oscar_CombineXofY.class 2KB
C06E07_Combine_Forms.class 2KB
C06E04_88th_Oscar_Combine.class 2KB
freemaker.iml 9KB
itext7.iml 3KB
xxx.java 6KB
PloanpapaerlessController.java 6KB
demo3.java 5KB
SignPDF.java 5KB
C03E02_PremierLeague.java 5KB
C06E06_88th_Oscar_Combine_AddTOC.java 5KB
demo4.java 5KB
C03E01_NewYorkTimes.java 5KB
PloanParam.java 4KB
C02E01_Axes.java 4KB
C02E01_Axes.java 4KB
demo1.java 4KB
C02E04_StarWarsCrawl.java 4KB
C02E04_StarWarsCrawl.java 4KB
C06E08_FillOutAndMergeForms.java 3KB
WordUtils.java 3KB
docUtil.java 3KB
WordUtil.java 3KB
C06E09_FillOutFlattenAndMergeForms.java 3KB
C05E03_AddContent.java 3KB
C06E02_TheGoldenGateBridge_Tiles.java 3KB
C05E01_AddAnnotationsAndContent.java 3KB
C02E02_GridLines.java 3KB
C02E02_GridLines.java 3KB
C02E03_StarWars.java 3KB
C02E03_StarWars.java 3KB
C06E01_TheGoldenGateBridge_Scale_Shrink.java 2KB
C05E02_FillAndModifyForm.java 2KB
controller.java 2KB
demo1.java 2KB
demo2.java 2KB
C06E03_TheGoldenGateBridge_N_up.java 2KB
pdfUtil.java 2KB
demo2.java 2KB
C05E04_ChangePage.java 2KB
demo2.java 2KB
demo1.java 2KB
C06E05_88th_Oscar_CombineXofY.java 2KB
C06E04_88th_Oscar_Combine.java 1KB
C06E07_Combine_Forms.java 1KB
demo3.java 1KB
demo1.java 1KB
demo3.java 929B
demo5.java 907B
index.jsp 57B
index.jsp 57B
inputFiles.lst 231B
createdFiles.lst 0B
workspace.xml 47KB
uiDesigner.xml 9KB
pom.xml 9KB
pom.xml 6KB
compiler.xml 851B
Maven__org_springframework_boot_spring_boot_test_autoconfigure_1_5_6_RELEASE.xml 769B
Maven__org_springframework_boot_spring_boot_starter_logging_1_5_6_RELEASE.xml 748B
Maven__org_springframework_boot_spring_boot_starter_tomcat_1_5_6_RELEASE.xml 741B
Maven__org_springframework_boot_spring_boot_autoconfigure_1_5_6_RELEASE.xml 734B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_autoconfigure_1_3_0.xml 730B
Maven__com_fasterxml_jackson_module_jackson_module_parameter_names_2_8_9.xml 729B
Maven__org_springframework_boot_spring_boot_starter_test_1_5_6_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_jdbc_1_5_6_RELEASE.xml 727B
Maven__org_springframework_boot_spring_boot_starter_web_1_5_6_RELEASE.xml 720B
Maven__com_vaadin_external_google_android_json_0_0_20131108_vaadin1.xml 700B
Maven__org_springframework_boot_spring_boot_starter_1_5_6_RELEASE.xml 692B
Maven__org_mybatis_spring_boot_mybatis_spring_boot_starter_1_3_0.xml 688B
Maven__com_fasterxml_jackson_datatype_jackson_datatype_joda_2_8_9.xml 674B
Maven__org_springframework_boot_spring_boot_test_1_5_6_RELEASE.xml 671B
Maven__org_springframework_spring_expression_4_3_10_RELEASE.xml 665B
Maven__org_apache_tomcat_embed_tomcat_embed_websocket_8_5_16.xml 660B
Maven__org_springframework_spring_expression_3_0_7_RELEASE.xml 658B
Maven__org_springframework_spring_context_4_3_10_RELEASE.xml 644B
Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml 644B
Maven__org_springframework_spring_context_3_0_7_RELEASE.xml 637B
Maven__org_springframework_spring_webmvc_4_3_10_RELEASE.xml 637B
Maven__org_springframework_boot_spring_boot_1_5_6_RELEASE.xml 636B
Maven__org_hibernate_hibernate_validator_5_3_5_Final.xml 634B
Maven__org_springframework_spring_beans_4_3_10_RELEASE.xml 630B
modules.xml 627B
Maven__org_apache_tomcat_embed_tomcat_embed_core_8_5_16.xml 625B
Maven__com_fasterxml_jackson_core_jackson_databind_2_8_9.xml 623B
共 194 条
- 1
- 2
资源评论
全粘架构师
- 粉丝: 232
- 资源: 24
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 数控车床基本操作.pdf
- 数控机床基础知识.ppt
- 数控卧式车床的维护和保养.pdf
- 数控卧式车床机械结构-晋磊.pdf
- 卧式加工中心机械结构-2003.pdf
- nginx安装包 可以部署前端服务
- 立加操作编程-SIEMENS.zip
- Individual assignment.ipynb
- 剪板伺服送料机,程序,三菱,昆仑通态,送料机程序,PLC多段数据不同,可任意调节A段B段c段长度,并定长切断 程序能存储5段工件数据,使用调出非常方便 PLC程序有台达和三菱FX ,触摸屏程序有昆
- 100KV无功动态补偿箱3D零件库.zip
- 按钮开关及指示灯3D零件库.zip
- 钣金常用外购件零件库3D零件库.zip
- 文件柜3D零件库.zip
- 钣金五金库3D零件库.zip
- 吊具设备控制机柜3D零件库.zip
- 文件柜手推式3D零件库.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功