Skip to content

loopwhile/study-springboot-python-pdf

Repository files navigation

🧾 Spring Boot + FastAPI PDF 계약서 생성 프로젝트

Spring Boot(백엔드)와 Python FastAPI(서브서비스)를 연동하여
계약 정보를 PDF로 자동 생성·다운로드하는 예제 프로젝트입니다.


⚙️ 개발 환경

구분 기술 스택
Backend Spring Boot 3.x, Java 21, JPA, MariaDB
Sub Service FastAPI, ReportLab (Python 3.10+)
Template Thymeleaf
빌드 도구 Gradle
DB 설정 application.properties 에서 변경 가능

🗂️ 프로젝트 구조

```markdown

src/
├─ main/
│   ├─ java/com/pdf/python/
│   │   ├─ config/           # WebClientConfig, PythonPdfClient
│   │   └─ domain/contract/
│   │       ├─ controller/   # ContractController
│   │       ├─ dto/          # ContractRequest
│   │       ├─ entity/       # Contract, ContractId
│   │       ├─ repository/   # ContractRepository
│   │       └─ service/      # ContractService
│   └─ resources/
│       ├─ templates/        # contract_form.html, contract_detail.html
│       └─ application.properties
├─ build.gradle
└─ settings.gradle


🔧 FastAPI 의존성 설치

pip install fastapi uvicorn reportlab pydantic fonttools httpx

⚙️ application.properties 예시

spring.datasource.url=jdbc:mariadb://localhost:3306/contractdb
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

pdf.python.base-url=http://localhost:8000
server.port=8080

🧠 Python(FastAPI) 서버 실행 명령어

uvicorn app:app --host 0.0.0.0 --port 8000

☕ Spring Boot 서버 실행 명령어

./gradlew bootRun

🚀 10) 동작 순서

  1. Python(FastAPI) 서비스 기동

    uvicorn app:app --host 0.0.0.0 --port 8000
  2. Spring Boot 기동

    ./gradlew bootRun
  3. 브라우저 접속

  4. PDF 생성 & 다운로드

    • “PDF 생성 & 다운로드” 링크 클릭
    • Spring Boot → Python 서비스 호출 → PDF 자동 생성 및 다운로드

✅ 결과 예시

PDF에는 아래 항목이 포함됩니다:

  • 계약 ID (UUID)
  • 당사자 A / B 이름
  • 계약 시작일, 종료일
  • 계약 조항(Terms & Conditions)
  • 서명란(Signature Area)

🗎 한글 깨짐 시 해결 (ReportLab 폰트 등록)

  1. Windows:

    • C:\Windows\Fonts\malgun.ttf, malgunbd.ttf 사용
  2. Linux/Docker:

    • apt-get install fonts-noto-cjk
    • NotoSansKR-Regular.ttf 경로 등록
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont

pdfmetrics.registerFont(TTFont("KR-Regular", "/path/to/malgun.ttf"))
pdfmetrics.registerFont(TTFont("KR-Bold", "/path/to/malgunbd.ttf"))

🧩 라이선스

본 예제는 학습 및 포트폴리오용으로 자유롭게 사용할 수 있습니다.


---

원하신다면 이 `README.md`에  
📦 `requirements.txt`,  
📘 API 명세(Swagger 엔드포인트 예시),  
📄 ERD 다이어그램 섹션도 추가해드릴 수 있습니다.  
추가해드릴까요?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published