zotero中总是找不到pdf,“无效或损坏的PDF文件”

BUG反馈 · 6268 次浏览
创建于 2023-01-15 12:11

1.

我使用的zotero是官方绿色版,你其他那几个动作可以成功运行,但是这个“一键看文献”出错,zotero中总是找不到pdf,zotero报错如下

 

2.

运行过程中,
之前旧的VBA版本好像是获得的:
Li et al., 2022|zotero://select/items/1_W7LTGIDT


现在运行C#代码得到的是这样的字符:
Li et al., 2022|128373

不知道报错是否和这个有关?

 

3.

这种改变是因为在zotero中运行下面代码无法达到效果,所以改变的吗?

$$
let AttachID=Zotero.Items.get({ItemID}).getAttachments();
if(AttachID.length!=0){
    let item=Zotero.Items.get(AttachID[0]);
    Zotero.Reader.open(item.id);
} else {
    ZoteroPane_Local.selectItem({ItemID});
    alert("没找到PDF文件,但已定位到该文献条目!");
}

 

4.

如果我仍然想获得“Li et al., 2022|zotero://select/items/1_W7LTGIDT”这样的字符串,C#那里应该怎么改啊?(我觉得"W7LTGIDT这种8位随机字母数字混合的比较通用一些,不知道现在为什么是 “128373”这种纯数字)

 

谢谢解惑


回复内容
ttChen 2023-01-16 19:06
#1

问题1:绿色版没测试过,可能存在问题;

问题2:对以前VBA版本,是通过调用zotero://select/items/ItemKey(key)链接打开的。电脑反应慢时,功能不太稳定

新版本是通过JAVAScript调用Zotero内部函数打开的,这串数字是条目的ID。ID的性能更高。

问题3:对,这个代码是通过调用条目的ID打开的,若条目存在附件,直接打开附件,若不存在附件,直接定位到条目;

问题4:可以c# VBA等解析Word域代码,利用JSON获得uri链接末尾部分的那段字符串,那段字符串就是ItemKey。

如http://zotero.org/users/1817658/items/BEJDTN25,后面的就是ItemKey

ttChen 最后更新于 2023-01-16 19:07
回复 ttChen 2023-01-16 19:13 :

原来如此,学到了,

不知道是否方便帮忙写一段获得 ItemKey 的 C# ,我是简单代码大概能看懂,稍微复杂点的,就搞不定了

回复 ttChen 2023-01-16 19:19 :

刚才测试了一下,“一键看文献”又能用了,难道是昨天更新zotero到 v6.0.20 的原因

Ps.我这个绿色版是官方的那个,还挺好用,但是如果想要调用 zotero://select/items/ItemKey(key) 的话,需要往注册表写个键

回复 ttChen 2023-01-16 19:36 :

还是有bug,不过我知道是什么原因了:有些条目附件有多个,则会按照如下顺序排序

笔记文件>html文件>pdf文件>超链接,不过也有出现超链接在pdf文件之前的,所以“AttachID[0]”中"0"可能需要改变:一般取最大值即可,即“AttachID.length”(PDF文件排在最后),但是代码我不会改,直接把“0”换为“AttachID.length”不行,是不是需要搞个中间数值变量?

最后更新于 2023-01-16 19:38
ttChen 回复 2023-01-16 21:14 :

判别一下文件类型,打开PDF文件即可。

回复 ttChen 2023-01-16 21:16 :

不会改代码,大佬你要更新吗?

ttChen 回复 2023-01-16 23:08 :

出差在外,等回来处理

回复 ttChen 2023-01-16 23:09 :

谢谢,期待

ttChen 回复 2023-01-20 15:46 :

新版本已修复该问题了。

回复 ttChen 2023-01-29 09:57 :

感谢,不过我还有两个问题需要请教一下


1. 现在的是获取条目的ID,性能更好,但是我需要获取 ItemKey ,是否方便帮忙写一段获得 ItemKey 的 C#?


