如何使用Java在PDF中添加列表。(How to add list in a PDF using Java.)
优质
小牛编辑
121浏览
2023-12-01
问题描述 (Problem Description)
如何使用Java在PDF中添加列表。
解决方案 (Solution)
以下是使用Java在PDF中添加列表的程序。
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.List;
import com.itextpdf.layout.element.Paragraph;
public class AddingList {
public static void main(String args[]) throws Exception {
//Creating a PdfWriter
String dest = "C:/itextExamples/addngList.pdf";
PdfWriter writer = new PdfWriter(dest);
//Creating a PdfDocument
PdfDocument pdf = new PdfDocument(writer);
//Creating a Document
Document document = new Document(pdf);
//Creating a Paragraph
Paragraph paragraph = new Paragraph("xnip provides the following tutorials");
//Creating a list
List list = new List();
//Add elements to the list
list.add("Java");
list.add("JavaFX");
list.add("Apache Tika");
list.add("OpenCV");
list.add("WebGL");
list.add("Coffee Script");
list.add("Java RMI");
list.add("Apache Pig");
//Adding paragraph to the document
document.add(paragraph);
//Adding list to the document
document.add(list);
//Closing the document
document.close();
System.out.println("List added");
}
}