summaryrefslogtreecommitdiffstats
path: root/components/printing/resources/print_preview_page.html
blob: 4ea37f52c45d5a4f135282c07b4098b8d2e0efa0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
<!doctype html>
<head>
<link rel="stylesheet" href="chrome://resources/css/text_defaults.css">
<style>
  body {
    margin: 0px;
    width: 0px;
  }
  .row {
    display: table-row;
    vertical-align: inherit;
  }
  #header, #footer {
    display: table;
    table-layout:fixed;
    width: inherit;
  }
  #header {
    vertical-align: top;
  }
  #footer {
    vertical-align: bottom;
  }
  .text {
    display: table-cell;
    font-size: 8px;
    vertical-align: inherit;
    white-space: nowrap;
  }
  #page_number {
    text-align: right;
  }
  #title {
    text-align: center;
  }
  #date, #url {
    padding-left: 0.7cm;
    padding-right: 0.1cm;
  }
  #title, #page_number {
    padding-left: 0.1cm;
    padding-right: 0.7cm;
  }
  #title, #url {
    overflow: hidden;
    text-overflow: ellipsis;
  }
  #title, #date {
    padding-bottom: 0cm;
    padding-top: 0.4cm;
  }
  #page_number, #url {
    padding-bottom: 0.4cm;
    padding-top: 0cm;
  }
</style>
<script>

function pixels(value) {
  return value + 'px';
}
  
function setup(options) {
  var body = document.querySelector('body');
  var header = document.querySelector('#header');
  var content = document.querySelector('#content');
  var footer = document.querySelector('#footer');

  body.style.width = pixels(options['width']);
  body.style.height = pixels(options['height']);
  header.style.height = pixels(options['topMargin']);
  content.style.height = pixels(options['height'] - options['topMargin'] -
                                options['bottomMargin']);
  footer.style.height = pixels(options['bottomMargin']);

  document.querySelector('#date span').innerText =
      new Date(options['date']).toLocaleDateString();
  document.querySelector('#title span').innerText = options['title'];

  document.querySelector('#url span').innerText = options['url'];
  document.querySelector('#page_number span').innerText = options['pageNumber'];

  // Reduce date and page number space to give more space to title and url.
  document.querySelector('#date').style.width =
      pixels(document.querySelector('#date span').offsetWidth);
  document.querySelector('#page_number').style.width =
      pixels(document.querySelector('#page_number span').offsetWidth);

  // Hide text if it doesn't fit into expected margins.
  if (header.offsetHeight > options['topMargin'] + 1) {
    header.style.display = 'none';
    content.style.height = pixels(options['height'] - options['bottomMargin']);
  }
  if (footer.offsetHeight > options['bottomMargin'] + 1) {
    footer.style.display = 'none';
  }
}

</script>
</head>
<body>
  <div id="header">
    <div class="row">
      <div id="date" class="text"><span/></div>
      <div id="title" class="text"><span/></div>
    </div>
  </div>
  <div id="content">
  </div>
  <div id="footer">
    <div class="row">
      <div id="url" class="text"><span/></div>
      <div id="page_number" class="text"><span/></div>
    </div>
  </div>
</body>
</html>