Repository navigation
Expand file tree
/
Copy pathsample.mjs
More file actions
64 lines (64 loc) · 2.7 KB
/
Copy pathsample.mjs
File metadata and controls
64 lines (64 loc) · 2.7 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
import { PDFDocument, StandardFonts, rgb } from 'pdf-lib';
import { writeFile } from 'node:fs/promises';
const doc = await PDFDocument.create();
const serif = await doc.embedFont(StandardFonts.TimesRoman),
bold = await doc.embedFont(StandardFonts.TimesRomanBold),
sans = await doc.embedFont(StandardFonts.Helvetica);
const sections = [
[
'A quieter way to read',
'Reading should feel effortless. A document has its own rhythm: a heading, a thought, a pause. Translation can follow that rhythm without taking you away from the page.',
'When you stop scrolling, this reader identifies the text on the page. Each paragraph is translated independently and returns to its original position. The surrounding figures and the shape of the document remain familiar.',
'Click a translated paragraph to see its original wording. You can move between languages at your own pace, keeping the context close at hand.',
],
[
'The space between words',
'Good tools give people room to think. A calm reading environment keeps the document at the center, with controls nearby when they are needed.',
'Translations are saved locally after they arrive. Returning to a paragraph uses the saved result, so the same passage does not need another API request.',
'Try the zoom controls, open Translation settings, or switch the target language. New results arrive one paragraph at a time while the document stays responsive.',
],
];
for (const [index, section] of sections.entries()) {
const page = doc.addPage([612, 792]);
page.drawText('FIELD NOTES / READING & LANGUAGE', {
x: 60,
y: 724,
size: 9,
font: sans,
color: rgb(0.38, 0.42, 0.47),
});
page.drawText(section[0], { x: 60, y: 670, size: 30, font: bold });
page.drawLine({
start: { x: 60, y: 646 },
end: { x: 552, y: 646 },
thickness: 0.5,
color: rgb(0.7, 0.73, 0.76),
});
let y = 608;
for (const text of section.slice(1)) {
const words = text.split(' ');
let line = '';
for (const word of words) {
const candidate = line ? line + ' ' + word : word;
if (serif.widthOfTextAtSize(candidate, 14) > 490) {
page.drawText(line, { x: 60, y, size: 14, font: serif });
y -= 21;
line = word;
} else line = candidate;
}
if (line) {
page.drawText(line, { x: 60, y, size: 14, font: serif });
y -= 21;
}
y -= 26;
}
page.drawRectangle({ x: 60, y: 150, width: 492, height: 90, color: rgb(0.94, 0.96, 0.97) });
page.drawText('A document. A pause. A new perspective.', {
x: 83,
y: 195,
size: 17,
font: serif,
});
page.drawText(String(index + 1), { x: 300, y: 45, size: 10, font: sans });
}
await writeFile('public/sample.pdf', await doc.save());