Exporting an html string to pdf with css formatting


I want to export an html string I have to pdf in my electron app. Is it a good idea to render the html at a different localhost port using the http-server provided by node (from the main process) and have electron access the html at that port in a new browser window and then call electron’s inbuilt pdf printing function. Does this seem like a good idea? Is there any way to prevent the user from accessing the localhost port in a browser or something? Thanks!