我只想对生成的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
求各位大神解答