summaryrefslogtreecommitdiff
path: root/lib/cover/cover-service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/cover/cover-service.ts')
-rw-r--r--lib/cover/cover-service.ts60
1 files changed, 24 insertions, 36 deletions
diff --git a/lib/cover/cover-service.ts b/lib/cover/cover-service.ts
index eecc289b..6db0c9b4 100644
--- a/lib/cover/cover-service.ts
+++ b/lib/cover/cover-service.ts
@@ -2,7 +2,6 @@
import { PDFNet } from "@pdftron/pdfnet-node"
import { promises as fs } from "fs"
import path from "path"
-import { file as tmpFile } from "tmp-promise"
import db from "@/db/db"
import { projectCoverTemplates, projects } from "@/db/schema"
import { eq, and } from "drizzle-orm"
@@ -147,40 +146,29 @@ export async function generateCoverPage(
const result = await PDFNet.runWithCleanup(async () => {
console.log("πŸ”„ PDFTron μ΄ˆκΈ°ν™” 및 λ³€μˆ˜ μΉ˜ν™˜ μ‹œμž‘")
- // μž„μ‹œ 파일 생성 (κ²°κ³Όλ¬Ό μ €μž₯용)
- const { path: tempOutputPath, cleanup } = await tmpFile({
- postfix: ".docx",
- })
-
- try {
- // ν…œν”Œλ¦Ώ λ‘œλ“œ 및 λ³€μˆ˜ μΉ˜ν™˜
- console.log("πŸ“„ ν…œν”Œλ¦Ώ λ‘œλ“œ 쀑...")
- const templateDoc = await PDFNet.Convert.createOfficeTemplateWithPath(
- templateFilePath
- )
-
- console.log("πŸ”„ λ³€μˆ˜ μΉ˜ν™˜ 쀑...")
- // JSON ν˜•νƒœλ‘œ λ³€μˆ˜ μ „λ‹¬ν•˜μ—¬ μΉ˜ν™˜
- const resultDoc = await templateDoc.fillTemplateJson(
- JSON.stringify(templateData)
- )
-
- console.log("πŸ’Ύ κ²°κ³Ό 파일 μ €μž₯ 쀑...")
- // μž„μ‹œ 파일둜 μ €μž₯
- await resultDoc.save(tempOutputPath, PDFNet.SDFDoc.SaveOptions.e_linearized)
-
- console.log("βœ… λ³€μˆ˜ μΉ˜ν™˜ μ™„λ£Œ")
-
- // 파일 읽기
- const buffer = await fs.readFile(tempOutputPath)
-
- return {
- success: true,
- buffer: Buffer.from(buffer),
- }
- } finally {
- // μž„μ‹œ 파일 정리
- await cleanup()
+ // ν…œν”Œλ¦Ώ λ‘œλ“œ 및 λ³€μˆ˜ μΉ˜ν™˜
+ console.log("πŸ“„ ν…œν”Œλ¦Ώ λ‘œλ“œ 쀑...")
+ const templateDoc = await PDFNet.Convert.createOfficeTemplateWithPath(
+ templateFilePath
+ )
+
+ console.log("πŸ”„ λ³€μˆ˜ μΉ˜ν™˜ 쀑...")
+ // JSON ν˜•νƒœλ‘œ λ³€μˆ˜ μ „λ‹¬ν•˜μ—¬ μΉ˜ν™˜
+ const resultDoc = await templateDoc.fillTemplateJson(
+ JSON.stringify(templateData)
+ )
+
+ console.log("πŸ’Ύ λ©”λͺ¨λ¦¬ λ²„νΌλ‘œ μ €μž₯ 쀑...")
+ // λ©”λͺ¨λ¦¬μ—μ„œ 직접 버퍼 κ°€μ Έμ˜€κΈ° (μž„μ‹œ 파일 λΆˆν•„μš”)
+ const buffer = await resultDoc.saveMemoryBuffer(
+ PDFNet.SDFDoc.SaveOptions.e_linearized
+ )
+
+ console.log("βœ… λ³€μˆ˜ μΉ˜ν™˜ 및 PDF 생성 μ™„λ£Œ")
+
+ return {
+ success: true,
+ buffer: Buffer.from(buffer),
}
}, process.env.NEXT_PUBLIC_PDFTRON_SERVER_KEY)
@@ -192,7 +180,7 @@ export async function generateCoverPage(
}
// 7. 파일λͺ… 생성
- const fileName = `${docNumber}_cover.docx`
+ const fileName = `${docNumber}_cover.pdf`
console.log(`βœ… μ»€λ²„νŽ˜μ΄μ§€ 생성 μ™„λ£Œ: ${fileName}`)