Szpadel/chrome-headless-render-pdf

Screen resolution at 800x600

Closed this issue · 5 comments

gief commented

The 800x600 screen resolution is a restriction on how the page prints to pdf for a number of sites.
Can we either hard-code a larger screen resolution or pass on a variable to fix this?

Example:
chrome-headless-render-pdf --url https://www.whatismyscreenresolution.com/ --no-margins --pdf screen.pdf
Result: 800x600

Request:
(a) hardcoded screen resolution at a larger standard size.

Line 332: of index.js would simply add '--window-size=1600,1280' to the array of parameters for chromeExec. The danger, of course, is that this would change the rendering for scripts that depend on the 800x600 resolution.

(b) flag for screen resolution
I believe this would require:

  1. Adding arguments to argv (cli/chrome-headless-render-pdf.js:27)
    string: ['url','pdf','chrome-binary','window-size'],
  2. Parsing out width and height
    var [x,y] = "window-size".split(',');
  3. Applying x and y to the call to chromeExec (assuming this is uniform across execs)
    "--window-size="+x+","+y
gief commented

I've tested the hardcoded solution above, and it does return 1600x1200 on the screen resolution site.

option b) with adding window-size conditionally, seams to be good solution

Does this affects visual rendering?
I think this only changes variables available through javascript, and it isn't affecting actual rendering resolution.

gief commented

Some CSS rules depend on the window size to change the rendering. A big one is Bootstrap, as can be seen here: https://stackoverflow.com/questions/26628388/twitter-bootstrap-prints-in-xs

Bootstrap features responsive CSS that will detect the window size and resize special "columns" accordingly. So, if a Bootstrap website is printed with a 800x600 resolution, the CSS rules will default to essentially a "mobile-view".

gief commented

FYI, I updated the original comment with proposed code

Resolved by #14