-1

I need to insert tabular data into an existing pdf at a particular position(an x,y position). How can I implement it? Which Python pdf library is best for the use case? Table format data should be formattable like bold, coloring, etc.

akhil viswam
  • 496
  • 9
  • 24

1 Answers1

0

This is easy in PyMuPDF: First define a table with n columns and m rows. Then use page.insert_textbox() to insert text with automatic text wrapping for each of the defined table cells.

import fitz  # import package PyMuPDF
doc=fitz.open(...)  # open new or existing PDF
page = doc.new_page()  # make a new page
# or load an existing page:
# page = doc[pno]  # load page number "pno"
cells = fitz.make_table(rect, cols=n, rows=m)  # define a m x n table
for i in range(m):
    for j in range(m):  # put text in cell(i, j)
        page.insert_textbox(cells[i][j], "some text", font=..., fontsize=...)

Hope this helps.

Jorj McKie
  • 2,062
  • 1
  • 13
  • 17