问题描述
我正在使用itextpdf-5.5.6.jar和bcprov-jdk15on-1.60.jar,并出现异常: java.lang.NoClassDefFoundError:org.bouncycastle.asn1.ASN1encodable在com.itextpdf.text.pdf.PdfEncryption
如何解决?
解决方法
itext POM将bouncycastle标记为可选
import pandas as pd
category_map = {
"11":"Agriculture,Forestry,Fishing and Hunting","21":"Mining,Quarrying,and Oil and Gas Extraction"}
df = pd.DataFrame([["48",17845],[" 11 ",88888],["12",33333],["21",999]],columns=["category","count of records"])
# cleanup category and add description
df["category"] = df["category"].str.strip()
df["Category_Description"] = [category_map.get(cat,"")
for cat in df["category"]]
# alternately....
#df.insert(2,"Category_Description",# [category_map.get(cat,"") for cat in df["category"]])
print(df)
所以您必须在项目POM中包括bouncycastle,以确保其可用。
请注意,bouextcastle 1.49对于itext5.5.6是recommended
,请从给定链接的下面下载bcprov-jdk15on-150.jar(对于JDK 1.5-1.7)文件,然后添加您的项目以解决java.lang.NoClassDefFoundError:org / bouncycastle / asn1 / ASN1Encodable异常。
http://www.bouncycastle.org/latest_releases.html
根据您的JDK版本从上述链接中找到合适的jar文件。
另一种方式:
您可以在以下URL上检查itext 5.5的依赖性。
http://mvnrepository.com/artifact/com.itextpdf/itextpdf/5.5.0
根据此页面,itext 5.5的bouncycastle的对应版本为1.49。我在互联网上某处的页面上看到bouncycastle发生了很大的变化,通常很难为特定版本的itext找到相应的bouncycastle版本。