Java如何在iText中创建带下划线或删除线的块?
您可以使用Chunk的setUnderline(floatthickness,floatyPosition)方法在下划线上添加下划线或删除线。负值yPosition会产生下划线,而正值会产生删除线。
package org.nhooo.example.itextpdf;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfWriter;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
public class UnderlineStrikeThroughDemo {
public static void main(String[] args) {
Document doc = new Document();
try {
PdfWriter.getInstance(doc, new FileOutputStream("UnderStrike.pdf"));
doc.open();
//用0.1厚度的下划线创建一个块
Chunk underline = new Chunk("The quick brown fox ");
underline.setUnderline(0.1f, -1f);
doc.add(underline);
//创建厚度为1的穿墙大块
Chunk strike = new Chunk("jumps over the lazy dog.");
strike.setUnderline(1f, 3f);
doc.add(strike);
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
} finally {
doc.close();
}
}
}Maven依赖
<!-- http://repo1.maven.org/maven2/com/itextpdf/itextpdf/5.5.10/itextpdf-5.5.10.jar -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短