Skip to content

Commit fb7c3ac

Browse files
author
Martin Reitschmied
committed
Main blade files for preview using paged.js
1 parent f9399c8 commit fb7c3ac

File tree

2 files changed

+136
-7
lines changed

2 files changed

+136
-7
lines changed

src/Views/printable.blade.php

Lines changed: 73 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,85 @@
66
<meta http-equiv="X-UA-Compatible" content="ie=edge">
77
<meta name="csrf-token" content="{{ csrf_token() }}">
88

9+
910
<title>@yield('title')</title>
11+
12+
@include('ambersive.documentviewer::printable_scripts')
13+
14+
<!-- Page preview styles -->
15+
<style>
16+
/* CSS for Paged.js interface */
17+
18+
:root {
19+
--color-background: #fafafa;
20+
--color-pageBox: #999;
21+
--color-paper: #fff;
22+
--color-marginBox: transparent;
23+
--color-button: #3fda59;
24+
}
25+
26+
/* To define how the book look on the screen: */
27+
@media screen {
28+
body {
29+
background-color: var(--color-background);
30+
}
31+
32+
.pagedjs_pages {
33+
display: flex;
34+
flex: 0;
35+
flex-wrap: wrap;
36+
flex-direction: column;
37+
width: 100%;
38+
margin: 0 auto;
39+
}
40+
41+
.pagedjs_page {
42+
background-color: var(--color-paper);
43+
box-shadow: 0 0 0 1px var(--color-pageBox);
44+
flex-shrink: 0;
45+
flex-grow: 0;
46+
margin: 0 auto;
47+
margin-top: 5mm;
48+
}
49+
50+
.pagedjs_page:last-of-type {
51+
margin-bottom: 1mm;
52+
}
53+
54+
/* show the margin-box */
55+
56+
.pagedjs_margin-top-left-corner-holder,
57+
.pagedjs_margin-top,
58+
.pagedjs_margin-top-left,
59+
.pagedjs_margin-top-center,
60+
.pagedjs_margin-top-right,
61+
.pagedjs_margin-top-right-corner-holder,
62+
.pagedjs_margin-bottom-left-corner-holder,
63+
.pagedjs_margin-bottom,
64+
.pagedjs_margin-bottom-left,
65+
.pagedjs_margin-bottom-center,
66+
.pagedjs_margin-bottom-right,
67+
.pagedjs_margin-bottom-right-corner-holder,
68+
.pagedjs_margin-right,
69+
.pagedjs_margin-right-top,
70+
.pagedjs_margin-right-middle,
71+
.pagedjs_margin-right-bottom,
72+
.pagedjs_margin-left,
73+
.pagedjs_margin-left-top,
74+
.pagedjs_margin-left-middle,
75+
.pagedjs_margin-left-bottom {
76+
box-shadow: 0 0 0 1px inset var(--color-marginBox);
77+
}
78+
}
79+
80+
</style>
1081

11-
<!-- Site specfic styles -->
1282
@section('styles')
13-
<!-- This is the styles section -->
83+
<!-- Custom styles -->
1484
@show
1585

1686
</head>
17-
<body class="pageBody">
87+
<body>
1888

1989
<div class="pages">
2090

@@ -24,9 +94,5 @@
2494

2595
</div>
2696

27-
<script>
28-
function printNow() {window.print();}
29-
</script>
30-
3197
</body>
3298
</html>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<script src="https://unpkg.com/pagedjs/dist/paged.polyfill.js"></script>
2+
<script>
3+
class RepeatingTableHeaders extends Paged.Handler {
4+
constructor(chunker, polisher, caller) {
5+
super(chunker, polisher, caller);
6+
}
7+
8+
afterPageLayout(pageElement, page, breakToken, chunker) {
9+
// Find all split table elements
10+
let tables = pageElement.querySelectorAll("table[data-split-from]");
11+
12+
tables.forEach((table) => {
13+
// There is an edge case where the previous page table
14+
// has zero height (isn't visible).
15+
// To avoid double header we will only add header if there is none.
16+
let tableHeader = table.querySelector("thead");
17+
if (tableHeader) {
18+
return;
19+
}
20+
21+
// Get the reference UUID of the node
22+
let ref = table.dataset.ref;
23+
// Find the node in the original source
24+
let sourceTable = chunker.source.querySelector("[data-ref='" + ref + "']");
25+
26+
// Find if there is a header
27+
let sourceHeader = sourceTable.querySelector("thead");
28+
if (sourceHeader) {
29+
console.log("Table header was cloned, because it is splitted.");
30+
// Clone the header element
31+
let clonedHeader = sourceHeader.cloneNode(true);
32+
// Insert the header at the start of the split table
33+
table.insertBefore(clonedHeader, table.firstChild);
34+
}
35+
});
36+
37+
// Find all tables
38+
tables = pageElement.querySelectorAll("table");
39+
40+
// special case which might not fit for everyone
41+
tables.forEach((table) => {
42+
// if the table has no rows in body, hide it.
43+
// This happens because my render engine creates empty tables.
44+
let sourceBody = table.querySelector("tbody > tr");
45+
if (!sourceBody) {
46+
console.log("Table was hidden, because it has no rows in tbody.");
47+
table.style.visibility = "hidden";
48+
table.style.position = "absolute";
49+
50+
var lineSpacer = table.nextSibling;
51+
if (lineSpacer) {
52+
lineSpacer.style.visibility = "hidden";
53+
lineSpacer.style.position = "absolute";
54+
}
55+
}
56+
});
57+
}
58+
59+
}
60+
61+
Paged.registerHandlers(RepeatingTableHeaders);
62+
63+
</script>

0 commit comments

Comments
 (0)