How are you creating the portal records? If you are creating them directly in the portal row by entering data into the blank "add" row, simply limit your portal to 22 rows and don't include a scroll bar.
Or you can remove that option, use a script to add the records that first counts the current number of records (with the Count() function) to determine whether to allow this.
But you really shouldn't need to limit the invoice to 22 rows in most circumstances. There are ways to print the typical invoice with related line items from a list view layout based on the portal's table that is not limited to a specific number of portal records.
Records are added with script (attached). If the portal surpasses 22 records the layout would have to run to 2 pages and I want to prevent that. I was hoping the portal would have a facility to cap the number of related records - I guess I'll need to add it my script?
What's your end goal? To only ever allow 22 line items for an invoice? Most people recommend to not print from a portal but to do as Phil says and print from a specific print layout. Here you could use merge fields and sliding to get everything to fit, and right where you want it to display.
But for portal limiting, in your script, you could start with and If statement and check for the count of related records. If it exceeds 21, then you can branch to end the script, or delete a line item and add a new one.
I don't like either options, which is why I initially ask, why only 22 line items?
Yes, a maximum of 22 lines and we do use a PRINT layout. It's at the data entry stage that occasionally someone will not amalgamate some costs and inadvertently create records that are omited from the print. I can add it to the script, just thought a cap would be useful?