2. 如果我想使用外部PDF阅读器打开PDF,那这段代码应该怎么改?


             Zotero.Reader.open(id);

ttChen 回复 2023-01-29 10:54 :

// FieldCode为获取到的域代码

string FieldCode="ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"3FIW7gOp\",\"properties\":{\"formattedCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"plainCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"noteIndex\":0},\"citationItems\":[{\"id\":1558,\"uris\":[\"http://zotero.org/users/1817658/items/WAJ2XKB5\"],\"itemData\":{\"id\":1558,\"type\":\"article-journal\",\"collection-title\":\"7.116\",\"container-title\":\"Biology and Fertility of Soils\",\"DOI\":\"10.1007/s00374-018-01338-3\",\"issue\":\"2\",\"language\":\"en-US\",\"note\":\"ISBN: 1432-0789\\npublisher: Springer\\nCitation Key: fungo2019Biol.Fertil.Soils\",\"page\":\"135-148\",\"title\":\"Ammonia and nitrous oxide emissions from a field Ultisol amended with tithonia green manure, urea, and biochar\",\"volume\":\"55\",\"author\":[{\"family\":\"Fungo\",\"given\":\"Bernard\"},{\"family\":\"Lehmann\",\"given\":\"Johannes\"},{\"family\":\"Kalbitz\",\"given\":\"Karsten\"},{\"family\":\"Thionģo\",\"given\":\"Margaret\"},{\"family\":\"Tenywa\",\"given\":\"Moses\"},{\"family\":\"Okeyo\",\"given\":\"Irene\"},{\"family\":\"Neufeldt\",\"given\":\"Henry\"}],\"issued\":{\"date-parts\":[[\"2019\"]]}}},{\"id\":1514,\"uris\":[\"http://zotero.org/users/1817658/items/FPWETRUL\"],\"itemData\":{\"id\":1514,\"type\":\"article-journal\",\"abstract\":\"Climate change continues to have a great impact on rice production in China, especially in Northeast China (NEC). Historical climate observations from the China Meteorological Administration and statistical agricultural records at the county level were utilized to evaluate the spatial and temporal effects of both climatic and socioeconomic factors on rice production between 1980 and 2010 in NEC by using a linear regression model. The results showed that a 1% increase in the rice accumulated temperature (RAT) significantly increases rice production by approximately 0.728%. Rising RAT over the past three decades increased rice production by 4.44% (equal to a relative contribution of 0.87% to production growth) in NEC, while the majority of rice production growth (79.6%) resulted from increased agricultural inputs. Furthermore, rice production has increased significantly since 2000, and its geographic centroid shifted over 320 km northeastward during the past 30 years. Historical statistical and simulated rice production data for each county were used to quantify the spatial relocation of rice production due to single climatic factors. During 1980–2010, temperature had a significant and coherent influence on moving rice production. The impact of growing season precipitation was not significant, while sunshine had a significant but less spatially coherent influence. Our findings highlight the response of the rice production system to external driving factors, both climate and socioeconomics, to target further research and provide important insights into how a rice cropping system is likely to adapt in a mid-high-latitude region in the future.\",\"collection-title\":\"8.414\",\"container-title\":\"Environmental Research Letters\",\"DOI\":\"10.1088/1748-9326/aafa55\",\"ISSN\":\"1748-9326\",\"issue\":\"2\",\"journalAbbreviation\":\"Environ. Res. Lett.\",\"language\":\"en-US\",\"note\":\"publisher: IOP Publishing\\nCitation Key: hu2019Environ.Res.Lett.\",\"page\":\"024014\",\"source\":\"Institute of Physics\",\"title\":\"Rice production and climate change in Northeast China: evidence of adaptation through land use shifts\",\"title-short\":\"Rice production and climate change in Northeast China\",\"volume\":\"14\",\"author\":[{\"family\":\"Hu\",\"given\":\"Yanan\"},{\"family\":\"Fan\",\"given\":\"Lingling\"},{\"family\":\"Liu\",\"given\":\"Zhenhuan\"},{\"family\":\"Yu\",\"given\":\"Qiangyi\"},{\"family\":\"Liang\",\"given\":\"Shefang\"},{\"family\":\"Chen\",\"given\":\"Shi\"},{\"family\":\"You\",\"given\":\"Liangzhi\"},{\"family\":\"Wu\",\"given\":\"Wenbin\"},{\"family\":\"Yang\",\"given\":\"Peng\"}],\"issued\":{\"date-parts\":[[\"2019\",2]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"}";
  // 转化为JSON对象
    JObject jObj=JObject.Parse(FieldCode.Replace("ADDIN ZOTERO_ITEM CSL_CITATION",""));

