How can I script the process of making a PDF for each value in a filter?

I have a spreadsheet with a “location” column. I’d like to generate a PDF for each location, with the PDF compiling every row that has that as the location. That’s something that seems really easy to describe, but I can’t find any good resources on scripting this. I’ve tried using “Record Macro”, but it doesn’t seem to capture when I change the value in the filter.

This are documented:
For access to range: https://wiki.documentfoundation.org/Macros/Basic/Calc/Ranges
For read data: https://wiki.documentfoundation.org/Macros/Basic/Calc/Data
For export to PDF: https://wiki.documentfoundation.org/Macros/Basic/Documents#Export_to_PDF