New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 740522 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Jul 2017
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: ----
Type: ----



Sign in to add a comment

headless: Support printing PDFs in screen mode.

Reported by daudmali...@gmail.com, Jul 10 2017

Issue description

until the latest version of chrome 59 , when we convert loaded page to pdf using flag --print-to-pdf
it converts the page to pdf and look like as the print function available in chrome gui
,
but i think it would be more better to convert loaded page to pdf as it can be seen on chrome browser regardless of @media print css of put some flag e.g --print-to-pdf-real

as they have implemented in wkhtmltopdf http://wkhtmltopdf.org/

Thanks & Best Regards
 
Components: -Admin>LabelRequest Internals>Headless
Status: Available (was: Untriaged)
Summary: headless: Support printing PDFs in screen mode. (was: chrome headless proper pdf)
If I understand correctly, you would like to render a PDF in CSS media screen mode, rather than print mode?
sorry for some typos ,
yeah you understood more o less,

actually i want to render a pdf regardless of CSS media,
it should be rendered as we can see it in chrome gui .


example :: there are html pages with css with media=print queries and when chrome render that html
that ignores those print queries because it's in screen mode and when we use ctrl+p(print) it render that page using CSS media=print queries .
 


so i want if it's possible to just ignore those print queries and always use screen queries 
like how chrome render html to display on screen

that pdf functionality would be doing exactly same.
is that possible or any future hope for this ?

was i able to make you understand ?

Thanks & Best Regards


Cc: thestig@chromium.org jzfeng@chromium.org zoeclifford@chromium.org
Yeah, I think I understand. Not sure if it's easily to add. thestig@ may know if there's currently a way to generate a PDF in screen mode.
alright let's wait for his reply
Thanks :)
Alternatively one could take screenshots of the page as PNG and then convert those screenshots to PDF.
@paulir yeah this will be my move if that option is not available ,
but it will be really nice if there is such option , like

--print-to-pdf --media=screen

of whatever media user wants
what do you guys think ?
As I understand it there are a couple benefits to printing to PDF over converting PNGs to PDF:

* Links work and text can be highlighted (I haven't tested, but this may also mean the file size is smaller)
* Paginated layout avoids stuff getting spliced across pages (which is actually bad if you want to 100% reproduce how Chromium shows stuff on a screen; but generally a good thing for decent looking paginated media)


yeah in-fact there are some benefits .
If you want to do this, I would recommend writing a (or installing a pre-existing) Chrome extension to manipulate the page and take away the print CSS.
really cool solution thanks a lot ,
so any suggestion for extension or anyway how to change loaded css using chrome headless without debugging mode .?
FYI, headless doesn't support chrome extensions, so any style removing would have to be done via devtools.
thanks for your solution it really works ,
anyway i've found this solution(see attachment) using gui chrome , so any idea how to achieve the same using cli ?


smaluate.PNG
23.9 KB View Download
Oh, that's great :) That must be Emulation.setEmulatedMedia:

https://chromedevtools.github.io/devtools-protocol/tot/Emulation/#method-setEmulatedMedia
cool , but unfortunately i have no idea how to use this option using 
chrome --headless ,
 which is what i want to do? any idea?
Status: WontFix (was: Available)
You'll have to use DevTools to issue this command. Run headless with --remote-debugging-port=9222 and connect to the websocket. See the blog post [1] for more info on how to use DevTools with headless.

[1] https://developers.google.com/web/updates/2017/04/headless-chrome
yeah i understood  thanks, but problem is there are some cases where we can't open ports , so in that case ?
Sorry, but you'll have to use the devtools protocol. I'm afraid we're not adding command line options for print options, as we previously discussed in  bug 603559 .
If that's not an option for you, you could consider embedding headless chrome in your application, see the readme for details about that [1].

[1] https://cs.chromium.org/chromium/src/headless/README.md?type=cs&q=headless/readme&sq=package:chromium&l=57
yeah i read those comments ,:( unfortunately we have no way to use DevTools using command line options , any future hope for this ???
okay let me check that 
thanks, i checked it thoroughly , 
well i am noob to chromium is there any documentation / tutorial available to compile/build this stuff ?

For building, see chromium developer docs... http://www.chromium.org/developers/

There aren't any plans to add command line options to --headless for this. Our primary API provided to developers is DevTools, not the command line. See also  bug 719921 .
alright , thanks a lot all of you
i built chromium successfully using following steps http://www.zackarychapple.guru/chrome/2016/08/24/chrome-headless.html

any idea or tip how can i enable these DevTools only for this headless version ?

Thanks
https://developers.google.com/web/updates/2017/04/headless-chrome will get you started
See the "Using programmatically (Node)" section. You'll likely use chrome-remote-interface. This will require some development and unfortunately we can't help you further as it's out of scope for us.

Good luck!
alright thanks :)

Sign in to add a comment