我已经在堆栈溢出和其他网站上搜索了以下代码,以便合并两个pdf文件,但收到以下错误。
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfReader;
public class Concatenate {
public static final String RESULT= "concatenated.pdf";
public static void main(String[] args) throws IOException, DocumentException {
String[] files = ["1.pdf","2.pdf"];
Document document = new Document();
PdfCopy copy = new PdfCopy(document, new FileOutputStream(RESULT));
document.open();
PdfReader reader;
int n;
for (int i = 0; i < files.length; i++)
{
reader = new PdfReader(files[i]);
n = reader.getNumberOfPages();
for (int page = 0; page < n; )
{
copy.addPage(copy.getImportedPage(reader, ++page));
}
copy.freeReader(reader);
reader.close();
}
document.close();
}
}
这就是我得到的错误:
Exception in thread "main" java.lang.NoClassDefFoundError:
org/bouncycastle/cms/RecipientId at
java.lang.Class.getDeclaredMethods0(Native Method) at
java.lang.Class.privateGetDeclaredMethods(Class.java:2531) at
java.lang.Class.privateGetPublicMethods(Class.java:2651) at
java.lang.Class.getMethods(Class.java:1467) at
org.codehaus.groovy.reflection.stdclasses.CachedSAMClass.getSAMMethod(CachedSAMClass.java:135) at
org.codehaus.groovy.reflection.ClassInfo.isSAM(ClassInfo.java:280) at
答案 0 :(得分:1)
现在正在使用以下JAR:
import com.lowagie.text.Document
import com.lowagie.text.DocumentException
import com.lowagie.text.pdf.PdfCopy
import com.lowagie.text.pdf.PdfReader
答案 1 :(得分:0)
请在系统类路径变量中添加bouncycastle库。
设置CLASSPATH =%CLASSPATH%; lib_path_of_bouncycastle