File size: 4,591 Bytes
83e35a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
/**
 * Enhanced PDF Export Settings Guide
 * 
 * For best results when exporting to PDF:
 */

// Browser-specific settings for optimal PDF export

const PDFExportGuide = {
    
    // Chrome/Edge settings
    chrome: {
        destination: "Save as PDF",
        layout: "Landscape",
        paperSize: "A4",
        margins: "None",
        scale: "Fit to page width",
        backgroundGraphics: true,
        headers: false
    },
    
    // Firefox settings
    firefox: {
        destination: "Save as PDF",
        orientation: "Landscape",
        paperSize: "A4",
        margins: "None",
        scale: 100,
        printBackgrounds: true,
        shrinkToFit: true
    },
    
    // Safari settings
    safari: {
        PDF: "Save as PDF",
        orientation: "Landscape",
        paperSize: "A4",
        scale: "100%",
        printBackgrounds: true
    }
};

// Alternative CSS for better PDF sizing
const enhancedPrintCSS = `
@media print {
    /* Force exact dimensions */
    html, body {
        width: 297mm;
        height: 210mm;
        margin: 0;
        padding: 0;
        overflow: hidden;
    }
    
    /* Hide everything except comic pages */
    body > *:not(.comic-container) {
        display: none !important;
    }
    
    /* Comic container full size */
    .comic-container {
        width: 297mm !important;
        height: 210mm !important;
        margin: 0 !important;
        padding: 0 !important;
        position: relative !important;
    }
    
    /* Each page exact A4 landscape */
    .comic-page {
        width: 297mm !important;
        height: 210mm !important;
        page-break-after: always !important;
        page-break-inside: avoid !important;
        position: relative !important;
        margin: 0 !important;
        padding: 10mm !important;
        box-sizing: border-box !important;
    }
    
    /* Grid fills available space */
    .comic-grid {
        width: 100% !important;
        height: 100% !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        grid-template-rows: 1fr 1fr !important;
        gap: 5mm !important;
    }
    
    /* Panels fill grid cells */
    .panel {
        width: 100% !important;
        height: 100% !important;
        position: relative !important;
        overflow: hidden !important;
        border: 2px solid black !important;
    }
    
    .panel img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }
    
    /* Print settings */
    @page {
        size: A4 landscape;
        margin: 0;
    }
}
`;

// Function to prepare document for PDF export
function preparePDFExport() {
    // Remove any existing print styles
    const existingPrintStyles = document.querySelector('#pdf-print-styles');
    if (existingPrintStyles) {
        existingPrintStyles.remove();
    }
    
    // Add enhanced print styles
    const styleEl = document.createElement('style');
    styleEl.id = 'pdf-print-styles';
    styleEl.innerHTML = enhancedPrintCSS;
    document.head.appendChild(styleEl);
    
    // Temporarily modify layout for better printing
    const comicPages = document.querySelectorAll('.comic-page');
    comicPages.forEach(page => {
        page.style.pageBreakAfter = 'always';
        page.style.pageBreakInside = 'avoid';
    });
    
    // Show browser-specific instructions
    const userAgent = navigator.userAgent;
    let instructions = '';
    
    if (userAgent.includes('Chrome') || userAgent.includes('Edge')) {
        instructions = 'Chrome/Edge detected. Use these settings:\n' +
                      '• Layout: Landscape\n' +
                      '• Margins: None\n' +
                      '• Scale: Fit to page width';
    } else if (userAgent.includes('Firefox')) {
        instructions = 'Firefox detected. Use these settings:\n' +
                      '• Orientation: Landscape\n' +
                      '• Margins: None\n' +
                      '• Scale: 100%';
    } else if (userAgent.includes('Safari')) {
        instructions = 'Safari detected. Use these settings:\n' +
                      '• Orientation: Landscape\n' +
                      '• Scale: 100%';
    }
    
    if (instructions) {
        console.log('📄 PDF Export Settings:\n' + instructions);
    }
}

// Enhanced export function
function exportToPDFEnhanced() {
    preparePDFExport();
    
    setTimeout(() => {
        window.print();
    }, 100);
}

// Add to window for global access
window.exportToPDFEnhanced = exportToPDFEnhanced;