If you “print” the html how different is is from what you get rendered to PDF? Depending on your automation needs you might want to try “printing” to a PDF. That is save the HTML as a file and then render the HTML to a PDF via a utility program.
There are libraries both JavaScript and Java for HTML to PDF conversion. However almost all of them tend to have a common problem not supporting web components. So they fail pretty easily when you use case is to convert something else than native HTML to PDF.
This usually means that for generating PDF reports you need to build a separate process and not to convert actual UI to PDF. Instead produce separate report file which native HTML and convert that to PDF. Alternatively you could skip the HTML totally by using some library like Apache POI to to produce the report. There are also many fully report generation oriented libraries in Java ecosystem.
Then you need something that is really capable of rendering web component. This pretty much means running Browser command line with shell script. You can do this e.g. with Chrome Headless Chrome to print pdf - Stack Overflow This means that you need to have Chrome and possibly some other software installed in your server. You can execute external command from Java.
Yeah, only problem with that is that its not really performant, since you create a new browser, and I can see this being an issue if there are many concurrent conversions.