Skip to content

Commit 0eddead

Browse files
committed
Add printing stylesheet, enables printing of text files
Currently printing will include the menu bar and longer text files will be cropped after the first page. This enables printing of text documents without any major styling changes, slightly adjusted margins and added table borders. This implements the CSS part of #112 Signed-off-by: Ferdinand Thiessen <rpm@fthiessen.de>
1 parent 246dbab commit 0eddead

3 files changed

Lines changed: 109 additions & 2 deletions

File tree

css/print.scss

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
@media print {
2+
@page {
3+
size: A4;
4+
margin: 2.5cm 2cm 2cm 2.5cm;
5+
}
6+
7+
#viewer[data-handler="text"] {
8+
// Hide top border
9+
border: none;
10+
width: 100%!important;
11+
// NcModal uses fixed, which will be cropped when printed
12+
position: absolute!important;
13+
14+
.modal-header {
15+
// Hide modal header (close button)
16+
display: none!important;
17+
}
18+
.modal-container {
19+
// Make sure top aligned as we hided the menubar */
20+
top: 0px;
21+
height: fit-content;
22+
}
23+
}
24+
25+
.text-editor {
26+
.text-menubar {
27+
// Hide menu bar
28+
display: none!important;
29+
}
30+
.action-item {
31+
// Hide table settings
32+
display: none!important;
33+
}
34+
.editor__content {
35+
// Margins set by page rule
36+
max-width: 100%;
37+
}
38+
.text-editor__wrapper {
39+
height: fit-content;
40+
position: unset;
41+
}
42+
43+
div.ProseMirror {
44+
h1, h2, h3, h4, h5 {
45+
// orphaned headlines are ugly
46+
break-after: avoid;
47+
}
48+
.image, img, table {
49+
// try no page breaks within tables or images
50+
break-inside: avoid-page;
51+
// Some more indention
52+
max-width: 90%!important;
53+
margin: 5vw auto 5vw 5%!important;
54+
}
55+
56+
// Add some borders below header and between columns
57+
th {
58+
color: black!important;
59+
font-weight: bold!important;
60+
border-width: 0 1px 2px 0!important;
61+
border-color: gray!important;
62+
border-style: none solid solid none!important;
63+
}
64+
th:last-of-type {
65+
border-width: 0 0 2px 0!important;
66+
}
67+
68+
td {
69+
border-style: none solid none none!important;
70+
border-width: 1px!important;
71+
border-color: gray!important;
72+
}
73+
td:last-of-type {
74+
border: none!important;
75+
}
76+
}
77+
}
78+
}

src/components/Editor.vue

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-
44
- @author Julius Härtl <jus@bitgrid.net>
55
-
6-
- @license GNU AGPL version 3 or any later version
6+
- @license AGPL-3.0-or-later
77
-
88
- This program is free software: you can redistribute it and/or modify
99
- it under the terms of the GNU Affero General Public License as
@@ -286,6 +286,12 @@ export default {
286286
if (this.active && (this.hasDocumentParameters)) {
287287
this.initSession()
288288
}
289+
if (!this.richWorkspace) {
290+
/* If the editor is shown in the viewer we need to hide the content,
291+
if richt workspace is used we **must** not hide the content */
292+
window.addEventListener('beforeprint', this.preparePrinting)
293+
window.addEventListener('afterprint', this.preparePrinting)
294+
}
289295
this.$parent.$emit('update:loaded', true)
290296
},
291297
created() {
@@ -639,6 +645,9 @@ export default {
639645
640646
async close() {
641647
clearInterval(this.saveStatusPolling)
648+
window.removeEventListener('beforeprint', this.preparePrinting)
649+
window.removeEventListener('afterprint', this.preparePrinting)
650+
642651
if (this.currentSession && this.$syncService) {
643652
try {
644653
await this.$syncService.close()
@@ -660,6 +669,17 @@ export default {
660669
}
661670
return true
662671
},
672+
673+
/** @param {Event} event */
674+
preparePrinting(event) {
675+
const content = document.getElementById('content')
676+
// Hide Content behind modal, this also hides the sidebar if open
677+
if (content && event.type === 'beforeprint') {
678+
content.style.display = 'none'
679+
} else if (content) {
680+
content.style.display = ''
681+
}
682+
},
663683
},
664684
}
665685
</script>
@@ -725,6 +745,7 @@ export default {
725745
726746
<style lang="scss">
727747
@import './../../css/style';
748+
@import './../../css/print';
728749
729750
.text-editor__wrapper {
730751
@import './../../css/prosemirror';

src/components/RichTextReader.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-
44
- @author Julius Härtl <jus@bitgrid.net>
55
-
6-
- @license GNU AGPL version 3 or any later version
6+
- @license AGPL-3.0-or-later
77
-
88
- This program is free software: you can redistribute it and/or modify
99
- it under the terms of the GNU Affero General Public License as
@@ -79,4 +79,12 @@ export default {
7979

8080
<style lang="scss">
8181
@import './../../css/prosemirror';
82+
@import './../../css/print';
83+
84+
@media print {
85+
// Hide Content behind modal, this also hides the sidebar if open
86+
#content {
87+
display: none;
88+
}
89+
}
8290
</style>

0 commit comments

Comments
 (0)