DevOps
  • Introduction
  • Setting
    • Terminal
      • Tmux
    • WSL+Ubuntu
    • [NeoVIM]
      • install & 활용방법
      • error 처리
      • LazyVIM
        • install & 활용방법
    • ssh
    • mysql
    • package관리
  • Fundamental(basic)
    • Network
      • https
  • [GitOps]
    • [SCM]
      • [Github]
        • center-managed
      • bitbucket
      • AWS-codeCommit
  • roadmap
    • devops
    • kubernetes
    • AWS
    • MLOPS
  • Cloud
    • [AWS]
      • aws sso script
      • tagging 자동화
      • 동일cidr에서 VPC 연결
      • 무중단서비스를 위한 고려사항
    • [GCP]
      • [GCP] GCP의 VPC
      • [GCP] GCP의 ALB
      • [GCP] OIDC와 OAUTH를 활용한 github action
      • [GCP] Composer 설명
      • [GCP] gmail-api
      • [GCP] DataLake
      • [GCP] Cloud 관리형 계정&role
      • [[GCP] private환경
        • DNS 설정으로 google api 및 colab-notebook 사용 하기
        • intelligence 설정으로 google api 및 colab-notebook 사용 하기
  • [kubernetes]
    • [cloud 기반]
      • csr
  • InfraAsCode
    • terraform
  • 코드로 그리는 다이어그램
    • CodeAsDiagram
      • example
    • Mermaid
    • PDFtoImage
  • AutoMation
  • [ETC]
    • Magic_Trackpad Window설치
Powered by GitBook
On this page
  1. 코드로 그리는 다이어그램

PDFtoImage

pdf 파일 다운로드

wget https://roadmap.sh/pdfs/roadmaps/kubernetes.pdf

pdf2image 설치(pip)

pip install pdf2image

예제 코드

import sys
from pdf2image import convert_from_path
import os
from datetime import datetime

# 커맨드 라인 인자 확인
if len(sys.argv) < 2:
    print("사용법: python3 convert.py <PDF 파일 경로>")
    sys.exit(1)

# PDF 파일 경로 (커맨드 라인 인자로부터)
pdf_path = sys.argv[1]

# PDF 파일 이름에서 확장자 제거 (.pdf 제거)
base_name = os.path.splitext(pdf_path)[0]

# 이미지를 저장할 디렉토리 설정
image_dir = './img'
if not os.path.exists(image_dir):
    os.makedirs(image_dir)
    print(f'{image_dir} 디렉토리가 생성되었습니다.')

# PDF를 이미지 리스트로 변환
images = convert_from_path(pdf_path)

# 이미지를 개별 파일로 저장하면서 파일 이름을 PDF 파일 이름에 기반하여 설정
for i, image in enumerate(images):
    image_filename = os.path.join(image_dir, f'{base_name}.png')
    # 파일이 이미 존재하는 경우 백업
    if os.path.exists(image_filename):
        timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
        backup_filename = os.path.join(image_dir, f'{base_name}_{timestamp}.png')
        os.rename(image_filename, backup_filename)
        print(f'{image_filename} 파일이 {backup_filename}로 백업되었습니다.')
    
    image.save(image_filename, 'PNG')
    print(f'{image_filename} 저장 완료.')
PreviousMermaidNextAutoMation

Last updated 1 year ago