-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrahmen.html
More file actions
168 lines (140 loc) · 5.69 KB
/
rahmen.html
File metadata and controls
168 lines (140 loc) · 5.69 KB
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
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PDF Rand Generator (Querformat)</title>
<script src="https://unpkg.com/pdf-lib@1.17.1/dist/pdf-lib.min.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f4f4f4;
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
}
.container {
background: white;
padding: 40px;
border-radius: 8px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
text-align: center;
max-width: 600px;
width: 100%;
}
h1 { margin-top: 0; color: #333; }
p { color: #666; }
.upload-btn-wrapper {
position: relative;
overflow: hidden;
display: inline-block;
margin: 20px 0;
}
input[type=file] {
font-size: 100px;
position: absolute;
left: 0;
top: 0;
opacity: 0;
cursor: pointer;
}
button {
border: 2px solid #007bff;
color: white;
background-color: #007bff;
padding: 10px 25px;
border-radius: 5px;
font-size: 18px;
font-weight: bold;
cursor: pointer;
transition: 0.3s;
}
button:hover { background-color: #0056b3; border-color: #0056b3; }
iframe {
margin-top: 30px;
width: 100%;
height: 500px; /* Etwas flacher für Querformat-Ansicht */
border: 1px solid #ccc;
display: none;
}
.status { margin-top: 10px; font-weight: bold; color: #007bff; min-height: 24px;}
</style>
</head>
<body>
<div class="container">
<h1>PDF Rand (Querformat)</h1>
<p>
Format: A4 Quer (Landscape)<br>
Rand: 31mm | Trennlinie: 16mm
</p>
<div class="upload-btn-wrapper">
<button class="btn">PDF Datei auswählen</button>
<input type="file" id="fileInput" accept="application/pdf" />
</div>
<div class="status" id="statusText"></div>
</div>
<iframe id="pdfPreview"></iframe>
<script>
const { PDFDocument, rgb } = PDFLib;
document.getElementById('fileInput').addEventListener('change', async (e) => {
const file = e.target.files[0];
if (!file) return;
const statusText = document.getElementById('statusText');
statusText.textContent = "Verarbeite PDF (Querformat)...";
try {
const arrayBuffer = await file.arrayBuffer();
const originalPdf = await PDFDocument.load(arrayBuffer);
const newPdf = await PDFDocument.create();
const mm = 2.83465;
// ÄNDERUNG: A4 Maße getauscht für Querformat
const A4_WIDTH = 297 * mm; // Breite ist jetzt die lange Seite
const A4_HEIGHT = 210 * mm; // Höhe ist jetzt die kurze Seite
const MARGIN_TOTAL = 31 * mm;
const LINE_POS = 16 * mm;
const contentMaxWidth = A4_WIDTH - (2 * MARGIN_TOTAL);
const contentMaxHeight = A4_HEIGHT - (2 * MARGIN_TOTAL);
const pages = originalPdf.getPages();
const embeddedPages = await newPdf.embedPages(pages);
for (let i = 0; i < embeddedPages.length; i++) {
const embeddedPage = embeddedPages[i];
const originalDims = embeddedPage.scale(1);
const page = newPdf.addPage([A4_WIDTH, A4_HEIGHT]);
// Rechteck/Linie zeichnen (passt sich an Querformat an)
page.drawRectangle({
x: LINE_POS,
y: LINE_POS,
width: A4_WIDTH - (2 * LINE_POS),
height: A4_HEIGHT - (2 * LINE_POS),
borderColor: rgb(0, 0, 0),
borderWidth: 1,
});
// Inhalt skalieren und zentrieren
const scaleX = contentMaxWidth / originalDims.width;
const scaleY = contentMaxHeight / originalDims.height;
const scale = Math.min(scaleX, scaleY);
const centeredX = (A4_WIDTH - (originalDims.width * scale)) / 2;
const centeredY = (A4_HEIGHT - (originalDims.height * scale)) / 2;
page.drawPage(embeddedPage, {
x: centeredX,
y: centeredY,
width: originalDims.width * scale,
height: originalDims.height * scale,
});
}
const pdfBytes = await newPdf.save();
const blob = new Blob([pdfBytes], { type: 'application/pdf' });
const url = URL.createObjectURL(blob);
const iframe = document.getElementById('pdfPreview');
iframe.src = url;
iframe.style.display = 'block';
statusText.textContent = "Fertig! Siehe Vorschau unten.";
} catch (err) {
console.error(err);
statusText.textContent = "Fehler beim Verarbeiten.";
alert("Fehler! Bitte überprüfe die Datei.");
}
});
</script>
</body>
</html>