/leb2code-pdf

Automatic convert python code files into pdf for KMUTT college students.

Primary LanguagePython

preview
Saving your time by automatic convert python code files into pdf files, for KMUTT college students.
LEB2 (Learning Environment version B2) https://www.leb2.org/

Installation

git clone https://github.com/monshinawatra/leb2code-pdf.git
cd leb2code-pdf
pip install -r requirements.txt

Quick start

Inference with leb2code.py

python leb2code.py "ชินวัตร นาไชยธง"      # Full name
                   "65090500408"        # KMUTT id
                   -d "lab5"            # Code files directory
                   -bg "Red (NCS)"      # Background color
                   -o "output/lab5.pdf  # Save path
                   -l                   # Show line number

Arguments parsing list
-h, --help show this help message and exit
-d <Dir>, --directory <Dir> Enter code directory
-k <Keyword>, --keyword <Keyword> Enter files keyword
-bg <Color>, --background_color <Color> Enter color name or Hex color code
-t <Theme>, --theme <Theme> Enter Color theme
-f <Font family>, --font <Font family> Enter font name (See all names in carbon exported config)
-s <Font size>, --font_size <Font size> Enter size of font
-l, --line_numbers Turn on/off line number
-w <Width (px)>, --width <Width (px)> Width of code snippets
-o <Path>, --save_path <Path> Enter path for save pdf

Inference in app.py arguments

Arguments Default Type Description
name (required) str Your full name. e.g. ชินวัตร นาไชยธง, Shinawatra Nachaithong
id (required) str Your KMUTT college students id. e.g. 65090500000
dir "./" str Your code directory.
language "Python" str Code language. 'python' by default and 'plain-text' for output image
keyword "lab" str All your unique code file name.
backgroundColor "Golden Poppy" str Background color. See all color names,
or you can use your custom HEX color code.
theme "Night Owl" str Color theme in code snippet.
fontFamily "Fira Code" str Font family, e.g. JetBrains Mono, Fira Code.
See all names in carbon exported config.
fontSize 16 int Just size of font in code snippets.
lineNumbers False bool Turn on/off line number
width 680 int Width of code snippets
save_path "demo.pdf" str Output path for pdf file.
paddingVertical "50px" str Vertical padding
paddingHorizontal "50px" str Horizontal padding

Results

Here it is result from carbon "Golden Poppy"
preview

Color and theme

Support themes
Zenburn Yeti VSCode Verminal Twilight SynthWave Solarized (Light) Solorarized (Dark) Shades of Purple Seti Paraiso Panda One Dark One Light Oceanic Next Nord Night Owl Monokai Material Lucario Hopscotch Duotine Cobalt Blackboard

Color Name You can uses these color as name, but if you don't like these colors, you can use your custom hex color code.

Color Name Color Name Color Name
preview "White" preview "Golden Poppy" preview "Teal"
preview "Silver" preview "Neon Orange" preview "Blue"
preview "Gray" preview "Bright Orange" preview "Sapphire Blue"
preview "Black" preview "Yellow" preview "Midnight Blue"
preview "Brown Chocolate" preview "Emerald Green" preview "Navy"
preview "Crimson" preview "Lime" preview "Purple"
preview "Violet Red" preview "Green" preview "Byzantium"
preview "Rose Red" preview "Aqua" preview "Pastel Pink"
preview "Red (NCS)" preview "Blue Green" preview "Pastel Red"
preview "Red" preview "Jade" preview "Salmon"
preview "Cinnamon" preview "Jungle Green" preview "Peach"
preview "Portland Orange" preview "Viridian"

Task

  • Main application.
  • Refactor our code.
  • Arguments parsing.
  • Beautify code snippets, layout, label in pdf file.

Reference

Carbon
Create and share beautiful images of your source code. https://carbon.now.sh/

Carbon API https://github.com/petersolopov/carbonara

PyFPDF
Free and open-source pure-python PDF library https://github.com/PyFPDF/fpdf2