Skip to content

Instantly share code, notes, and snippets.

@bbrown
Last active March 2, 2016 21:30
Show Gist options
  • Save bbrown/49037176976e5d8cad11 to your computer and use it in GitHub Desktop.
Save bbrown/49037176976e5d8cad11 to your computer and use it in GitHub Desktop.
Angular directive that sets the page's orientation to landscape for printing
angular.module("app").directive("setPrintToLandscape", function($document)
{
return {
restrict: "AE",
link: function link(scope)
{
// Currently only supported in Chrome.
// FF - https://bugzilla.mozilla.org/show_bug.cgi?id=851441
// Safari - https://bugs.webkit.org/show_bug.cgi?id=63575
var newSheet = angular.element("<style/>").attr({ "type":"text/css", "media":"print" });
newSheet[0].appendChild(document.createTextNode(""));
$document.find("head").append(newSheet);
newSheet[0].sheet.insertRule("@page { size:landscape }", 0);
scope.$on("$destroy", function()
{
newSheet.remove();
});
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment