Skip to content

Commit

Permalink
Legg til timestamp på toppen av dokumentet (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
b162214 authored Oct 20, 2023
1 parent c348787 commit d2abc47
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Text> = mutableListOf()
Expand Down Expand Up @@ -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)
Expand All @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d2abc47

Please sign in to comment.