Created
September 11, 2020 05:29
-
-
Save Fitzy1293/bb9554d7e96b67e9769d5fffe9d02f77 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
''' | |
Converts files from the notetaking program I use to pdfs for sharing. | |
''' | |
import os, sys | |
import cairosvg | |
import img2pdf | |
from PIL import Image | |
def svgzToPDF(): | |
dir = os.getcwd() | |
svgzFname = sys.argv[1] | |
svgzPath = os.path.join(dir, svgzFname) | |
fnameNoType = svgzFname.split('.')[0] | |
pngPath = os.path.join(dir, f'{fnameNoType}.png') | |
cairosvg.svg2png(url=svgzPath, write_to=pngPath) | |
print(f'Converted {svgzPath} to {pngPath}') | |
image = Image.open(pngPath) | |
pdfBytes = img2pdf.convert(image.filename) | |
pdfPath = os.path.join(dir, f'{fnameNoType}.pdf') | |
file = open(pdfPath, 'wb+') | |
file.write(pdfBytes) | |
image.close() | |
file.close() | |
print(f'Converted {pngPath} to {pdfPath}') | |
os.remove(pngPath) | |
print(f'Removed {pngPath}') | |
svgzToPDF() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment