Skip to content

Commit 7fbf88c

Browse files
authored
Feature/navigation buttons (#4)
* Added page printing
1 parent 4d93617 commit 7fbf88c

File tree

1 file changed

+134
-3
lines changed

1 file changed

+134
-3
lines changed

merge_all_publications.py

Lines changed: 134 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ def merge_html_pages(publication_files, output_path):
6464
background-color: black;
6565
}
6666
.container {
67-
width: 840px;
67+
width: 843px;
6868
margin: 0 auto;
6969
overflow-y: auto;
7070
}
7171
.publication {
72-
width: 840px;
72+
width: 843px;
7373
height: 600px;
7474
position: relative;
7575
margin-bottom: 20px;
@@ -135,6 +135,70 @@ def merge_html_pages(publication_files, output_path):
135135
display: flex;
136136
align-items: center;
137137
}
138+
.print-container {
139+
display: flex;
140+
align-items: center;
141+
gap: 5px;
142+
margin-left: 15px;
143+
}
144+
.print-button {
145+
background-color: #28a745;
146+
font-size: 12px;
147+
padding: 6px 12px;
148+
}
149+
.print-button:hover {
150+
background-color: #218838;
151+
}
152+
153+
/* Print media queries */
154+
@page {
155+
size: landscape;
156+
}
157+
158+
@media print {
159+
/* Hide navigation elements */
160+
.separator, .nav-button, .goto-container, .current-page-display, .print-container {
161+
display: none !important;
162+
}
163+
164+
/* Reset body and container for print */
165+
body {
166+
background-color: white !important;
167+
margin: 0 !important;
168+
padding: 0 !important;
169+
}
170+
171+
.container {
172+
width: 100% !important;
173+
margin: 0 auto !important;
174+
padding: 0 !important;
175+
text-align: center !important;
176+
}
177+
178+
/* Hide all pages by default */
179+
.publication {
180+
display: none !important;
181+
page-break-after: always;
182+
}
183+
184+
/* Show only the page marked for printing with simple scaling */
185+
.publication.print-active {
186+
display: block !important;
187+
transform: scale(0.85) !important;
188+
transform-origin: top center !important;
189+
margin: 20px auto !important;
190+
}
191+
192+
/* Hide only the specific InDesign interactive elements that should be hidden */
193+
._idGenStateHide {
194+
display: none !important;
195+
}
196+
197+
/* Hide audio controls */
198+
audio {
199+
display: none !important;
200+
}
201+
}
138202
</style>
139203
<script type="text/javascript">
140204
function scrollToPage(userPageNumber) {
@@ -184,6 +248,70 @@ def merge_html_pages(publication_files, output_path):
184248
input.value = '';
185249
}
186250
251+
function printCurrentPage() {
252+
// Get the currently visible page
253+
const currentPageNumber = getCurrentVisiblePage();
254+
printSpecificPage(currentPageNumber);
255+
}
256+
257+
function printSpecificPage(pageNumber) {
258+
console.log('Printing page:', pageNumber);
259+
260+
// Remove print-active class from all pages
261+
document.querySelectorAll('.publication').forEach(pub => {
262+
pub.classList.remove('print-active');
263+
});
264+
265+
// Add print-active class to the target page
266+
const targetPageId = 'publication-' + (pageNumber - 1);
267+
const targetPage = document.getElementById(targetPageId);
268+
269+
console.log('Target page ID:', targetPageId);
270+
console.log('Target page element:', targetPage);
271+
272+
if (targetPage) {
273+
targetPage.classList.add('print-active');
274+
console.log('Added print-active class to:', targetPage);
275+
276+
// Add a small delay to ensure CSS is applied
277+
setTimeout(() => {
278+
// Trigger print dialog
279+
window.print();
280+
281+
// Clean up after print dialog closes
282+
setTimeout(() => {
283+
targetPage.classList.remove('print-active');
284+
console.log('Removed print-active class');
285+
}, 1000);
286+
}, 100);
287+
} else {
288+
console.error('Could not find page element with ID:', targetPageId);
289+
alert('Could not find page to print. Available pages: ' +
290+
Array.from(document.querySelectorAll('.publication')).map(p => p.id).join(', '));
291+
}
292+
}
293+
294+
function getCurrentVisiblePage() {
295+
// Find which page is currently most visible in viewport
296+
const publications = document.querySelectorAll('.publication');
297+
let mostVisiblePage = 1;
298+
let maxVisibleArea = 0;
299+
300+
publications.forEach((pub, index) => {
301+
const rect = pub.getBoundingClientRect();
302+
const visibleHeight = Math.min(rect.bottom, window.innerHeight) - Math.max(rect.top, 0);
303+
const visibleArea = Math.max(0, visibleHeight) * rect.width;
304+
305+
if (visibleArea > maxVisibleArea) {
306+
maxVisibleArea = visibleArea;
307+
mostVisiblePage = index + 1; // Convert to 1-based
308+
}
309+
});
310+
311+
return mostVisiblePage;
312+
}
313+
314+
187315
// Register interactive handlers from original script and add our navigation
188316
function initializeNavigation() {
189317
if (typeof RegisterInteractiveHandlers === 'function') {
@@ -241,10 +369,13 @@ def merge_html_pages(publication_files, output_path):
241369
<input type="number" class="goto-input" id="{input_id}" min="1" max="{total_pages}" placeholder="1-{total_pages}">
242370
<button class="nav-button" onclick="{goto_onclick}">Go</button>
243371
</div>
244-
<button class="nav-button" {next_disabled} onclick="{next_onclick}">Next Page</button>
372+
<div class="print-container">
373+
<button class="nav-button print-button" onclick="printCurrentPage()">Print Current Page</button>
374+
</div>
245375
<div class="current-page-display">
246376
Page {display_page_number} of {total_pages}
247377
</div>
378+
<button class="nav-button" {next_disabled} onclick="{next_onclick}">Next Page</button>
248379
</div>
249380
'''
250381

0 commit comments

Comments
 (0)