Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,17 @@ object Dependencies {
//junit
const val JUNIT = "org.jetbrains.kotlin:kotlin-test-junit5"
const val JUNIT_PLATFORM_LAUNCHER = "org.junit.platform:junit-platform-launcher"

//poi
const val POI = "org.apache.poi:poi:${DependencyVersions.POI_VERSION}"
const val POI_OOXML = "org.apache.poi:poi-ooxml:${DependencyVersions.POI_VERSION}"

//Pdf
const val PDF_ITEXT = "com.itextpdf:itext7-fonts:${DependencyVersions.PDF_ITEXT}"
const val PDF_HTML = "com.itextpdf:html2pdf:${DependencyVersions.PDF_HTML}"

const val THYMELEAF = "org.springframework.boot:spring-boot-starter-thymeleaf"

//commons io
const val COMMONS_IO = "commons-io:commons-io:${DependencyVersions.COMMONS_IO}"
}
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/DependencyVersions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ object DependencyVersions {

// Kotlinx Coroutines
const val KOTLINX_COROUTINES_VERSION = "1.8.1"

const val PDF_ITEXT = "7.2.0"
const val PDF_HTML = "3.0.3"
const val POI_VERSION = "5.2.3"
const val COMMONS_IO = "2.11.0"
}
9 changes: 9 additions & 0 deletions casper-application-infrastructure/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@ dependencies {

implementation(Dependencies.KOTLIN_REFLECT)
testImplementation(Dependencies.KOTLIN_TEST)

// itext
implementation(Dependencies.PDF_HTML)
implementation (Dependencies.THYMELEAF)

//read-file
implementation(Dependencies.COMMONS_IO)
implementation(Dependencies.POI)
implementation(Dependencies.POI_OOXML)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package hs.kr.entrydsm.application.global.document.pdf.config

import com.itextpdf.html2pdf.ConverterProperties
import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider
import com.itextpdf.io.font.FontProgramFactory
import org.springframework.stereotype.Component
import java.io.IOException

@Component
class ConverterPropertiesCreator {

private var fontPath: String = "/fonts/"

fun createConverterProperties(): ConverterProperties {
val properties = ConverterProperties()
val fontProvider = DefaultFontProvider(false, false, false)

Font.fonts.forEach { font ->
try {
val fontProgram = FontProgramFactory.createFont("$fontPath$font")
fontProvider.addFont(fontProgram)
} catch (e: IOException) {
throw IllegalStateException("폰트 파일을 찾을 수 없습니다: $font", e)
}
}

properties.fontProvider = fontProvider
return properties
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hs.kr.entrydsm.application.global.document.pdf.config

object Font {
val fonts = listOf(
"KoPubWorld Dotum Light.ttf",
"KoPubWorld Dotum Bold.ttf",
"KoPubWorld Dotum Medium.ttf",
"DejaVuSans.ttf"
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package hs.kr.entrydsm.application.global.document.pdf.config

import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.thymeleaf.TemplateEngine
import org.thymeleaf.templatemode.TemplateMode
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver

@Configuration
class PdfConfig {

@Bean
fun templateEngine(): TemplateEngine {
val templateResolver = ClassLoaderTemplateResolver().apply {
prefix = "classpath:/templates/"
suffix = ".html"
templateMode = TemplateMode.HTML
}
return TemplateEngine().apply {
this.setTemplateResolver(templateResolver)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package hs.kr.entrydsm.application.global.document.pdf.data

import org.springframework.stereotype.Component
import java.util.HashMap

@Component
class IntroductionPdfConverter {

fun execute(application: Any): PdfData {
val values: MutableMap<String, Any> = HashMap()
setIntroduction(application, values)
setPersonalInfo(application, values)
setSchoolInfo(application, values)
setPhoneNumber(application, values)
setReceiptCode(application, values)
return PdfData(values)
}

private fun setPersonalInfo(application: Any, values: MutableMap<String, Any>) {
// TODO: Application 도메인 모델 연동 필요
values["userName"] = "더미사용자명"
values["address"] = "더미주소"
values["detailAddress"] = "더미상세주소"
}

private fun setSchoolInfo(application: Any, values: MutableMap<String, Any>) {
// TODO: 교육상태 및 졸업정보 연동 필요
// 현재는 더미 데이터로 설정
values["schoolName"] = "더미중학교"
}

private fun setReceiptCode(application: Any, values: MutableMap<String, Any>) {
// TODO: Application 도메인 모델 연동 필요
values["receiptCode"] = "더미수험번호"
}

private fun setPhoneNumber(application: Any, values: MutableMap<String, Any>) {
values["applicantTel"] = toFormattedPhoneNumber("01012345678")
}

private fun toFormattedPhoneNumber(phoneNumber: String): String {
if (phoneNumber.length == 8) {
return phoneNumber.replace("(\\d{4})(\\d{4})".toRegex(), "$1-$2")
}
return phoneNumber.replace("(\\d{2,3})(\\d{3,4})(\\d{4})".toRegex(), "$1-$2-$3")
}

private fun setIntroduction(application: Any, values: MutableMap<String, Any>) {
values["selfIntroduction"] = "더미 자기소개 내용"
values["studyPlan"] = "더미 학업계획 내용"
values["newLineChar"] = "\n"
values["examCode"] = "더미수험번호"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package hs.kr.entrydsm.application.global.document.pdf.data

data class PdfData(
private val values: MutableMap<String, Any>
) {
fun toMap(): MutableMap<String, Any> = values

fun getValue(key: String): Any? = values[key]

fun setValue(key: String, value: Any) {
values[key] = value
}
}
Loading
Loading