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
pip install fastapi uvicorn reportlab pydantic fonttools httpx
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
uvicorn app:app --host 0.0.0.0 --port 8000
./gradlew bootRun
-
Python(FastAPI) 서비스 기동
uvicorn app:app --host 0.0.0.0 --port 8000
-
Spring Boot 기동
./gradlew bootRun
-
브라우저 접속
- URL: http://localhost:8080/contracts/new
- 계약 입력 → 저장 → 상세 페이지 이동
-
PDF 생성 & 다운로드
- “PDF 생성 & 다운로드” 링크 클릭
- Spring Boot → Python 서비스 호출 → PDF 자동 생성 및 다운로드
PDF에는 아래 항목이 포함됩니다:
- 계약 ID (UUID)
- 당사자 A / B 이름
- 계약 시작일, 종료일
- 계약 조항(Terms & Conditions)
- 서명란(Signature Area)
-
Windows:
C:\Windows\Fonts\malgun.ttf
,malgunbd.ttf
사용
-
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 다이어그램 섹션도 추가해드릴 수 있습니다.
추가해드릴까요?