亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何正確加密合并的pdf文檔

如何正確加密合并的pdf文檔

動漫人物 2022-07-06 19:17:28
我對 pdfBox API 有疑問。我正在嘗試使用以下代碼加密合并的 pdfdocument:這是合并/創建文檔的功能    public static void fillMultipleReportsInOne(List<report> reports) throws IOException {        PDFMergerUtility PDFmerger = new PDFMergerUtility();         PDDocument resultPDF = new PDDocument();        for (report report : reports) {            try             {                PDDocument pdfDocument = PDDocument.load(new File(SRC + "test.pdf"));                // get the document catalog                PDAcroForm acroForm = pdfDocument.getDocumentCatalog().getAcroForm();                // as there might not be an AcroForm entry a null check is necessary                setFormFields(acroForm, report.getName(), report.getArea(), report.getOperatingActivities(), report.getVocationlaSchool(), report.getWeeklyTopics());                // Save and close the filled out form.                PDFmerger.appendDocument(resultPDF, pdfDocument);        } catch (Exception e) {            e.printStackTrace();        }    }    encryptPDF(resultPDF, SRC + "merged.pdf");}這是加密的功能: public static PDDocument encryptPDF(PDDocument pddocumentToEncrypt, String SRC) {        // Define the length of the encryption key.        // Possible values are 40 or 128 (256 will be available in PDFBox 2.0).        int keyLength = 128;        AccessPermission ap = new AccessPermission();        // Disable printing, everything else is allowed        ap.setCanModifyAnnotations(false);        ap.setCanFillInForm(false);        ap.setCanModify(false);        // Owner password (to open the file with all permissions) is "12345"        // User password (to open the file but with restricted permissions, is empty here)         StandardProtectionPolicy spp = new StandardProtectionPolicy("12334", "", ap);        spp.setEncryptionKeyLength(keyLength);        spp.setPermissions(ap);我的結果如下所示:結果
查看完整描述

1 回答

?
FFIVE

TA貢獻1797條經驗 獲得超6個贊

打電話

pddocumentToEncrypt.getDocumentCatalog().getAcroForm().refreshAppearances();

為 2.0 版本修復了這個問題。setValue()當設置 /NeedAppearances 時,該版本不會在調用中設置外觀(即表單值的視覺表示) (請參閱 參考資料PDTerminalField.applyChange())。/NeedAppearances 設置(如果為真)意味著查看應用程序應該創建外觀,以便中間的處理應用程序不需要這樣做;我懷疑其中一項或多項權限設置會阻止 Adobe Reader 在顯示時對其進行更改。

另一種解決方案是致電

pdfDocument.getDocumentCatalog().getAcroForm().setNeedAppearances(false);

在設置表單值之前。

唯一未解之謎是為什么第一個值在合并文件中可見。


查看完整回答
反對 回復 2022-07-06
  • 1 回答
  • 0 關注
  • 254 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號