So I know that PDF files can contain viruses themselves if they are target specifically for that purpose. However, my question for here is this: If a webpage that has some malicious scripts or a virus is converted into a PDF using one of the popular programmatic html to pdf conversion libraries (eg. in nodejs or python), and a user opens that PDF, is there any chance at all that the PDF itself is infected as well?
Although it's possible to a specially crafted HTML page crash the library, perhaps executing code because of this, it would not reflect on the resulting PDF file. Depending on the attack, it would not even generate any file.
But I don't think anyone would create a crafted page attack a library in a way that generated a crafted PDF to attack your PDF reader.
is there any chance at all that the file is infected?
Whenever you ask that is there any chance, almost always the answer will be Yes, it can be infected. Those chances could be infinitesimal, but a contrived enough scenario would likely find a way for it to be infected.
I assume you want to sanitize untrusted web pages in an sandbox enviroment, which are then moved to a "trusted" system which is itself isolated from the internet (otherwise, the malicious web page could simply contain a link to the real malicious page, with the pdf just keeping it¹).
It would be quite hard that a malicious page converts into a malicious pdf. I don't think such html→pdf conversion library would insert scripts in the pdf or invalid data that would result in an escape from the pdf reader.
Rather than finding a pdf exploit that can be expressed in a way that survives conversion from html, it would be easier to get an exploit for the html to pdf converter. After owning the converter process, it'd be trivial to make it output any arbitrary content.
So yes, it would be possible, at the cost of obtaining that second exploit.
A more secure approach would be to convert it to a safer format. You could convert it to an image, having another process validate that it is indeed a valid image, You can see this idea on the blog post Converting untrusted PDFs into trusted ones: The Qubes Way by Joanna Rutkowska. It was dealing with converting untrusted pdf to trusted pdf, but it is applicable as well to your case of html to pdf. They go so far to convert it into rgb values, in order to remove any vulnerabilities on the image decompressor as well.
Of course, that is of no help for PEBKAC exploits, where the user would be tricked by the web page content to e.g. send an email with their password to the attacker.
¹ Plus, typically, you would have the exploit on the first stage, but it actually being a dropper which downloads the next one from the internet. While it might be possible to bundle everything together on a single file, it's uncommon.