This article demonstrates how to add various types of lists to PDF using the PdfListApi interface provided by Spire.Cloud.PDF.
import spire.cloud.pdf.sdk.ApiException;
import spire.cloud.pdf.sdk.Configuration;
import spire.cloud.pdf.sdk.api.PdfListApi;
import spire.cloud.pdf.sdk.model.Font;
import spire.cloud.pdf.sdk.model.List;
import java.util.ArrayList;
public class AddList {
static String appId = "APP ID";
static String appKey = "APP Key";
static String baseUrl= "https://api.cloudxdocs.com";
//Create a Configuration instance based on your AppID and AppKey
static Configuration configuration = new Configuration(appId, appKey, baseUrl);
//Create a PdfListApi instance
static PdfListApi pdfListApi = new PdfListApi(configuration);
public static void main(String[]args) throws ApiException {
//Specify the input PDF document
String name = "AddList.pdf";
//Specify the file path of the output document
String outPath = "/PdfList/AddList.pdf";
//Specify the number of the page that you want to add lists to
int pageNumber = 1;
//Specify the password used to open the document, and it's "null" if nothing
String password = null;
//Specify the folder storing the input document, and it's "null" if nothing
String folder = "input";
//Use the 2G storage provided by E-iceblue, and it's "null" by default
String storage = null;
//Create an ArrayList of list type to add the lists created below
ArrayList<List> lists = new ArrayList<List>();
//Create a Font
Font font = new Font();
font.setFontType(Font.FontTypeEnum.STANDARD);
font.setFontFamily("Helvetica");
font.setFontSize(12f);
font.setFontStyle(Font.FontStyleEnum.BOLD);
//Create an ArrayList of String type for the text value of lists created below
ArrayList<String> strList1 = new ArrayList<String>();
strList1.add("123");
strList1.add("456");
strList1.add("789");
strList1.add("000");
//Create a sorted list with UPPERROMAN number style
spire.cloud.pdf.sdk.model.List list1 = new spire.cloud.pdf.sdk.model.List();
list1.setX(50f);
list1.setY(50f);
list1.setWidth(null);
list1.setHeight(null);
list1.setType(List.TypeEnum.SORTED);
list1.setText(strList1);
list1.setIndent(0f);
list1.setTextIndent(0f);
list1.setFont(font);
list1.setNumberStyle(List.NumberStyleEnum.UPPERROMAN);
list1.setStartNumber(null);
//Create a sorted list with UPPERLATIN number style
spire.cloud.pdf.sdk.model.List list2 = new spire.cloud.pdf.sdk.model.List();
list2.setX(50f);
list2.setY(200f);
list2.setWidth(100f);
list2.setHeight(100f);
list2.setType(List.TypeEnum.SORTED);
list2.setText(strList1);
list2.setIndent(5f);
list2.setTextIndent(5f);
list2.setFont(font);
list2.setNumberStyle(List.NumberStyleEnum.UPPERLATIN);
list2.setStartNumber(3);
//Create a sorted list with LOWERROMAN number style
spire.cloud.pdf.sdk.model.List list3 = new spire.cloud.pdf.sdk.model.List();
list3.setX(50f);
list3.setY(300f);
list3.setWidth(100f);
list3.setHeight(100f);
list3.setType(List.TypeEnum.SORTED);
list3.setText(strList1);
list3.setIndent(5f);
list3.setTextIndent(5f);
list3.setFont(font);
list3.setNumberStyle(List.NumberStyleEnum.LOWERROMAN);
list3.setStartNumber(3);
//Create a sorted list with NUMERIC number style
spire.cloud.pdf.sdk.model.List list4 = new spire.cloud.pdf.sdk.model.List();
list4.setX(50f);
list4.setY(400f);
list4.setWidth(100f);
list4.setHeight(100f);
list4.setType(List.TypeEnum.SORTED);
list4.setText(strList1);
list4.setIndent(5f);
list4.setTextIndent(5f);
list4.setFont(font);
list4.setNumberStyle(List.NumberStyleEnum.NUMERIC);
list4.setStartNumber(3);
//Create a sorted list with no number style
spire.cloud.pdf.sdk.model.List list5 = new spire.cloud.pdf.sdk.model.List();
list5.setX(50f);
list5.setY(520f);
list5.setWidth(100f);
list5.setHeight(100f);
list5.setType(List.TypeEnum.SORTED);
list5.setText(strList1);
list5.setIndent(5f);
list5.setTextIndent(5f);
list5.setFont(font);
list5.setNumberStyle(List.NumberStyleEnum.NONE);
list5.setStartNumber(3);
//Create an ArrayList of String type for the text value of lists created below
ArrayList<String> strList2 = new ArrayList<String>();
strList2.add("147");
strList2.add("258");
strList2.add("369");
strList2.add("000");
//Create an unsorted list with no number style
spire.cloud.pdf.sdk.model.List list6 = new spire.cloud.pdf.sdk.model.List();
list6.setX(350f);
list6.setY(50f);
list6.setWidth(null);
list6.setHeight(null);
list6.setType(List.TypeEnum.UNSORTED);
list6.setText(strList2);
list6.setIndent(0f);
list6.setTextIndent(0f);
list6.setFont(font);
list6.setNumberStyle(null);
list6.setStartNumber(null);
//Create an unsorted list with LOWERLATIN number style
spire.cloud.pdf.sdk.model.List list7 = new spire.cloud.pdf.sdk.model.List();
list7.setX(350f);
list7.setY(200f);
list7.setWidth(100f);
list7.setHeight(100f);
list7.setType(List.TypeEnum.UNSORTED);
list7.setText(strList2);
list7.setIndent(5f);
list7.setTextIndent(5f);
list7.setFont(font);
list7.setNumberStyle(List.NumberStyleEnum.LOWERLATIN);
list7.setStartNumber(3);
//Add the lists to the ArrayList
lists.add(list1);
lists.add(list2);
lists.add(list3);
lists.add(list4);
lists.add(list5);
lists.add(list6);
lists.add(list7);
//Call addList method to add the ArrayList to PDF and save to a speicified path
pdfListApi.addList(name, outPath, pageNumber, lists, folder, storage, password);
}
}
Output: