CSS page break left/right - css

Does anyone know of a tool out there that previews #page CSS rules? Failing that, is there something out there that I could use to print a document with full support for these rules?
http://www.w3.org/TR/CSS2/page.html
Opera comes closest. It supports everything except for the left/right page breaks (treats them as always) but still requires you to print to something to see them (can't see a live print preview).

Displaying Print preview
In Opera 12.16 (and all version prior to it, but unfortuntely not in Opera 16+), you can press Control + Shift + P to display Print preview, which will use print CSS media to display the page. If, for any reason, this shortcut does not work for you, you need to add it to keyboard shortcuts:
Open Opera Preferences (Control + F12)
Switch to Advanced tab → Shortcuts
Click Edit… button on the right side of Keyboard Setup part
Click New
Fill in "p ctrl shift" in first column (Input context and shortcuts) and "Print preview" in second (Actions)
OK, OK, refresh the page and try it now ;-)
Using #page CSS rules
… should be simple, everything works just fine in Opera (again, only 12.16-). Just remember to put #page CSS rules in #media print section of stylesheet, like this:
#media print {
#page {
margin: 0.7cm 0.85cm;
}
#page :first {
margin-top: 5cm;
}
#page :left {
margin-right: 2.5cm;
}
#page :right {
margin-left: 2.5cm;
}
}
I'm using these few rules to style my documents for better printing (notice extra margin on inner sides of pages, leaving space for binding). Hope it helps!

Related

How do I disable ChromeVox UI when printing?

The ChromeVox extension for Google Chrome browser places an orange outline around content when selected on the screen.
This orange outline is also printed when printing a web page. See how button below is selected with orange outline and then also appears on print preview.
How do I disable this orange focus ring when printing?
Solved it with print css media-queries!
The ChromeVox injects markup and styles into the body of the page that looks like this:
<div aria-hidden="true" class="cvox_indicator_container ...more classes...">
...more html markup...
</div>
So I updated my global CSS stylesheet to include the following:
#media print {
.cvox_indicator_container {
display: none;
}
}
Which worked great.
Then I got to thinking that I wanted to make sure this never changed even if ChromeVox changed their css to have greater specificity.
Then, I updated the css to:
#media print {
html body div.cvox_indicator_container {
display: none !important;
}
}
Note: This may be overkill, but certainly has more specificity.
Ideally the ChomeVox team would add something like this solution to their code. I tried to find their open-source repo… got close but failed. Halp?

Chrome does not support the css #page?

I have css for print as simple as this:
#page {
#top-left {
content: "TOP SECRET";
color: red
}
#bottom-center {
content: counter(page);
font-style: italic
}
}
But the Chrome print preview and save to pdf seems not to recognize this at all. How can I correctly set the header and footer when priting?
EDIT: #page is supported by none ref
However, do I have other choice to do this. I'm not working on websites. The product wants a pdf as result only. I can accept chrome, webkit, plantomjs etc.
You can use the open tool PagedJS to render iframes or whole pages using the CSS paged-media spec. https://pagedjs.org/
This tool is a polyfill that converts blocks like the one you posted (CSS Paged Media that isn't implemented by browsers) into browser-compliant html/css.
It also has a CLI alternative that sets up puppeteer & creates PDF outputs: https://gitlab.coko.foundation/pagedjs/pagedjs-cli
Near as I can determine, CSS features for paged media are primarily for systems that render for printing, rather than systems that render for the screen (browsers) or the print feature of browsers. An example of an HTML/CSS engine for printing is Prince. So, #page won't work in a browser, nor (as far as I know) was it intended to.

Using print css, image added before:body not showing in Internet Explorer 8

I am using a separate print css on our website. It's been requested that we have our logo at the top of printed pages. This is the code I'm using for print.css:
body:before {
content: url(../images/logo.gif);
}
This works on Firefox, Chrome, Safari and Opera ... and of course you know what's coming next.
It doesn't work in Internet Explorer 8 which apparently supports before as a pseudo-class: http://www.quirksmode.org/css/beforeafter_content.html
In print preview there is a blank space the same size as the logo but our logo doesn't print. If I change the code to:
content: "Test Text" url(../images/logo.gif);
The "Test Text" shows, but still not the logo.
Does anyone have any ideas? It's made very difficult that I can't debug off "print preview" and simply changing the media type on the CSS links renders something completely different in the browser screen.
Cheers
Tama
You can't print background images by default. Users need to change their browser settings to print background colours and images.
Your best bet is to add some HTML like this:
<div class="PrintOnly">
<img id="PrintLogo" src="logo.gif"/>
</div>
Styling something like this to explicitly hide from non-print media configurations:
.PrintOnly { display:none; }
#media print {
.PrintOnly { display:block; }
}

Print Background colours in Chrome