// 转zotero uris链接为zotero://select链接
    jObj.SelectTokens("citationItems[*].uris[0]").Select(x=>$"zotero://select/library/items/{Path.GetFileName((string)x)}");


获取到的结果为:

zotero://select/library/items/WAJ2XKB5
zotero://select/library/items/FPWETRUL

ttChen 最后更新于 2023-01-29 10:59
ttChen 回复 2023-01-29 11:22 :

 jObj.SelectTokens("citationItems[*].uris[0]")这步获到的就是ItemKey

ttChen 回复 2023-01-29 11:24 :

View PDF - 动作信息 - Quicker (getquicker.net) 这是浏览器打开PDF的动作,把最后一步改一下即可。

回复 ttChen 2023-01-30 15:22 :

我反复尝试,还没搞定,卡在了获取ItemKey

这是运行C#代码那一段,能不能帮忙改一下,我想获得

zhang et al., 2012|128882|WAJ2XKB5

Wang et al., 2010|5986|WABCXLM8

这样的输出



using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Office.Interop.Word;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Runtime.InteropServices;

// Quicker将会调用的函数
public static string Exec(string paramValue)
{
    string code = "";
    var Word = (Microsoft.Office.Interop.Word.Application)Marshal.GetActiveObject("Word.Application");
    var doc = Word.ActiveDocument;
    Range rng;
    foreach (Field mfield in Word.Selection.Paragraphs[1].Range.Fields) {
        rng = mfield.Result;
        rng.SetRange(rng.Start - 2 - mfield.Code.Text.Length, rng.End + 2);
        if (Word.Selection.Range.InRange(rng)) {
            code=mfield.Code.Text;
            break;
        }
    }
    if (string.IsNullOrEmpty(code)) return "请选择文献引用!";
    JObject json = JObject.Parse(code.Replace("ADDIN ZOTERO_ITEM CSL_CITATION ", ""));
    var itemdata = json["citationItems"].Select(
    x => new {
        id = (string)x["id"],
        // uris1 = string.Join(",", uris),  // //uris1 需要导出类似“WAJ2XKB5”8位字符(ItemKey),这个地方应该怎么改啊?
        // uris1 = GetFileName((string)x),
        // uris1 = json.SelectTokens("citationItems[*].uris[0]"),
        author = (string.IsNullOrEmpty((string)x["itemData"]["author"][0]["family"]) ? ((string)x["itemData"]["author"][0]["literal"]) : ((string)x["itemData"]["author"][0]["family"])) + " et al., " +
        (string)x["itemData"]["issued"]["date-parts"][0][0]
    }).ToList();

    var result = itemdata.Select(x => x.author + "|" + x.id + "|" + x.uris1).ToList();  //uris1 需要导出类似“WAJ2XKB5”8位字符(ItemKey)
    return string.Join( "\n", result);  //数组转为字符串
}

最后更新于 2023-01-30 15:42
ttChen 回复 2023-01-30 19:47 :

ItemKey=Path.GetFileName((string)x.SelectToken("uris[0]"))

回复 ttChen 2023-01-31 10:30 :

感谢,

再请教一个问题,Word中的域代码里面是不是只有zotero父条目的ItemKey,没有子PDF的ItemKey?

最后更新于 2023-01-31 10:31
ttChen 回复 2023-01-31 10:32 :

所有的东西都有Itemkey

回复 ttChen 2023-01-31 10:35 :

zotero里面肯定有,但是在这个串里面有PDF文件的 Itemkey吗?


// FieldCode为获取到的域代码

string FieldCode="ADDIN ZOTERO_ITEM CSL_CITATION {\"citationID\":\"3FIW7gOp\",\"properties\":{\"formattedCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"plainCitation\":\"(Fungo et al, 2019; Hu et al, 2019)\",\"noteIndex\":0},\"citationItems\":[{\"id\":1558,\"uris\":[\"http://zotero.org/users/1817658/items/WAJ2XKB5\"],\"itemData\":{\"id\":1558,\"type\":\"article-journal\",\"collection-title\":\"7.116\",\"container-title\":\"Biology and Fertility of Soils\",\"DOI\":\"10.1007/s00374-018-01338-3\",\"issue\":\"2\",\"language\":\"en-US\",\"note\":\"ISBN: 1432-0789\\npublisher: Springer\\nCitation Key: fungo2019Biol.Fertil.Soils\",\"page\":\"135-148\",\"title\":\"Ammonia and nitrous oxide emissions from a field Ultisol amended with tithonia green manure, urea, and biochar\",\"volume\":\"55\",\"author\":[{\"family\":\"Fungo\",\"given\":\"Bernard\"},{\"family\":\"Lehmann\",\"given\":\"Johannes\"},{\"family\":\"Kalbitz\",\"given\":\"Karsten\"},{\"family\":\"Thionģo\",\"given\":\"Margaret\"},{\"family\":\"Tenywa\",\"given\":\"Moses\"},{\"family\":\"Okeyo\",\"given\":\"Irene\"},{\"family\":\"Neufeldt\",\"given\":\"Henry\"}],\"issued\":{\"date-parts\":[[\"2019\"]]}}},{\"id\":1514,\"uris\":[\"http://zotero.org/users/1817658/items/FPWETRUL\"],\"itemData\":{\"id\":1514,\"type\":\"article-journal\",\"abstract\":\"Climate change continues to have a great impact on rice production in China, especially in Northeast China (NEC). Historical climate observations from the China Meteorological Administration and statistical agricultural records at the county level were utilized to evaluate the spatial and temporal effects of both climatic and socioeconomic factors on rice production between 1980 and 2010 in NEC by using a linear regression model. The results showed that a 1% increase in the rice accumulated temperature (RAT) significantly increases rice production by approximately 0.728%. Rising RAT over the past three decades increased rice production by 4.44% (equal to a relative contribution of 0.87% to production growth) in NEC, while the majority of rice production growth (79.6%) resulted from increased agricultural inputs. Furthermore, rice production has increased significantly since 2000, and its geographic centroid shifted over 320 km northeastward during the past 30 years. Historical statistical and simulated rice production data for each county were used to quantify the spatial relocation of rice production due to single climatic factors. During 1980–2010, temperature had a significant and coherent influence on moving rice production. The impact of growing season precipitation was not significant, while sunshine had a significant but less spatially coherent influence. Our findings highlight the response of the rice production system to external driving factors, both climate and socioeconomics, to target further research and provide important insights into how a rice cropping system is likely to adapt in a mid-high-latitude region in the future.\",\"collection-title\":\"8.414\",\"container-title\":\"Environmental Research Letters\",\"DOI\":\"10.1088/1748-9326/aafa55\",\"ISSN\":\"1748-9326\",\"issue\":\"2\",\"journalAbbreviation\":\"Environ. Res. Lett.\",\"language\":\"en-US\",\"note\":\"publisher: IOP Publishing\\nCitation Key: hu2019Environ.Res.Lett.\",\"page\":\"024014\",\"source\":\"Institute of Physics\",\"title\":\"Rice production and climate change in Northeast China: evidence of adaptation through land use shifts\",\"title-short\":\"Rice production and climate change in Northeast China\",\"volume\":\"14\",\"author\":[{\"family\":\"Hu\",\"given\":\"Yanan\"},{\"family\":\"Fan\",\"given\":\"Lingling\"},{\"family\":\"Liu\",\"given\":\"Zhenhuan\"},{\"family\":\"Yu\",\"given\":\"Qiangyi\"},{\"family\":\"Liang\",\"given\":\"Shefang\"},{\"family\":\"Chen\",\"given\":\"Shi\"},{\"family\":\"You\",\"given\":\"Liangzhi\"},{\"family\":\"Wu\",\"given\":\"Wenbin\"},{\"family\":\"Yang\",\"given\":\"Peng\"}],\"issued\":{\"date-parts\":[[\"2019\",2]]}}}],\"schema\":\"https://github.com/citation-style-language/schema/raw/master/csl-citation.json\"}";

