mgmeyers / obsidian-zotero-integration

Insert and import citations, bibliographies, notes, and PDF annotations from Zotero into Obsidian.
GNU General Public License v3.0
913 stars 50 forks source link

Importing annotations from multiple PDFs for the same entry #346

Closed MSHelm closed 1 month ago

MSHelm commented 4 months ago

Hi everyone, First of all, great plugin, I absolutely love it :)

For several papers I read, there is extensive information contained in Supplementary Materials. These usually come as a separate PDF file. I can assign both pdf's to the same entry in Zotero, but if I annotate something in the Supplementary file it is not imported into Zotero. I assume only the first file added to an entry is used. The Data Explorer also only shows information for the first PDF, no path or annotations for the second PDFs is shown.

Is there any way to import annotations for both PDFs into the same note in Zotero with a single Import command?

A potential workaround for me would be to concatenate the PDFs into one in an external tool and only then add it to Zotero.

FeralFlora commented 3 months ago

Yes, to do so, you have to access the annotations from the attachments array, rather than the annotations array, because the latter only contains the annotations in the first PDF.

Here's how I do it:

{% set allAnnotations = [] -%}
{% for attachment in attachments -%}
    {% if attachment.annotations | length > 0 -%}
        {% for annotation in attachment.annotations -%}
            {% set _ = allAnnotations.push(annotation) -%}
        {% endfor -%}
    {% endif -%}
{% endfor -%}

This collects all the annotations into one array.

nathancashion commented 3 months ago

Will this also work for existing Notes under the item? e.g. I had created a summary note in Zotero. Under Zotero 7 beta using this plug-in, the import would hang on Fetching Collections.

I tried again under Zotero 6 and the import completed, though it only pulled annotations from the PDF, not from the note.

MSHelm commented 1 month ago

Thanks a lot @FeralFlora that works brilliantly for me

FeralFlora commented 1 month ago

I'm glad to hear that, @MSHelm :)