0

以下のコードは、pdf ファイルを書き込むためのものです。

BaseFont bf = BaseFont.createFont(FONT, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
FontSelector fs = new FontSelector();
fs.addFont(new Font(bf));                
String fileName = filePath3 + "//DEVIATION_REPORT.pdf";
OutputStream file = new FileOutputStream(new File(fileName));
Font smallFont = new Font(Font.FontFamily.COURIER, 6, Font.NORMAL);
Font headerFont = new Font(Font.FontFamily.HELVETICA, 7, Font.BOLD);
Font tabFont = new Font(Font.FontFamily.HELVETICA, 5, Font.NORMAL);
Font rusFont = new Font(bf, 5);                
Font blueFont = new Font(bf, 5);
blueFont.setColor(BaseColor.BLUE);                
Font redFont = new Font(bf, 5);
redFont.setColor(BaseColor.RED);

String comType;
if (compType == 2)
   comType = "Character";
else 
   comType = "Word";

Document doc = new Document();
PdfWriter.getInstance(doc, file);                
doc.open();            

Image image1 = Image.getInstance(cmdpath + "ScRp.jpg");
image1.setAlignment(Element.ALIGN_LEFT);

Paragraph prg = new Paragraph("Compare", smallFont);
prg.setAlignment(Element.ALIGN_RIGHT);
doc.add(image1);
doc.add(prg);
doc.add(new Paragraph("__________________________________________________"));
doc.add(new Paragraph("Passed Report"));
doc.add(new Paragraph(" "));

PdfPTable table = new PdfPTable(2);
PdfPCell cell1 = new PdfPCell(new Paragraph("No", headerFont));
cell1.setHorizontalAlignment(Element.ALIGN_CENTER);
cell1.setPaddingBottom(5);                
PdfPCell cell2 = new PdfPCell(new Paragraph("Details", headerFont));
cell2.setHorizontalAlignment(Element.ALIGN_CENTER);
cell2.setPaddingBottom(5);             
table.addCell(cell1);
table.addCell(cell2);
doc.add(table);
doc.newPage();
doc.close();
file.close();

PDFを編集不可にしたい場合はどうすればよいですか。私は使用しようとしました

 PdfEncryptor.encrypt(  
 new PdfReader(fileName),  
 new FileOutputStream("HelloWorldProtected.pdf"),  
 null,  
 "StrongPassword".getBytes(),  
 PdfWriter.AllowPrinting,  
 PdfWriter.STRENGTH128BITS);  

しかし、コンパイラはここで停止します。15分以上待ったが何も起こらない。

file.setreadOnly()も作成しますが、編集後に保存することはできません。ユーザーは引き続き編集できます。ユーザーはドキュメントを名前を付けて保存し、編集不可能なドキュメントに置き換えることができます。

ファイルを編集不可にする他の方法はありますか。ご意見をお聞かせください。

4

1 に答える 1