ttChen 回复 2023-01-31 21:39 :

这里面没有啊,需要写代码获取

回复 ttChen 2023-02-02 20:53 :

好吧


目前打开PDF的顺序是  word->zotero->zotero 内置的阅读器或者外置的PDF阅读器,这个流程需要依赖zotero,并且对使用第三方PDF阅读器的用户不太友好


为了减少依赖性,我想到另外一个方法 word->外置的PDF阅读器,具体如下:

1. Word域代码中读取PDF文件所在文件夹(即8位随机Itemkey)

2. quicker遍历 目录 storage\8位随机Itemkey 文件夹下的PDF文件(应该只有一个),并打开这个PDF文件


前两天根据你的指导,完成了一部分,但是对Word中域代码这一块不太了解,目前只会获得zotero父条目的ItemKey,没有子PDF的ItemKey,所以“word->外置的PDF阅读器”这个流程暂时无法实现


PS。过于深究这些可能意义不大,仅仅是学习、优化

ttChen 回复 2023-02-02 21:43 :

根据大家的要求,刚刚开发一个WPS版zotero插件,实现了word版本的全部功能https://getquicker.net/Sharedaction?code=e90100f6-7713-4241-ba6e-08db0423d7d9

若了解python的话,里面有很详细的代码。欢迎交流。

ttChen 最后更新于 2023-02-02 21:43
回复 ttChen 2023-02-02 21:47 :

这个是将zotero中的文献插入到WPS中,我上面说的是从Word的域代码中获得PDF文件的Itemkey,然后使用系统的PDF阅读器打开PDF文件,这俩好像不一样

不过你开发的这个插入zotero文献到wps中的功能真的很强,赞

ttChen 回复 2023-02-02 21:47 :

另外,利用前面的代码找到ItemID或者Itemkey后,还需要借助Javascript,从内部进一步获取该文献所有PDF附件的itemID。然后就可以找到目录名称了。

ttChen 最后更新于 2023-02-02 21:48
ttChen 回复 2023-02-02 22:01 :

ItemKey和ItemID,利用Javascript,通过Zotero.Items.getByLibraryAndKey或者getLibraryAndKeyFromID等函数是可以随意互换的。

回复 ttChen 2023-02-02 22:03 :

明白了,看来无论如何都得从zotero那里才能查询到PDF附件的 Itemkey,或者说都得zotero在后面做伺服,是这样吧?


Zotero.Items.getByLibraryAndKey或者getLibraryAndKeyFromID这些函数 你是从哪查找到的资料啊?

ttChen 回复 2023-02-02 22:04 :

Zotero源代码,在Javascript Runner里面,输入函数名也可看到源函数

ttChen 最后更新于 2023-02-02 22:05
回复 ttChen 2023-02-02 22:06 :

厉害了,


看了下 [ZoteroForWPS - 动作信息 - Quicker](  https://getquicker.net/Sharedaction?code=e90100f6-7713-4241-ba6e-08db0423d7d9  )    ,感觉比Word版的“插入引用”功能还要强,赞

ttChen 回复 2023-02-03 12:23 :

整合一下,以免WPS也那么多动作。

回复主贴