Java如何在iText中创建带下划线或删除线的块?
您可以使用Chunk的setUnderline(float thickness, float yPosition)方法在下划线上添加下划线或删除线。负值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 --><groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.10</version>
</dependency>
以上是 Java如何在iText中创建带下划线或删除线的块? 的全部内容, 来源链接: utcz.com/z/354222.html