I am creating a script to export an attribute table in pdf format with PyQGIS 3. The number of features is different regarding the farmer.

pdf_table = QgsLayoutItemAttributeTable.create(layout)
pdf_table.setMaximumNumberOfFeatures(250) # maximum number of features expected
frame2 = QgsLayoutFrame(layout, pdf_table)
frame2.attemptResize(QgsLayoutSize(198.200, 224),True)
frame2.attemptMove(QgsLayoutPoint(9.334, 31.071, QgsUnitTypes.LayoutMillimeters))
pdf_table.setResizeMode(1) # activate the extension of attribute table to the next page
#if the number of lines exceed the heigth defined

I would like to set the position of the attribute table extended in the next pages. Here is an example with an attribute table extended on one other page, but it can goes until 5 pages.

enter image description here

EDIT An attribute table frame is created for each extension of the attribute table, so I need to get the reference of the extended ones and apply new parameters.

enter image description here

So I think it should be something like that :

for f in range(1, pdf_table.frameCount()): #start from 2nd page to the total number of sub-frames
    nextFrame = pdf_table.frame(f) #refers to the frame at index f
    nextFrame.attemptResize(QgsLayoutSize(198.200, 250),True)
    nextFrame.attemptMove(QgsLayoutPoint(9, 15), page=f)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.