Basic Printing Support file identification

Guys, is there a way to make Basic Printing support identify the files with the name of the deck? It always exports my decks with the same identification:






The header/footer is added by your browser, and can be turned off in the printing screen. If you want something other than ‘print.html’, you could rename the file before printing it.

1 Like

Thanks! Is there field to do this in the extension config?

Nope, but you can modify the source code off the add-on to achieve this. You can access the file by opening Anki, then navigating to Tools -> Add-ons -> Select 'Basic Printing Support' -> View Files.

Next, open the file in a text editor of your choice. Replace the line(s):

path = os.path.join(
    QStandardPaths.writableLocation(QStandardPaths.DesktopLocation), "print.html"

With the following:

path = os.path.join(
    QStandardPaths.writableLocation(QStandardPaths.DesktopLocation), + ".html"

Save the file and exit. When you restart anki the add-on will be updated, and each file will be named {deck_name}.html.



1 Like

This is a bit risky as-is, because you could create file names that could be invalid. Here is a snippet taken from Django’s slugifying module (which is rather conservative):

  • Add at the top of the file this
import unicodedata
import re

def slugify(value, allow_unicode=False):
    Taken from
    Convert to ASCII if 'allow_unicode' is False. Convert spaces or repeated
    dashes to single dashes. Remove characters that aren't alphanumerics,
    underscores, or hyphens. Convert to lowercase. Also strip leading and
    trailing whitespace, dashes, and underscores.
    value = str(value)
    if allow_unicode:
        value = unicodedata.normalize('NFKC', value)
        value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
    value = re.sub(r'[^\w\s-]', '', value.lower())
    return re.sub(r'[-\s]+', '-', value).strip('-_')
  • Transform the snippet in
path = slugify(os.path.join(
    QStandardPaths.writableLocation(QStandardPath.DesktopLocation), + ".html"
), True)
  • Transform the last True in False (or just remove it) if you don’t want to keep non-ascii characters in file names.