무료 tomdnow API로 파일을 마크다운으로 변환 자동화하기
무료 tomdnow API를 사용하여 PDF, DOCX, HWP 등 20개 이상의 형식을 프로그래밍 방식으로 마크다운으로 변환하세요. curl과 Python 예제를 포함합니다.
API로 마크다운 변환을 자동화하는 이유
웹 인터페이스에서 파일 하나를 변환하는 것은 쉽습니다. 하지만 500개의 PDF 보고서를 변환해야 한다면? 내부 시스템에 업로드되는 모든 문서를 자동으로 변환해야 한다면? 변환된 마크다운을 AI 도구에 직접 입력하는 파이프라인을 구축해야 한다면?
이때 tomdnow API가 필요합니다. 무료이고, 신용카드가 필요 없으며, 웹 인터페이스와 동일한 20개 이상의 파일 형식을 지원합니다. 무료 티어에서 하루 50회 변환이 가능합니다.
API 키 발급받기
변환 요청을 보내기 전에 API 키가 필요합니다. 단 한 번의 HTTP 요청으로 발급받을 수 있습니다:
curl -X POST https://api.tomdnow.com/api/v1/keys \
-H "Email: you@example.com"
응답에 API 키와 티어 정보가 포함됩니다:
{
"api_key": "tmd_abc123...",
"tier": "free",
"daily_limit": 50
}
API 키를 안전하게 보관하세요. 이후 모든 요청에 X-Api-Key 헤더로 포함해야 합니다.
curl로 파일 변환하기
변환 엔드포인트는 파일 업로드를 받아 마크다운 콘텐츠와 메타데이터를 반환합니다. 기본 예제입니다:
curl -X POST https://api.tomdnow.com/api/v1/convert \
-H "X-Api-Key: tmd_your_api_key" \
-F "file=@document.pdf"
응답에는 변환된 마크다운과 파일 메타데이터가 포함됩니다:
{
"markdown": "# 문서 제목\n\n변환된 내용...",
"metadata": {
"title": "document",
"type": "pdf",
"size": 102400
},
"api_usage": {
"tier": "free",
"daily_remaining": 49
}
}
파일만 변경하면 지원되는 모든 형식을 변환할 수 있습니다. API가 파일 유형을 자동으로 감지합니다:
# Word 문서 변환
curl -X POST https://api.tomdnow.com/api/v1/convert \
-H "X-Api-Key: tmd_your_api_key" \
-F "file=@report.docx"
# 한글(HWP) 문서 변환
curl -X POST https://api.tomdnow.com/api/v1/convert \
-H "X-Api-Key: tmd_your_api_key" \
-F "file=@공문서.hwp"
# Excel 스프레드시트 변환
curl -X POST https://api.tomdnow.com/api/v1/convert \
-H "X-Api-Key: tmd_your_api_key" \
-F "file=@data.xlsx"
Python으로 파일 변환하기
더 복잡한 워크플로우에는 requests 라이브러리를 사용하는 Python이 자연스럽습니다. 단일 파일을 변환하는 함수입니다:
import requests
API_KEY = "tmd_your_api_key"
API_URL = "https://api.tomdnow.com/api/v1/convert"
def convert_to_markdown(file_path: str) -> str:
"""tomdnow API를 사용하여 파일을 마크다운으로 변환합니다."""
with open(file_path, "rb") as f:
response = requests.post(
API_URL,
headers={"X-Api-Key": API_KEY},
files={"file": f},
)
response.raise_for_status()
return response.json()["markdown"]
# 사용법
markdown = convert_to_markdown("report.pdf")
print(markdown)
여러 파일 일괄 처리
API의 진정한 힘은 일괄 변환에 있습니다. 디렉토리의 모든 파일을 변환하고 마크다운으로 저장하는 Python 스크립트입니다:
import os
import requests
from pathlib import Path
API_KEY = "tmd_your_api_key"
API_URL = "https://api.tomdnow.com/api/v1/convert"
SUPPORTED = {
".pdf", ".docx", ".pptx", ".xlsx", ".xls",
".hwp", ".hwpx", ".html", ".epub", ".csv",
".json", ".xml", ".msg", ".ipynb", ".rtf", ".txt",
}
def convert_file(file_path: str) -> str:
"""단일 파일을 변환하고 마크다운 콘텐츠를 반환합니다."""
with open(file_path, "rb") as f:
resp = requests.post(
API_URL,
headers={"X-Api-Key": API_KEY},
files={"file": f},
)
resp.raise_for_status()
return resp.json()["markdown"]
def batch_convert(input_dir: str, output_dir: str):
"""input_dir의 모든 지원 파일을 마크다운으로 변환합니다."""
os.makedirs(output_dir, exist_ok=True)
for file_path in Path(input_dir).iterdir():
if file_path.suffix.lower() not in SUPPORTED:
continue
print(f"변환 중: {file_path.name}")
try:
markdown = convert_file(str(file_path))
out_path = Path(output_dir) / f"{file_path.stem}.md"
out_path.write_text(markdown, encoding="utf-8")
print(f" 저장됨: {out_path.name}")
except requests.HTTPError as e:
print(f" 오류: {e}")
# ./documents/의 모든 파일을 ./markdown/으로 변환
batch_convert("./documents", "./markdown")
이 스크립트는 입력 디렉토리의 지원되는 모든 파일을 처리하고 마크다운 출력을 별도 폴더에 저장합니다. 지원되지 않는 파일 형식을 건너뛰고 오류를 우아하게 처리합니다.
통합 아이디어
API 접근 권한이 생기면 파일-마크다운 변환을 워크플로우에 통합하는 실용적인 방법을 소개합니다.
CI/CD 파이프라인
CI 파이프라인에 변환 단계를 추가합니다. 누군가 PDF나 Word 문서를 저장소에 커밋하면 자동으로 마크다운으로 변환하고 결과를 커밋합니다:
# CI 스크립트에서
for file in docs/sources/*.pdf; do
md_file="docs/generated/$(basename "$file" .pdf).md"
curl -s -X POST https://api.tomdnow.com/api/v1/convert \
-H "X-Api-Key: $TOMDNOW_API_KEY" \
-F "file=@$file" | jq -r '.markdown' > "$md_file"
done
Obsidian 가져오기 스크립트
폴더의 새 문서를 감시하고 자동으로 Obsidian 볼트로 변환하는 스크립트를 구축합니다:
import time
from pathlib import Path
from watchdog.observers import Observer
from watchdog.events import FileCreatedHandler
class ConvertHandler(FileCreatedHandler):
def on_created(self, event):
if Path(event.src_path).suffix.lower() in SUPPORTED:
markdown = convert_file(event.src_path)
stem = Path(event.src_path).stem
out = Path("~/obsidian-vault/Imports") / f"{stem}.md"
out.expanduser().write_text(markdown)
observer = Observer()
observer.schedule(ConvertHandler(), "./watch-folder")
observer.start()
AI 파이프라인 전처리
AI API에 입력하기 전에 문서를 마크다운으로 변환합니다:
# 변환 후 OpenAI에 전송
markdown = convert_file("quarterly-report.pdf")
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o",
messages=[{
"role": "user",
"content": f"이 보고서를 요약해 주세요:\n\n{markdown}"
}],
)
print(response.choices[0].message.content)
속도 제한 및 모범 사례
- 무료 티어: 하루 50회 요청. 신용카드 불필요.
- 파일 크기 제한: 파일당 10MB.
- 일괄 스크립트에 지연을 추가하여 속도 제한 내에서 유지하세요. 요청 사이 1초 지연이면 충분합니다.
- 결과를 캐싱하여 같은 파일을 두 번 변환하지 마세요.
- 응답의
daily_remaining을 확인하여 사용량을 모니터링하세요.
tomdnow.com에서 무료 API 키를 발급받고 자동화를 시작하세요.