How to create thousands of notes corresponding to (and linked to) thousands of PDF-files

I have thousands of papers as PDF-files (all named: Author, Title.PDF) which I would like to organize (with lots of tags) in Obsidian. I therefore would like to have a note in obsidian for each PDF-file (and linked to the PDF-file). Is there a way to accomplish this, to automatically import PDFs as/into linked notes (with the same name as the PDFs)?

1 Like

Here is my hacky workaround. It’s a lot; but, since you are working with thousands of files, as long as it gets the job done, it’s worth it.

You could first add all the PDFs into a folder in your vault. Then select them all and drag and drop them into an empty note to create a list of embeds to the PDFs. Then, you can search and replace the document, replacing ![[ with [[. Now you just have a list of links to your PDFs. Assuming that this is all you want inside each of the notes, you can proceed to copy and paste the entire list into another note and search and replace .pdf]] with ]].

Now you have one list of all the links to the notes you want to create and another note listing all the links you want inside their respective notes. Next, cut and paste one of the lists below the other list in a single note. Now copy and paste this list into a spreadsheet application and sort it alphabetically, using the descending option which will sort it from z to a. The important thing is that the link without the .pdf at the end comes before the one that has the .pdf.

Now copy and paste unformatted (ctrl shift v) into an empty note in Obsidian. Select all and press ctrl Enter, which should append a - [ ] at the beginning of each line. Now, cut and paste the entire note into an empty file in VSCode. Choose Edit>Replace and enable Regular Expressions by clicking the little asterisk within the find field. Add the following expression in the find field - \[ \] \[\[(.*.pdf)\]\] and in the replace field add [[$1]] and click the Replace All icon.

Now, change the find field to be - \[ \] \[\[(.*)\]\] and the replace field to be ### $1 and click Replace All. Next select all, and copy and paste the text into a note in Obsidian. Now, enable the Note Refactor plugin and run the command to Split note by headings- H3.

Let me know if you need any additional information. I just tested this and it worked fine for me. Hopefully I didn’t make any typos here. Good luck!

A shell script like this should work when run in a folder of PDFs on MacOS or Linux (or Windows with Windows Subsystem For Linux):

for f in ./*.pdf; do
    # Strip extension from filename
    name=$(basename "$f" | sed -E 's/(.+)\.pdf$/\1/')
    # Put link to PDF in corresponding note
    echo "[[$name.pdf]]" > "$name".md
    # Add to list of links to notes (and PDFs) in a note named "PDFs"
    echo "- [[$name]] ([[$name.pdf]])" >> "PDFs.md"
done

The first word of the second-to-last and fourth-to-last lines, which the syntax highlighting has made nearly invisible, is echo.

Obviously test it on a copy or a subset of a copy first, just to be safe. I tested it on a pair of PDFs.

1 Like

thanks for the awesome information.

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