Save PDF with merged annotations

88 views
Skip to first unread message

Emiliano Heyns

unread,
Sep 9, 2024, 3:33:54 PMSep 9
to zotero-dev
Is

await Zotero.PDFWorker.export("item key", "absolute path.pdf", true)

the correct way to save a PDF attachments with merged annotations?

Martynas Bagdonas

unread,
Sep 10, 2024, 2:57:59 AMSep 10
to zotero-dev
Yes, it just exports the PDF file with all its annotations that you can see in Zotero Reader. And it's the same as doing File → Save As…

Although the first argument isn't "item key", it's itemID so you need to firstly get the id:
let item = Zotero.Items.getByLibraryAndKey(libraryID, key);
let itemID = item.id;

Emiliano Heyns

unread,
Sep 10, 2024, 4:49:31 AMSep 10
to zotero-dev
With this

const key="....";
const libraryID=...;
const dest="..."

const item = Zotero.Items.getByLibraryAndKey(libraryID, key)
await Zotero.PDFWorker.export(item.id, dest, true)

I get

Error: No arguments provided\nError: No arguments provided
Zotero.DataObjects.prototype.getAsync<@chrome://zotero/content/xpcom/data/dataObjects.js:158

Martynas Bagdonas

unread,
Sep 10, 2024, 5:28:31 AMSep 10
to zotero-dev
Most likely libraryID or key isn't correct. Check Zotero.Items.getByLibraryAndKey result.

Emiliano Heyns

unread,
Sep 10, 2024, 7:42:28 AMSep 10
to zotero-dev
You're right, that is null. But here's what I'm doing:

I fetch an attachment by its key via the local API


I get an attachment object back with result.library.id and result.data.key ( = <key> )

I use those in Zotero.Items.getByLibraryAndKey(result.library.id, result.data.key)

and then I get null back.

So what am I doing wrong?

XY Wong

unread,
Sep 10, 2024, 9:22:11 AMSep 10
to zotero-dev
It's not a good idea to call local APIs within Zotero and the ability to call local APIs from plugin code can be disabled in the future.

For performance reasons, if you want to retrieve the item data inside a worker, it's better to write a proxy for the specific methods.


Emiliano Heyns

unread,
Sep 10, 2024, 9:32:40 AMSep 10
to zotero-dev
> It's not a good idea to call local APIs within Zotero

I am not, in fact, calling the local API from within Zotero.

> and the ability to call local APIs from plugin code can be disabled in the future.

I also do not want to retrieve the item data inside a worker. Cool idea though. I don't see the benefit to disabling this, but that's not my call to make.

I am calling the local API from outside Zotero. There's a few things which I can't (yet) do via the local API (like writes, but also in this case rendering annotations onto a PDF) and I'm augmenting those through code ran through debug bridge. But I keep to the local API for anything it can do that I need.

I still don't know why I'm getting null back, unless the library.id I'm getting back from the API is not the libraryID.

Dan Stillman

unread,
Sep 10, 2024, 9:32:53 AMSep 10
to zoter...@googlegroups.com
On 9/10/24 9:22 AM, XY Wong wrote:
> It's not a good idea to call local APIs within Zotero and the ability
> to call local APIs from plugin code can be disabled in the future.

To be clear, this is specifically about the local HTTP API. There's no
reason to be calling that from within Zotero — that's entirely for
external applications. (In addition to the unnecessary overhead, it's
disabled by default. Are you force-enabling that from within BBT? Please
don't do that.)

Emiliano Heyns

unread,
Sep 10, 2024, 9:36:36 AMSep 10
to zotero-dev
I'm not doing any of these things.

Emiliano Heyns

unread,
Sep 10, 2024, 9:42:12 AMSep 10
to zotero-dev
This doesn't involve BBT at all AAMOF

XY Wong

unread,
Sep 10, 2024, 9:42:57 AMSep 10
to zoter...@googlegroups.com
Then that’s fine, sorry for the misunderstanding.

--
You received this message because you are subscribed to a topic in the Google Groups "zotero-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/zotero-dev/nbgm7uQxnYk/unsubscribe.
To unsubscribe from this group and all its topics, send an email to zotero-dev+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zotero-dev/7660f613-7031-4cd8-84a1-f5d7a06d0f4an%40googlegroups.com.

Emiliano Heyns

unread,
Sep 10, 2024, 10:51:14 AMSep 10
to zotero-dev
Cool, but I still don't know what I'm doing wrong in the Zotero.Items.getByLibraryAndKey call.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages