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:
browser:
Top:
bottom:
Thanks
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:
browser:
Top:
bottom:
Thanks
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.
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 __init__.py
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),
mw.col.decks.name(mw.col.decks.selected()) + ".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
.
IT WORKED, THANKS!
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):
import unicodedata
import re
def slugify(value, allow_unicode=False):
"""
Taken from https://github.com/django/django/blob/master/django/utils/text.py
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)
else:
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('-_')
path = slugify(os.path.join(
QStandardPaths.writableLocation(QStandardPath.DesktopLocation),
mw.col.decks.name(mw.col.decks.selected()) + ".html"
), True)
True
in False
(or just remove it) if you don’t want to keep non-ascii characters in file names.Hi, would you help me again with this? I had to install basic printing support again on another computer and I tried to do what you said, but I got this:
Traceback (most recent call last):
File “/Users/gabrieldias/Library/Application Support/Anki2/addons21/1025789669/init.py”, line 37, in onPrint
QStandardPaths.writableLocation(QStandardPaths.DesktopLocation),
AttributeError: type object ‘QStandardPaths’ has no attribute ‘DesktopLocation’
Can you help me to fix this? Thanks!