spire.pdf for java 3.5.1已正式发布。该版本支持pdf签名添加时间戳、设置在pdf页面是否显示签名信息以及绘制箭头、云朵、椭圆、矩形和连接线条形状等标记。另外,也修复了在提取pdf中的文本、将pdf转为图片时出现的一些问题。新功能及问题修复详情如下。
新功能:
- 支持pdf签名添加时间戳
//配置时间戳服务器
string url = "https://freetsa.org/tsr";
signature.configuretimestamp(url);
signature.addshowconfiguretext(signatureconfiguretext.contact_info);//显示contact_info(默认显示所有)
signature.removeshowconfiguretext(signatureconfiguretext.contact_info);//不显示contact_info
signature.setshowconfiguretext(enumset.of(signatureconfiguretext.contact_info));//只显示contact_info
pdfdocument pdf = new pdfdocument();
pdfpagebase page = pdf.getpages().add();
//箭头
string text1 = "this is arrow annotation";
pdffont font = new pdffont(pdffontfamily.helvetica, 20);
pdfsolidbrush brush1 = new pdfsolidbrush(new pdfrgbcolor(color.blue));
pdfstringformat leftalignment = new pdfstringformat(pdftextalignment.left, pdfverticalalignment.middle);
page.getcanvas().drawstring(text1, font, brush1, 50, 50, leftalignment);
dimension2d dimension = font.measurestring(text1);
rectangle2d.float bounds = new rectangle2d.float(50, 50, (float) dimension.getwidth(), (float) dimension.getheight());
int[] linepoints = new int[]{92, (int) (page.getsize().getheight() - bounds.gety() - 60),
(int) (92 bounds.getwidth()), (int) (page.getsize().getheight() - bounds.gety() - 60)};
pdflineannotation annotation1 = new pdflineannotation(linepoints, "linearrow annotation test");
annotation1.setbeginlinestyle(pdflineendingstyle.openarrow);
annotation1.setendlinestyle(pdflineendingstyle.openarrow);
annotation1.setbackcolor(new pdfrgbcolor(color.red));
annotation1.setcaptiontype(pdflinecaptiontype.inline);
annotation1.setlinecaption(true);
((pdfnewpage) page).getannotations().add(annotation1);
//云朵
string text2 = "this is cloud annotation";
pdfbrush brush2 = pdfbrushes.getblue();
page.getcanvas().drawstring(text2, font, brush2, 50, 200);
point2d point2d[] = new point2d[]{
new point2d.float(30, 200),
new point2d.float(300, 180),
new point2d.float(300, 250),
new point2d.float(30, 220),
new point2d.float(30, 200)
};
pdfpolygonannotation annotation2 = new pdfpolygonannotation(page, point2d);
annotation2.settext("polygoncloud annotation test");
annotation2.setauthor("e-iceblue");
annotation2.setsubject("test");
annotation2.setmodifieddate(new date());
annotation2.setbordereffect(pdfbordereffect.big_cloud);
annotation2.setlocation(new point2d.float(190, 230));
annotation2.setcolor(new pdfrgbcolor(color.gray));
((pdfnewpage) page).getannotations().add(annotation2);
//椭圆
string text3 = "this is circle annotation";
pdfbrush brush3 = pdfbrushes.getblue();
dimension2d dimension2d = font.measurestring(text3);
dimension2d.setsize(dimension2d.getwidth() 35, dimension2d.getheight() 20);
page.getcanvas().drawstring(text3, font, brush3, 50, 300);
rectangle2d.float annotationbounds1 = new rectangle2d.float();
annotationbounds1.setframe(new point2d.float(36, (float) 290), dimension2d);
pdfsquareandcircleannotation annotation3 = new pdfsquareandcircleannotation(annotationbounds1);
annotation3.setsubtype(pdfsquareandcircleannotationtype.circle);
float[] f1 = {0.5f, 0.5f, 0.5f, 0.5f};
annotation3.setrectangulardifferencearray(f1);
annotation3.settext("circle annotation test");
annotation3.setcolor(new pdfrgbcolor(color.red));
annotation3.setmodifieddate(new date());
annotation3.setname("*****");
lineborder border1 = new lineborder();
border1.setborderwidth(2);
annotation3.setlineborder(border1);
((pdfnewpage) page).getannotations().add(annotation3);
//矩形
string text4 = "this is square annotation";
pdfbrush brush4 = pdfbrushes.getblue();
dimension2d dimension4 = font.measurestring(text4);
dimension2d.setsize(dimension2d.getwidth() 80, dimension2d.getheight() 20);
page.getcanvas().drawstring(text4, font, brush4, 50, 400);
rectangle2d.float annotationbounds2 = new rectangle2d.float();
annotationbounds2.setframe(new point2d.float(30, (float) 400), dimension4);
pdfsquareandcircleannotation annotation4 = new pdfsquareandcircleannotation(annotationbounds2);
annotation4.setsubtype(pdfsquareandcircleannotationtype.square);
float[] f2 = {0.5f, 0.5f, 0.5f, 0.5f};
annotation4.setrectangulardifferencearray(f2);
annotation4.settext("square annotation test");
annotation4.setcolor(new pdfrgbcolor(color.red));
annotation4.setmodifieddate(new date());
annotation4.setname("*****");
lineborder border2 = new lineborder();
border2.setborderwidth(2);
annotation4.setlineborder(border2);
((pdfnewpage) page).getannotations().add(annotation4);
//连接线
string text5 = "this is connected lines annotation";
pdfbrush brush5 = pdfbrushes.getblue();
page.getcanvas().drawstring(text5, font, brush5, 50, 465);
point2d pointzd[] = new point2d[]{
new point2d.float(30, 470),
new point2d.float(300, 450),
new point2d.float(300, 520),
new point2d.float(30, 490),
new point2d.float(30, 470)
};
pdfpolygonannotation annotation5 = new pdfpolygonannotation(page, pointzd);
annotation5.settext("connected lines annotation test");
annotation5.setauthor("冰蓝");
annotation5.setsubject("test");
annotation5.setmodifieddate(new date());
annotation5.setbordereffect(pdfbordereffect.none);
annotation5.setlocation(new point2d.float(190, 230));
annotation5.setcolor(new pdfrgbcolor(color.gray));
((pdfnewpage) page).getannotations().add(annotation5);
pdf.savetofile("output/annotation.pdf");
for (pdfpagebase page : (iterable) doc.getpages()) {
content.append(page.extracttext(true,true,true));
}
问题修复:
- 修复了提取文本时,空格与源文档不一致的问题
- 修复了设置“setcertificated(true)”不生效的问题
- 修复了提取表格文本时,存在多余的空行的问题
- 修复了调用“dispose()”方法后,“file.delete()”方法无法删除文件的问题
- 优化了pdf转换到图片耗时较长的问题
获取spire.pdf for java 3.5.1,请点击: