Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing from javascript without header and footer: state of the art?

When I print content using javascript, the browser automatically adds header and footer (url/date/pagenr). Currently there seems to be no way to suppress this from the webapp-side.

Css3 might eventually be a solution for it (e.g. with @page, @top-left styles), but currently doesnt seem to work here (winvista chrome 17.0.942.0 / firefox 9.0). When is it supposed to come to the browsers?

Another solution might arise with chrome-browser: With above version the printdlg is not the modal system-printdlg but rendered within the website (there is also a checkbox to disable header+footer). Now that chrome has remade the printdlg, chrome might also provide a api to control printing using javascript?

Are there other solutions on the horizont? It cant be the final state, that to print from the browser with full control pdf- or other plugins are needed.

like image 859
Pl4n3 Avatar asked Nov 22 '11 14:11

Pl4n3


People also ask

How do I Print without header and footer in HTML?

Google Chrome: Go to the Menu icon in the top right corner of the browser and Click on Print button. Uncheck the “Headers and footers” option underneath the “Margins” option. Apple Safari: Go to the print option from the menu and the Print dialog appears. Uncheck the “Print headers and footers” option.

How do I Print a PDF without the header and footer?

Remove all headers and footers Open the PDF file containing header and footer. Then choose Tools > Edit PDF > Header & Footer > Remove. To remove headers and footers from multiple PDFs, close any open documents and choose Tools > Edit PDF > Header & Footer > Remove.


2 Answers

Do this:

@page {
   margin: 0;
}

Done!

like image 140
CarbonDry Avatar answered Oct 12 '22 10:10

CarbonDry


Currently, Javascript is very limited to accessing resources "outside the browser" like hardware and the file system for security reasons. Hinting from this trend, I doubt programmatically controlling how prints come out will be in Javascript's future. I say this because having those headers and footers (despite how ugly they are) should still ultimately be the user's decision.

Even with CSS3, you are still talking about reaching content outside of the HTML document itself. Those headers and footers are set by internal browser functions. However, Chrome does create an easy UI to get rid of them when printing.

However, especially with Chrome, there is a lot of power in their extensions, especially if you use NDAPI plugins (though this just poses another security risk). This route is very technical, but could probably be "another solution."

like image 38
Mark Avatar answered Oct 12 '22 10:10

Mark