Finding solution for converting html code to text-based PDF

So basically i need to convert my html code to a pdf file using js or java

I have been trying out several tools and came across one called html2pdf, which works well for dynamically converting CSS and HTML files. However, the main issue is that html2pdf currently converts HTML to an image and then pushes it to a PDF file. This results in a PDF file that cannot be searched or copied. Since we can’t change the fact that html2pdf turns HTML into an image, I am looking for a new tool that can convert HTML and CSS to PDF using Java or JavaScript.