I am trying to print a PHP generated document in chrome, on the browser it looks fine Link to the page I want to print But my printer will not print any coloured backgrounds, can anyone offer any suggestions please? Can I do this with CSS?
You adjust in the browser, whether the background colors and images are printed. See your browsers printing options.
Google Chrome offers this feature starting from version 26 (march 2013).
Also starting from version 17, Chrome allows changing the background print behavior programmatically by using -webkit-print-color-adjust:exact; in the element CSS to print the background.
Gordon's answer is great, but for people whose CSS skills are rusty, here's a more complete example.
Put the following in your document's <head> section.
<style type="text/css">
#media print { body { -webkit-print-color-adjust: exact; } }
</style>
By the way, although Chrome/Chromium's print dialog now has a Background graphics checkbox, it only seems to work if you do not click Print using system dialog (observed with Chromium in Linux).
Chrome > Print (cmd P) > click More Settings > Options: check Background graphics

Can I remove the URL from my print css, so the web address doesn't print?

I have written some stylesheets - including a print.css - and it's working fine.
I'd like to remove the URL from printing out on each of the pages. I am beginning to wonder if it is impossible. Is there an element/option that I can set to display:none to do this?
The reason is that the specific pages that have a 'normal' and 'print' stylesheet have been specially formatted so when printed, it forms a meaningful booklet. Therefore the URL is irrelevant.
In Firefox, https://bug743252.bugzilla.mozilla.org/attachment.cgi?id=714383 (view page source :: tag HTML).
In your code, replace <html> with <html moznomarginboxes mozdisallowselectionprint>.
In others browsers, I don't know, but you can view http://www.mintprintables.com/print-tips/header-footer-windows/
Sadly, no. The header and footer are generated by the browser. Only the end-user can change the footer - it might be an idea to give the user a step-by-step for each browser what to do. See for example here for a set of illustrated walk-throughs for windows based browsers.
The only alternative I know of is generating PDFs, with which you have full control over the printed output.
Use that code.that will help to solve your problem
#media print
{
#page { margin: 0; }
body { margin: 1.6cm; }
}
#media print
{
a[href]:after { content: none !important; }
img[src]:after { content: none !important; }
}
you can try this in the stylesheet:
#page{size:auto; margin-bottom:5mm;}
But this also removes the page number
This solution will do the trick in Chrome and Opera by setting margin to 0 in a css #page directive. It will not (currently) work for other browsers though...
It depends on your web browser. If you're using Firefox you can adjust or turn off those header and footer lines (URL, page number, etc) by going into File > Page Setup then clicking the Margins & Header/Footer tab.
If I understand you correctly, you talk about the page headers and footers. They are printed by the browser. They are not part of your HTML content, so you can't influence them directly.
Show your users how to disable headers and footers in the «Page setup...» dialog.
The headers and footers for printing from browsers is, sadly, a browser preference, not a document-level element that you can style. Refer to my very similar question for further workarounds and disappointment.
Historically, it's been impossible to make these things disappear as they are user settings and not considered part of the page you have control over.
http://css-discuss.incutio.com/wiki/Print_Stylesheets#Print_headers.2Ffooters_and_print_margins
However, as of 2017, the #page at-rule has been standardized, which can be used to hide the page title and date in modern browsers:
#page { size: auto; margin: 0mm; }
Credit to Vigneswaran S for this tip.
Remove the url from header and footer using below method
#page { size: letter; margin-top: 4mm;margin-bottom: 4mm }
I've also tried everything but finally I'm writing below code to make URL shorter:
var curURL = window.location.href;
history.replaceState(history.state, '', '/');
window.print();
history.replaceState(history.state, '', curURL);
But you need to make a custom PRINT button for user to click.
Now we can do this with:
<style type="text/css" media="print">
#page {
size: auto; /* auto is the initial value */
margin: 0; /* this affects the margin in the printer settings */
}
</style>
Source: https://stackoverflow.com/a/14975912/1760939
I assume that you are talking about the URL that shows in the footer of the page.
If so, this is set by the browser and it is not something that you can do from your code.
I am not sure but the URL is added by a browser when you want to print. It is not part of the page so can not be affected by CSS. Maybe there is a way but it will be browser dependent.
i found something in the browser side itself.
Try this steps. here i have been mentioned the Steps to disable the Header and footer in all the three major browsers.
Chrome Click the Menu icon in the top right corner of the browser. Click Print. Uncheck Headers and Footers under the Options section.
Firefox Click Firefox in the top left corner of the browser. Place your mouse over Print, the click Page Setup. Click the Margins & Header/Footer tab. Change each value under Headers & Footers to --blank--.
Internet Explorer Click the Gear icon in the top right corner of the browser. Place your mouse over Print, then click Page Setup. Change each value under Headers and Footers to -Empty-.
This is a browser issue. But you can handle this problem by these line of codes:
<style type="text/css" media="print">
#media print
{
#page {
margin-top: 0;
margin-bottom: 0;
}
body {
padding-top: 72px;
padding-bottom: 72px ;
}
}
</style>
For Internet Explorer, go to Tools. Click on the print option and then page set up. Under headers and Footer, make all the choices "empty". Then it will not print out on your printed pages.
I hope this helps.

Resources