# How to Import a PDF into Anki with Pages Alternating as Card Fronts and Backs?

**URL:** <https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542>\
**Category:** Help\
**Created:** [November 30, 2024, 3:10am UTC](https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542 "2024-11-30T03:10:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![spencbrady](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/spencbrady/32/25187_2.png) [@spencbrady](https://forums.ankiweb.net/u/spencbrady)\
**Post date:** [November 30, 2024, 3:10am UTC](https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542/1 "2024-11-30T03:10:40Z")

</div>

I bought a flashcard set in PDF format, and I want to import it into Anki. Is there a way to make Anki automatically create cards where the first page of the PDF is the front of the first card, the second page is the back of the first card, the third page is the front of the second card, the fourth page is the back of the second card, and so on?

---

<div class="post-metadata">

**Author:** ![jhhr](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/jhhr/32/21339_2.png) [@jhhr](https://forums.ankiweb.net/u/jhhr)\
**Post date:** [December 1, 2024, 1:30pm UTC](https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542/3 "2024-12-01T13:30:19Z")

</div>

There isn’t a way to make _Anki_ do the conversion from PDF to Anki notes. It should be possible to write a script to process the PDF into an appropriately structured .txt file which can then be imported into Anki to make Anki notes.

If you know / are willing to learn some python coding, then it can be done.

> **[Working with PDF files in Python - GeeksforGeeks](https://www.geeksforgeeks.org/python/working-with-pdf-files-in-python/)**
>
> Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and...

> **[How to Write Your First Python Script Like a Pro](https://beapython.dev/2019/12/23/writing-your-first-python-script/)**
>
> Written by: Stefan Bradstreet When it comes to learning to code, Python is one of the easiest coding languages to start with since it resembles standard English. It’s also an interpreted lang…

* * *

## This should get you started

The .txt export/import format is fairly simple: each column on a row corresponds to a note field. If you have two note fields, _Front_ and _Back_, then txt import file would look like this (using tab char as a separator):

```auto
#separator:tab
#html:true
note1frontcontent	note1backcontent
note2frontcontent	note2backcontent
....
etc.

```

Then the script would do something like

```python
from pypdf import PdfReader

csv_file = open('anki_cards_import.txt', 'w')

# Add header info that Anki will read
csv_file.write("#separator:tab\n#html:true\n")

# creating a pdf reader object
reader = PdfReader('your_purchased_flashcards.pdf')
page_count = len(reader.pages)

# assuming the total page_count is even, we want to process the pages in pairs
for i in range(0, page_count, 2):
    # creating a page object
    page1 = reader.pages[i]
    page2 = reader.pages[i+1]

    # extracting text from first and second page
    page1content = page1.extract_text()
    page2content = page2.extract_text()

    # write contents to a new line in the csv
    csv_file.write(f"{page1content}\t{page2content}\n")

csv_file.close()

```

---

<div class="post-metadata">

**Author:** ![ccscanf](https://sea2.discourse-cdn.com/flex002/user_avatar/forums.ankiweb.net/ccscanf/32/7792_2.png) [@ccscanf](https://forums.ankiweb.net/u/ccscanf)\
**Post date:** [December 1, 2024, 5:45pm UTC](https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542/4 "2024-12-01T17:45:42Z")

</div>

Hey there,

Yes, you can use [2anki.net](https://2anki.net) for that as of today! I’ve seen this question pop up several times on the forum, so I couldn’t resist hacking something together and replying.

Just upload your PDF, and it’ll generate PNG images for the front and back of your cards as basic notes. I chose PNG because it ensures pixel-perfect accuracy, which is great for keeping everything looking exactly like the original.

If PNGs don’t work for you, you can copy the code here and tweak the approach yourself:  
[GitHub Code](https://github.com/2anki/server/blob/c66b02f1bd52cb10d26054d308efcbe5227a7266/src/lib/parser/pdf/convertPDFToImages.ts#L94).

Hope that helps! Let us know how it goes 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex002/uploads/anki2/original/1X/8f1279ababc5879d54e4838989f606cfe55af8c7.jpeg) [@system](https://forums.ankiweb.net/u/system)\
**Post date:** [January 2, 2025, 8:54am UTC](https://forums.ankiweb.net/t/how-to-import-a-pdf-into-anki-with-pages-alternating-as-card-fronts-and-backs/52542/6 "2025-01-02T08:54:49Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
