-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCvTemplateGalleryFileExample.java
More file actions
131 lines (118 loc) · 5.85 KB
/
CvTemplateGalleryFileExample.java
File metadata and controls
131 lines (118 loc) · 5.85 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
package com.demcha.examples.templates.cv;
import com.demcha.compose.GraphCompose;
import com.demcha.compose.document.api.DocumentPageSize;
import com.demcha.compose.document.api.DocumentSession;
import com.demcha.compose.document.templates.api.DocumentTemplate;
import com.demcha.compose.document.templates.cv.presets.BlueBanner;
import com.demcha.compose.document.templates.cv.presets.BoxedSections;
import com.demcha.compose.document.templates.cv.presets.CenteredHeadline;
import com.demcha.compose.document.templates.cv.presets.ClassicSerif;
import com.demcha.compose.document.templates.cv.presets.CompactMono;
import com.demcha.compose.document.templates.cv.presets.EditorialBlue;
import com.demcha.compose.document.templates.cv.presets.EngineeringResume;
import com.demcha.compose.document.templates.cv.presets.Executive;
import com.demcha.compose.document.templates.cv.presets.ModernProfessional;
import com.demcha.compose.document.templates.cv.presets.MonogramSidebar;
import com.demcha.compose.document.templates.cv.presets.NordicClean;
import com.demcha.compose.document.templates.cv.presets.Panel;
import com.demcha.compose.document.templates.cv.presets.SidebarPortrait;
import com.demcha.compose.document.templates.cv.presets.TimelineMinimal;
import com.demcha.compose.document.templates.cv.spec.CvSpec;
import com.demcha.compose.document.theme.BusinessTheme;
import com.demcha.examples.support.ExampleDataFactory;
import com.demcha.examples.support.ExampleOutputPaths;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
/**
* Renders all 14 Templates v2 CV presets against the same shared
* sample data. Each PDF lands in
* {@code examples/target/generated-pdfs/cv-<id>.pdf} where
* {@code <id>} is the preset's stable identifier (e.g.
* {@code cv-modern-professional.pdf}).
*
* <p>This is the single source of truth for the example CV gallery
* in v2. The matching cover-letter gallery lives in
* {@link CoverLetterTemplateGalleryFileExample}.</p>
*/
public final class CvTemplateGalleryFileExample {
private static final BusinessTheme THEME = BusinessTheme.modern();
private CvTemplateGalleryFileExample() {
}
/**
* Renders all 14 v2 CV preset gallery PDFs.
*
* @return list of absolute paths of the rendered PDFs in source
* order
* @throws Exception if any rendering fails
*/
public static List<Path> generate() throws Exception {
return generate(null);
}
/**
* Renders one preset (when {@code presetId} matches its stable id)
* or all presets when {@code presetId} is null.
*
* @param presetId stable preset id to render exclusively, or null
* to render all presets
* @return list of absolute paths of the rendered PDFs
* @throws Exception if any rendering fails
*/
public static List<Path> generate(String presetId) throws Exception {
List<Run> runs = List.of(
run(ModernProfessional.ID, ModernProfessional.RECOMMENDED_MARGIN, ModernProfessional::create),
run(NordicClean.ID, NordicClean.RECOMMENDED_MARGIN, NordicClean::create),
run(ClassicSerif.ID, ClassicSerif.RECOMMENDED_MARGIN, ClassicSerif::create),
run(CompactMono.ID, CompactMono.RECOMMENDED_MARGIN, CompactMono::create),
run(Executive.ID, Executive.RECOMMENDED_MARGIN, Executive::create),
run(EngineeringResume.ID, EngineeringResume.RECOMMENDED_MARGIN, EngineeringResume::create),
run(TimelineMinimal.ID, TimelineMinimal.RECOMMENDED_MARGIN, TimelineMinimal::create),
run(BoxedSections.ID, BoxedSections.RECOMMENDED_MARGIN, BoxedSections::create),
run(CenteredHeadline.ID, CenteredHeadline.RECOMMENDED_MARGIN, CenteredHeadline::create),
run(BlueBanner.ID, BlueBanner.RECOMMENDED_MARGIN, BlueBanner::create),
run(EditorialBlue.ID, EditorialBlue.RECOMMENDED_MARGIN, EditorialBlue::create),
run(Panel.ID, Panel.RECOMMENDED_MARGIN, Panel::create),
run(SidebarPortrait.ID, SidebarPortrait.RECOMMENDED_MARGIN, SidebarPortrait::create),
run(MonogramSidebar.ID, MonogramSidebar.RECOMMENDED_MARGIN, MonogramSidebar::create));
CvSpec spec = ExampleDataFactory.sampleCvSpecV2();
List<Path> generated = new ArrayList<>();
for (Run cv : runs) {
if (presetId != null && !cv.id.equals(presetId)) {
continue;
}
generated.add(renderOne(spec, cv));
}
return List.copyOf(generated);
}
/**
* Renders all v2 CV preset gallery PDFs and prints each path.
*
* @param args optional first arg = preset id filter
* @throws Exception if any rendering fails
*/
public static void main(String[] args) throws Exception {
String presetId = args.length == 0 ? null : args[0];
for (Path output : generate(presetId)) {
System.out.println("Generated: " + output);
}
}
private static Path renderOne(CvSpec spec, Run cv) throws Exception {
Path outputFile = ExampleOutputPaths.prepare("templates/cv", "cv-" + cv.id + ".pdf");
DocumentTemplate<CvSpec> template = cv.factory.apply(THEME);
float m = (float) cv.margin;
try (DocumentSession document = GraphCompose.document(outputFile)
.pageSize(DocumentPageSize.A4)
.margin(m, m, m, m)
.create()) {
template.compose(document, spec);
document.buildPdf();
}
return outputFile;
}
private static Run run(String id, double margin, Function<BusinessTheme, DocumentTemplate<CvSpec>> factory) {
return new Run(id, margin, factory);
}
private record Run(String id, double margin, Function<BusinessTheme, DocumentTemplate<CvSpec>> factory) {
}
}