这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Image;
import com.itextpdf.text.Phrase;
import com.itextpdf.text.pdf.PdfPCell;
Expand All @@ -29,6 +30,13 @@ public static void main(String[] args) {

document.open();

Document documentParagraph = new Document();
PdfWriter.getInstance(documentParagraph, new FileOutputStream("iTextParagraph.pdf"));

documentParagraph.open();

addParagraphInCenter(documentParagraph);

PdfPTable table = new PdfPTable(3);
addTableHeader(table);
setAbsoluteColumnWidths(table);
Expand All @@ -45,6 +53,12 @@ public static void main(String[] args) {
}
}

private static void addParagraphInCenter(Document document) throws IOException, DocumentException {
Paragraph paragraph = new Paragraph("This paragraph will be horizontally centered.");
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
}

private static void addTableHeader(PdfPTable table) {
Stream.of("column header 1", "column header 2", "column header 3")
.forEach(columnTitle -> {
Expand Down