Skip to content

Instantly share code, notes, and snippets.

@yaxinr
Last active April 17, 2019 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yaxinr/ceb32f3a332eb3de7830cc5e8f422d3b to your computer and use it in GitHub Desktop.
Save yaxinr/ceb32f3a332eb3de7830cc5e8f422d3b to your computer and use it in GitHub Desktop.
emberjs printing

I need print badges on landscape format. I add route /badges. Then on this route printing page size must be landscape.

In controllers/application.coffee i observe currentPath and add html head style {@page:size: controller.size}. In badges controller set size prop to landscape

Also i set to row class style page-break-inside: avoid And add class print-color with style print-color-adjust: exact for print color

gist

conclusion: Each route|controller can be have own page size, and this give simple printing

cssPagedMedia = do ->
style = document.createElement('style')
document.head.appendChild style
(rule) ->
style.innerHTML = rule
return
cssPagedMedia.size = (size) ->
cssPagedMedia '@page {size: ' + size + ';}'
return
export default Controller.extend
routeChanged: observer 'currentPath', ->
size = @getWithDefault 'currentController.size', 'auto'
cssPagedMedia.size size
currentController: computed 'currentPath', ->
applicationRoute = @getWithDefault 'applicationRoute', false
currentPath = @get 'currentPath'
applicationRoute.controllerFor(currentPath)
import Controller from '@ember/controller'
export default Controller.extend
size: 'a4 landscape'
import EmberRouter from '@ember/routing/router'
import config from 'ember-get-config'
Router = EmberRouter.extend
location: config.locationType
rootURL: config.rootURL
Router.map ->
@route 'badges'
@media print
.row
page-break-inside: avoid
.print-color
-webkit-print-color-adjust: exact
print-color-adjust: exact
.text-center.print-color: each model.guests as |guest|
.row style="height: 85mm"
each (array 1 2) as |i|
span style="width: 118mm; font-size: 24px;"
.h-25.bg-primary.text-white.border-right.border-white= model.contractor.title
.h-50 style="font-size: 36px;"= guest.title
.h-25.border-top.border-dark= guest.position
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment