Last active
January 1, 2023 17:13
How to Insert Table in PDF using Python. For more details: https://kb.aspose.com/pdf/python/how-to-insert-table-in-pdf-using-python/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import aspose.pdf as pdf | |
# Load License | |
license = pdf.License() | |
license.set_license("Aspose.Total.lic") | |
# Instantiate a new PDF document | |
pdfFile = pdf.Document() | |
# Create a page in the PDF file | |
newPage = pdfFile.pages.add() | |
# Create a table | |
table = pdf.Table() | |
# Set border width | |
table.default_cell_border = pdf.BorderInfo(pdf.BorderSide.ALL, 1.0, pdf.Color.red) | |
for rowNumber in range(5): | |
# Add a row to the table | |
row = table.rows.add() | |
# Add table cells | |
row.cells.add('Column (' + str(rowNumber) + ', 1)') | |
row.cells.add('Column (' + str(rowNumber) + ', 2)') | |
row.cells.add('Column (' + str(rowNumber) + ', 3)') | |
# Add table to the target page | |
newPage.paragraphs.add(table) | |
# Save the PDF on the disk | |
pdfFile.save("PdfTableWithPython.pdf") | |
print("Table in PDF created successfully") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment