Skip to content

Instantly share code, notes, and snippets.

@Fitzy1293
Created September 11, 2020 05:29
Show Gist options
  • Save Fitzy1293/bb9554d7e96b67e9769d5fffe9d02f77 to your computer and use it in GitHub Desktop.
Save Fitzy1293/bb9554d7e96b67e9769d5fffe9d02f77 to your computer and use it in GitHub Desktop.
#!/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