itext setEncryption报错问题
来源:互联网 发布:java后台接收上传图片 编辑:程序博客网 时间:2024/05/16 17:29
我只想对生成的pdf 设置不能复制
源代码1 :
private final static String READFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.prt"; //txt文件
private final static String WRITEFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.PDF"; //生成的pdf文件
@SuppressWarnings("deprecation")
public static void main(String[] args) throws DocumentException,
IOException {
Document document = new Document(PageSize.A4, 80, 80, 60, 30);
PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(WRITEFILEPATH));
pdfWriter.setEncryption(null,null, PdfWriter.AllowFillIn, false);
document.open();
BaseFont bfChinese = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 18, Font.NORMAL);
Paragraph t = new Paragraph("oracle手册", FontChinese); //起一个别名,上班老板都不会发现,呵呵。
t.setAlignment(Element.ALIGN_CENTER);
t.setLeading(30.0f);
document.add(t);
FontChinese = new Font(bfChinese, 11, Font.NORMAL);
BufferedReader read = null;
try {
read = new BufferedReader(new FileReader(READFILEPATH));
String line = null;
while ((line = read.readLine()) != null) {
t = new Paragraph(line, FontChinese);
t.setAlignment(Element.ALIGN_LEFT);
t.setLeading(20.0f);
document.add(t);
}
} catch (Exception e) {
System.out.println("目标文件不存,或者不可读!");
e.printStackTrace();
} finally {
try {
read.close();
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("============执行成功!===========");
}
源代码2 :
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
public class PDFConvert2 {
private final static String READFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.PDF"; //txt文件
private final static String WRITEFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910(2).PDF"; //生成的pdf文件
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader(READFILEPATH);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream( WRITEFILEPATH));
stamper.setEncryption(null,null, PdfWriter.AllowFillIn, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
}
出现这个问题
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString
at com.lowagie.text.pdf.PdfEncryption.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.setEncryption(Unknown Source)
at com.lowagie.text.pdf.PdfStamper.setEncryption(Unknown Source)
at com.ncs.test.PDFConvert2.main(PDFConvert2.java:21)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.ASN1OctetString
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 4 more
后来网上说添加这两个jar包bcpkix-jdk15on-1.48.jar,bcprov-jdk15on-147.jar
我加了以后 又报这种错误
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DEREncodable
at com.lowagie.text.pdf.PdfEncryption.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.setEncryption(Unknown Source)
at com.lowagie.text.pdf.PdfStamper.setEncryption(Unknown Source)
at com.ncs.test.PDFConvert2.main(PDFConvert2.java:21)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DEREncodable
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 4 more
求各位大神解答
源代码1 :
private final static String READFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.prt"; //txt文件
private final static String WRITEFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.PDF"; //生成的pdf文件
@SuppressWarnings("deprecation")
public static void main(String[] args) throws DocumentException,
IOException {
Document document = new Document(PageSize.A4, 80, 80, 60, 30);
PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(WRITEFILEPATH));
pdfWriter.setEncryption(null,null, PdfWriter.AllowFillIn, false);
document.open();
BaseFont bfChinese = BaseFont.createFont("STSong-Light",
"UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 18, Font.NORMAL);
Paragraph t = new Paragraph("oracle手册", FontChinese); //起一个别名,上班老板都不会发现,呵呵。
t.setAlignment(Element.ALIGN_CENTER);
t.setLeading(30.0f);
document.add(t);
FontChinese = new Font(bfChinese, 11, Font.NORMAL);
BufferedReader read = null;
try {
read = new BufferedReader(new FileReader(READFILEPATH));
String line = null;
while ((line = read.readLine()) != null) {
t = new Paragraph(line, FontChinese);
t.setAlignment(Element.ALIGN_LEFT);
t.setLeading(20.0f);
document.add(t);
}
} catch (Exception e) {
System.out.println("目标文件不存,或者不可读!");
e.printStackTrace();
} finally {
try {
read.close();
document.close();
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("============执行成功!===========");
}
源代码2 :
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.DocumentException;
import com.lowagie.text.pdf.PdfReader;
import com.lowagie.text.pdf.PdfStamper;
import com.lowagie.text.pdf.PdfWriter;
public class PDFConvert2 {
private final static String READFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910.PDF"; //txt文件
private final static String WRITEFILEPATH = "C:\\Users\\libin\\Desktop\\test_converto_PDF\\910(2).PDF"; //生成的pdf文件
public static void main(String[] args) {
try {
PdfReader reader = new PdfReader(READFILEPATH);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream( WRITEFILEPATH));
stamper.setEncryption(null,null, PdfWriter.AllowFillIn, false);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (DocumentException e) {
} catch (IOException e) {
e.printStackTrace();
}
}
}
出现这个问题
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1OctetString
at com.lowagie.text.pdf.PdfEncryption.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.setEncryption(Unknown Source)
at com.lowagie.text.pdf.PdfStamper.setEncryption(Unknown Source)
at com.ncs.test.PDFConvert2.main(PDFConvert2.java:21)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.ASN1OctetString
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 4 more
后来网上说添加这两个jar包bcpkix-jdk15on-1.48.jar,bcprov-jdk15on-147.jar
我加了以后 又报这种错误
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/asn1/DEREncodable
at com.lowagie.text.pdf.PdfEncryption.<init>(Unknown Source)
at com.lowagie.text.pdf.PdfWriter.setEncryption(Unknown Source)
at com.lowagie.text.pdf.PdfStamper.setEncryption(Unknown Source)
at com.ncs.test.PDFConvert2.main(PDFConvert2.java:21)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.asn1.DEREncodable
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
... 4 more
求各位大神解答
0 0
- itext setEncryption报错问题
- iText中文,报错解决
- iText中文,报错解决
- itext报错PdfReader not opened with owner password
- IText中文处理问题!!!
- itext中文问题
- iText的一些问题
- iText模板应用问题
- iText中文问题
- itext 图片问题
- itext 解决中文问题
- iText 中文问题
- itext中文问题
- itext生成PDF文件报错“Font 'STSong-Light' with 'UniGB-UCS2-H' is not recognized.”
- JAVAWeb的Servlet中使用itext.jar报错找不到包
- iText 生成pdf,分页问题
- iText操作PDF问题总结
- itext使用所遇问题
- eclipse中出现ContainerBase.addChild: start: 的解决办法
- echarts之legend-改变图例的图标为自定义图片
- android签名打包时 String.xml报错,***is not translated in zh错误,引用的其他库比如V7 ,value中的string 全部报错
- 解决ADB not responding问题 Android studio
- mapreduce文档汇总
- itext setEncryption报错问题
- run reflection
- Android多线程问题。android.os.NetworkOnMainThreadException
- python04-错误、调试和测试
- Objective-C 和 Core Foundation 对象相互转换的内存管理总结
- <php+mysql>从PHP连接数据库,以及mysqli_connect()不能使用localhost的解答
- java *** 制作圣诞贺卡
- 基于栈和队列实现二叉树的遍历
- 请用fontAwesome代替网页icon小图标