pnnl / Quality-Install-Tool

BSD 2-Clause "Simplified" License
2 stars 3 forks source link

Fix PDF Styling #112

Closed charliepnnl closed 1 year ago

charliepnnl commented 1 year ago

The problem we have had is that PrintJS is picking up styling for the html element that is calculated based on the html viewport. This leads to some parts of the PDF being squashed to the left of the page.

It appears that a way to overcome this issue is to abandon the idea of getting the styling from the html element itself. Instead, we need to apply the same styling using the css print-js option. Here are the needed options to print-js print function:

css: ['https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css', '/App.css'],
documentTitle: 'DOE - Quality Installation Report',
printable: printContainerId,
scanStyles: false,
type: 'html', 

The scanStyles: false option tells PrintJS to ignore the existing styling on the html element. The bootstrap and App.css styling gets us most of the styling we need – and it is calculated based on the print width, not the html viewport width. However, some issues remain:

charliepnnl commented 1 year ago

@jackcruz53 Another piece of styling that needs to be updated is how we style h1, h2, ...

I suggest looking at how bootstrap handles them and do something similar. I believe bootstrap adjusts their size according to the viewport width, which is a nice touch. There are two aspects that we need to change compared to bootstrap:

charliepnnl commented 1 year ago

@jackcruz53 Since a copy of App.css needs to put placed in the public folder in order for PrintJS to find it, the copy webpack plugin (https://github.com/webpack-contrib/copy-webpack-plugin) should be used to copy App.css to public/print.css.