« [perl]リダイレクト | トップページ | [perl]リダイレクト »

[Python]SVGをPDFに変換する

ダウンロード - svg2pdf.zip

#!/usr/bin/env python3


from svglib.svglib import svg2rlg

from reportlab.graphics import renderPDF, renderPM

import sys

import os


args = sys.argv


strFilePath = args[1]

strFileDir = os.path.dirname(strFilePath)

strFileName = os.path.basename(strFilePath)

strBaseFileName = os.path.splitext(os.path.basename(strFilePath))[0]



print("strFilePath:" + strFilePath)

print("strFileDir:" + strFileDir)

print("strFileName:" + strFileName)

print("strBaseFileName:" + strBaseFileName)




drawing = svg2rlg(strFilePath)

renderPDF.drawToFile(drawing,strFileDir + "/" + strBaseFileName + ".pdf")




#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


property refMe : a reference to current application

##設定項目
set strPyFileName to "svg2pdf.py"

###パス取得
set aliasPathToMe to path to me as alias
tell application "Finder"
set aliasPathToMeContainerDir to container of aliasPathToMe as alias
end tell
###パスを生成
set strPathToMeContainerDir to POSIX path of aliasPathToMeContainerDir as text
set strBinPath to strPathToMeContainerDir & "bin/" as text
set strPyPath to strBinPath & strPyFileName as text
####ダイアログ用デスクトップパス
set aliasDefaultLocation to path to desktop folder from user domain as alias
####ダイアログ
set listChooseFiles to (choose file with prompt "ファイルを選んでください" default location aliasDefaultLocation of type {"public.svg-image"} with invisibles and multiple selections allowed without showing package contents) as list

####ファイルの数だけ繰り返し
repeat with objFile in listChooseFiles
###UNIXパスに変換
set theFilePath to POSIX path of objFile as text
###スクリプトに渡す
set strCommandText to "'" & strPyPath & "' '" & theFilePath & "'" as text
do shell script strCommandText

end repeat

|

« [perl]リダイレクト | トップページ | [perl]リダイレクト »

Python」カテゴリの記事

Acrobat python」カテゴリの記事

XML SVG」カテゴリの記事