101 - a very simple table
A very simple table example.
simpletable
JAVA
JAVA
/*
This file is part of the iText (R) project.
Copyright (c) 1998-2023 Apryse Group NV
Authors: Apryse Software.
For more information, please contact iText Software at this address:
sales@itextpdf.com
*/
package com.itextpdf.samples.sandbox.tables;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.UnitValue;
import java.io.File;
public class SimpleTable {
public static final String DEST = "./target/sandbox/tables/simple_table.pdf";
public static void main(String[] args) throws Exception {
File file = new File(DEST);
file.getParentFile().mkdirs();
new SimpleTable().manipulatePdf(DEST);
}
protected void manipulatePdf(String dest) throws Exception {
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Table table = new Table(UnitValue.createPercentArray(8)).useAllAvailableWidth();
for (int i = 0; i < 16; i++) {
table.addCell("hi");
}
doc.add(table);
doc.close();
}
}
C#
C#
using System;
using System.IO;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
namespace iText.Samples.Sandbox.Tables
{
public class SimpleTable
{
public static readonly string DEST = "results/sandbox/tables/simple_table.pdf";
public static void Main(String[] args)
{
FileInfo file = new FileInfo(DEST);
file.Directory.Create();
new SimpleTable().ManipulatePdf(DEST);
}
private void ManipulatePdf(String dest)
{
PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
Document doc = new Document(pdfDoc);
Table table = new Table(UnitValue.CreatePercentArray(8)).UseAllAvailableWidth();
for (int i = 0; i < 16; i++)
{
table.AddCell("hi");
}
doc.Add(table);
doc.Close();
}
}
}