9

I want to print an HTML page the way it is, without any additional content such as URL and date.

Some people told me that you cannot do it using CSS/JavaScript because those additional stuff are from the browser/printer.

The user who will print the page is using the server machine. The browser will be the interface and PHP can be used in conjunction to print.

What would be the best way to do it?

user937450
  • 713
  • 5
  • 11
  • 20
  • 1
    What do you mean by "machine printing page is server itself"? Is the server doing the printing not printing the page via a browser? – Charlie Gorichanaz Apr 10 '13 at 00:07
  • If you are referring to the information that gets printed in the header and footer of the document, then yes, those are generated by the browser or the printer (print settings). Are you referring to something else? Are you using a browser to print? – Revent Apr 10 '13 at 00:09
  • I think in CSS3 there are features for this. But never tested. I had the problem once too I couldn't solve it – hek2mgl Apr 10 '13 at 00:10
  • @Charlie Gorichanaz The user is opening the page via browser on the server machine. That means that if its possible to do what i want server-side it will work too. – user937450 Apr 10 '13 at 00:10
  • See this answer for some ideas, but generally you want to do this via the browser's print settings. http://stackoverflow.com/a/2780518/172602 – Charlie Gorichanaz Apr 10 '13 at 00:14
  • From what I can tell, you are trying to print it without the header/footer information that most browsers add to it. For firefox, you can remove it by going to "File->Page Setup->Margins & Header/Footer' and disable what you don't want to print with it. – Jon Apr 10 '13 at 00:25

3 Answers3

10

The URL, date, and page title, and other information that are often printed in the header and/or footer are controlled by the web browser. Unfortunately, you cannot control these via CSS or HTML. It is up to the visitor of your site to decide whether or not they want these elements to print.

Users can turn off headers and footers by following the steps below. (Steps may vary based on browser version, or may even be unavailable on older browsers. All steps done in the latest version of each browser.)

Chrome

  1. Click the Menu icon in the top right corner of the browser.
  2. Click Print.
  3. Uncheck Headers and Footers under the Options section.

Firefox

  1. Click Firefox in the top left corner of the browser.
  2. Place your mouse over Print, the click Page Setup.
  3. Click the Margins & Header/Footer tab.
  4. Change each value under Headers & Footers to --blank--.

Internet Explorer

  1. Click the Gear icon in the top right corner of the browser.
  2. Place your mouse over Print, then click Page Setup.
  3. Change each value under Headers and Footers to -Empty-.
Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
4

You can do it including a page media CSS rule in your page:

<style>
  @page {
    size: auto;
    margin: 0;
  }
</style>
ianaya89
  • 4,153
  • 3
  • 26
  • 34
  • 1
    It can be useful to replace `margin: 0;` by `margin-top: 0; margin-bottom:0;` in order to be able to keep the left and right margins. The headers and footers will still not appear. (checked on Firefox 51.0.1) – mauritslamers Apr 20 '17 at 18:53
  • 1
    the best answer ever :) – sina May 19 '21 at 14:46
0

In google chrome you can turn off additional content when you print.

In the options section at the bottom left, turn off "headers and footers".

https://storage.googleapis.com/support-kms-prod/SNP_2703025_en_v0

rafaelcastrocouto
  • 11,781
  • 3
  • 38
  • 63