# Basic Printing Support: how to print notes from oldest to newest?

**URL:** <https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189>\
**Category:** Add-ons\
**Created:** [September 17, 2022, 3:24am UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189 "2022-09-17T03:24:03Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elias](https://avatars.discourse-cdn.com/v4/letter/e/41988e/32.png) [@elias](https://forums.ankiweb.net/u/elias)\
**Post date:** [September 17, 2022, 3:24am UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/1 "2022-09-17T03:24:03Z")

</div>

Hi I’m using this addon and loving but it seems that it sorts the cards alphabetically using the first letter of a field

 ![image](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/2X/4/41f32ef220ba6644793edcc482386c6e3a45b62b.png)

(I made this real card days ago. today I made 26 cards from A to Z just to check it)

So I need to sort the cards from old to new bc I study and do the cards right from books and this way I preserve the following of a content and I can print instead of doing a review material

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [September 17, 2022, 8:29am UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/2 "2022-09-17T08:29:35Z")

</div>

Someone recently asked me to modify the add-on to do the same. Here is the updated package:

> **[Gofile - Free file sharing and storage platform](https://gofile.io/d/gJ3UMr)**
>
> Gofile is a free file sharing and storage platform. You can store and share your content of any type without any limit.

---

<div class="post-metadata">

**Author:** ![abdo](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/abdo/32/654_2.png) [@abdo](https://forums.ankiweb.net/u/abdo)\
**Post date:** [May 14, 2024, 5:45pm UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/4 "2024-05-14T17:45:59Z")

</div>

Here’s an updated link:

> **[print.ankiaddon](https://drive.google.com/file/d/1guN9EIM0Ctjt7LKUvqy0j4q1iDxTt7gj/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

**Author:** ![V-LK](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/v-lk/32/23768_2.png) [@V-LK](https://forums.ankiweb.net/u/V-LK)\
**Post date:** [October 1, 2024, 2:12pm UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/5 "2024-10-01T14:12:04Z")

</div>

Hi, I’m getting this error message when trying to use the print.ankiaddon. I’m using Anki 23.10.1

```auto
Traceback (most recent call last):
  File "C:\Users\...\print\ __init__.py", line 32, in onPrint
    QStandardPaths.writableLocation(QStandardPaths.DesktopLocation), "print.html"
AttributeError: type object 'QStandardPaths' has no attribute 'DesktopLocation'

```

---

<div class="post-metadata">

**Author:** ![dae](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/dae/32/65_2.png) [@dae](https://forums.ankiweb.net/u/dae)\
**Post date:** [October 2, 2024, 1:29pm UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/6 "2024-10-02T13:29:39Z")

</div>

Did you update the add-on to the latest version?

---

<div class="post-metadata">

**Author:** ![katanki](https://avatars.discourse-cdn.com/v4/letter/k/4af34b/32.png) [@katanki](https://forums.ankiweb.net/u/katanki)\
**Post date:** [October 24, 2024, 4:42pm UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/7 "2024-10-24T16:42:45Z")

</div>

Has anyone tried this recently? Im copying the new update into the python file and then when i go to print it tells me theres a problem with my add on

---

<div class="post-metadata">

**Author:** ![Danika\_Dakika](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/danika_dakika/32/17815_2.png) [@Danika\_Dakika](https://forums.ankiweb.net/u/Danika_Dakika)\
**Post date:** [October 25, 2024, 9:50pm UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/8 "2024-10-25T21:50:31Z")

</div>

What new update? And what files are you copying where? This add-on should automatically prompt you for an update when one is available.

---

<div class="post-metadata">

**Author:** ![Bon252vn](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Bon252vn](https://forums.ankiweb.net/u/Bon252vn)\
**Post date:** [October 26, 2024, 2:18am UTC](https://forums.ankiweb.net/t/basic-printing-support-how-to-print-notes-from-oldest-to-newest/23189/9 "2024-10-26T02:18:01Z")

</div>

Maybe you can try this, replace the code in " **init**.py" file:

import os  
import re

from anki.cards import CardId  
from anki.decks import DeckId  
from anki.utils import ids2str  
from aqt import mw  
from aqt.qt import \*  
from aqt.utils import openLink

config = mw.addonManager.getConfig( **name** )

def sortedCids(did: DeckId) → list[CardId]:  
dids = [did]  
for name, id in mw.col.decks.children(did):  
dids.append(id)  
return mw.col.db.list(  
“”"  
select c.id from cards c where did in %s order by c.id"“”  
% ids2str(dids)  
)

def onPrint():  
path = os.path.join(  
QStandardPaths.writableLocation(QStandardPaths.StandardLocation.DesktopLocation),  
“print.html”,  
)

```
try:
    did = mw.col.decks.current()["id"] # Get current deck ID
    ids = sortedCids(did)
except Exception as e:
    QMessageBox.information(None, "Error", f"Could not retrieve deck ID: {str(e)}")
    return

def esc(s: str) -> str:
    # Remove repeated question in answer if exists
    s = re.sub(r"\[\[type:[^]]+\]\]", "", s) # Remove type answer
    return s

buf = open(path, "w", encoding="utf8")
buf.write("<html><head>" + '<meta charset="utf-8">' + mw.baseHTML() + "</head><body>")
buf.write(
    """<style>

```

img { max-width: 100%; }  
tr { page-break-inside:avoid; page-break-after:auto }  
td { page-break-after:auto; }  
td { border: 1px solid #ccc; padding: 1em; }  
.playImage { display: none; }

“”"  
)  
first = True

```
mw.progress.start(immediate=True)
for j, cid in enumerate(ids):
    if j % config.get("cardsPerRow", 2) == 0: # Default to 2 if config is missing
        if not first:
            buf.write("</tr>")
        else:
            first = False
        buf.write("<tr>")
    
    c = mw.col.get_card(cid)
    qatxt = c.render_output(True, False).answer_text
    qatxt = mw.prepare_card_text_for_display(qatxt)
    cont = '<td width="{1}%"><center>{0}</center></td>'.format(
        esc(qatxt), 100 / config["cardsPerRow"]
    )
    buf.write(cont)
    
    if j % 50 == 0:
        mw.progress.update(f"Cards exported: {j + 1}")
buf.write("</tr>")
buf.write("</table></body></html>")
mw.progress.finish()
buf.close()
openLink(QUrl.fromLocalFile(path))

```

# Add action to menu

q = QAction(mw)  
q.setText(“Print”)  
q.setShortcut(QKeySequence(“Shift+P”))  
mw.form.menuTools.addAction(q)  
q.triggered.connect(onPrint)
