From d2abc47f01e0a14789501b52be436ec89d8d427f Mon Sep 17 00:00:00 2001 From: Gustav Berggren <83211434+b162214@users.noreply.github.com> Date: Fri, 20 Oct 2023 09:53:08 +0200 Subject: [PATCH] =?UTF-8?q?Legg=20til=20timestamp=20p=C3=A5=20toppen=20av?= =?UTF-8?q?=20dokumentet=20(#324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inntektsmelding/joark/dokument/PdfBuilder.kt | 14 +++++++++++++- .../inntektsmelding/joark/dokument/PdfDokument.kt | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfBuilder.kt b/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfBuilder.kt index 8cef92798..fb80d6d9f 100644 --- a/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfBuilder.kt +++ b/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfBuilder.kt @@ -16,7 +16,8 @@ class PdfBuilder( val titleSize: Int = 30, val sectionSize: Int = 24, val bodySize: Int = 16, - private val logo: String = "logo.png" + private val logo: String = "logo.png", + private val topText: String? = null ) { private val list: MutableList = mutableListOf() @@ -67,6 +68,16 @@ class PdfBuilder( return y >= pageNumber * PAGE_HEIGHT && y < (pageNumber + 1) * PAGE_HEIGHT } + private fun addTopText(contentStream: PDPageContentStream, font: PDType0Font, text: String) { + contentStream.beginText() + Text(bodySize, text, bold = false, italic = true, 0 + paddingHorisontal / 2, MAX).also { text -> + contentStream.setFont(font, text.fontSize.toFloat() * RATIO) + contentStream.newLineAtOffset(text.x.toFloat(), text.y.toFloat()) + contentStream.showText(text.value) + } + contentStream.endText() + } + private fun producePage(pageNr: Int, doc: PDDocument, FONT_NORMAL: PDType0Font, FONT_BOLD: PDType0Font, FONT_ITALIC: PDType0Font): PDPage { val page = PDPage() val contentStream = PDPageContentStream(doc, page) @@ -79,6 +90,7 @@ class PdfBuilder( val logoX = PAGE_WIDTH - w - paddingHorisontal val logoY = MAX - h contentStream.drawImage(pdImage, logoX, logoY, w, h) + topText?.also { addTopText(contentStream, FONT_ITALIC, it) } } val filteredList = list.filter { isPage(it.y, pageNr) } diff --git a/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfDokument.kt b/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfDokument.kt index 36ea881b6..0c943c74e 100644 --- a/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfDokument.kt +++ b/joark/src/main/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/joark/dokument/PdfDokument.kt @@ -22,7 +22,7 @@ import java.time.LocalDate private const val FORKLARING_ENDRING = "Forklaring for endring" class PdfDokument(val dokument: Inntektsmelding) { - private val pdf = PdfBuilder(bodySize = 20) // Setter skriftstørrelsen på labels og text + private val pdf = PdfBuilder(bodySize = 20, topText = "Innsendt: ${dokument.tidspunkt.toNorsk()}") // Setter skriftstørrelsen på labels og text private var y = 0 private val KOLONNE_EN = 0 private val KOLONNE_TO = 420