Skip to content

Commit

Permalink
chore: formating change
Browse files Browse the repository at this point in the history
  • Loading branch information
MikAoJk committed Oct 29, 2024
1 parent 59f5661 commit 3a2369f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
25 changes: 14 additions & 11 deletions src/main/kotlin/no/nav/pdfgen/core/pdf/CreatePdf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import no.nav.pdfgen.core.PDFGenCore
import no.nav.pdfgen.core.util.scale
import no.nav.pdfgen.core.util.toPortait
import org.apache.fontbox.ttf.TTFParser
import org.apache.fontbox.ttf.TrueTypeFont
import org.apache.pdfbox.io.RandomAccessReadBufferedFile
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.pdmodel.PDPage
Expand Down Expand Up @@ -54,11 +53,14 @@ fun createPDFA(html: String): ByteArray {
PdfRendererBuilder()
.apply {
for (font in PDFGenCore.environment.fonts) {
val ttf = TTFParser().parse(
RandomAccessReadBufferedFile(
val ttf =
TTFParser()
.parse(
RandomAccessReadBufferedFile(
"${PDFGenCore.environment.fontsRoot.path}/${font.path}"
)
).also { it.isEnableGsub = false }
)
.also { it.isEnableGsub = false }
useFont(
PDFontSupplier(PDType0Font.load(PDDocument(), ttf, font.subset)),
font.family,
Expand Down Expand Up @@ -89,13 +91,14 @@ fun createPDFA(imageStream: InputStream, outputStream: OutputStream) {

val quality = 1.0f

val pdImage = try {
JPEGFactory.createFromImage(document, image, quality)
} catch (e: javax.imageio.IIOException) {
// To avoid "javax.imageio.IIOException: Illegal band size: should be 0 < size <= 8"
// for certain black/white pictures
LosslessFactory.createFromImage(document, image)
}
val pdImage =
try {
JPEGFactory.createFromImage(document, image, quality)
} catch (e: javax.imageio.IIOException) {
// To avoid "javax.imageio.IIOException: Illegal band size: should be 0 < size <= 8"
// for certain black/white pictures
LosslessFactory.createFromImage(document, image)
}

val imageSize = scale(pdImage, page)

Expand Down
5 changes: 1 addition & 4 deletions src/test/kotlin/no/nav/pdfgen/core/pdf/CreatePdfKtTest.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package no.nav.pdfgen.core.pdf

import java.io.ByteArrayOutputStream
import no.nav.pdfgen.getResource
import org.apache.pdfbox.pdmodel.PDDocument
import org.apache.pdfbox.text.PDFTextStripper
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream

class CreatePdfKtTest {
@Test
Expand Down

0 comments on commit 3a2369f

Please sign in to comment.