Skip to content

Commit e1bb1bb

Browse files
authored
Merge pull request #131 from navikt/without-header-footer
Without header footer
2 parents 2f30efc + 1ff40b7 commit e1bb1bb

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

legacy-archive/server/src/pdf/PdfGenerator.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ export class PdfGenerator {
120120

121121
const widthActual = width >= MIN_WIDTH_PX ? width : DEFAULT_WIDTH_PX;
122122

123+
// Remove header and footer in print
124+
const htmlWithoutHeaderAndFooter = html.replaceAll(
125+
/(<header([^;]*)<\/header>|<footer([^;]*)<\/footer>)/g,
126+
''
127+
);
128+
123129
// Ensures assets with relative urls are loaded from the correct origin
124-
const htmlWithBase = html.replace(
130+
const htmlWithBase = htmlWithoutHeaderAndFooter.replace(
125131
'<head>',
126132
`<head><base href="${process.env.APP_ORIGIN_INTERNAL}"/>`
127133
);

xp-archive/server/src/services/PdfService.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,15 @@ export class PdfService {
130130
try {
131131
const page = await this.browser.newPage();
132132

133+
// Remove header and footer in print
134+
const htmlWithoutHeaderAndFooter = html.replaceAll(
135+
/(<header([^;]*)<\/header>|<footer([^;]*)<\/footer>)/g,
136+
''
137+
);
138+
133139
await page.setViewport({ width: widthActual, height: 1024, deviceScaleFactor: 1 });
134140
await page.emulateMediaType('screen');
135-
await page.setContent(html);
141+
await page.setContent(htmlWithoutHeaderAndFooter);
136142

137143
const pdf = await page.pdf({
138144
printBackground: true,

0 commit comments

Comments
 (0)