簡體   English   中英

如何使用 Java (IText API) 在不丟失數字簽名的情況下合並 PDF

[英]How to merge PDFs without losing digital signature using Java (IText API)

I have a pdf document which is digitally signed, I want to attach this digitally signed Pdf to another normal pdf using java itext api, is it possible? 我試圖將包含數字簽名的 pdf 與另一個附加在一起。 我可以合並 pdf,但最終的 pdf 沒有在 output pdf 文件中保留數字簽名。 可能嗎?。

正如其他人已經說過的,簽名背后的想法(至少是想法的主要部分)是確保文件沒有改變。 另一方面,合並確實會更改文檔。 因此,合並會破壞簽名。

但是,另一種方法是使另一個“普通”PDF 成為可移植集合(一種帶有附件的特殊 PDF)並將簽名的 PDF 附加到該集合。

從集合中打開已簽名的 PDF 時,簽名將與原始簽名 PDF 中一樣完好無損。

創建可移植集合的示例代碼

您可以在 iText 站點上找到便攜式集合創建的示例:

public static final String DEST = "results/collections/portable_collection.pdf";
public static final String DATA = "resources/data/united_states.csv";
public static final String HELLO = "resources/pdfs/hello.pdf";
public static final String IMG = "resources/images/berlin2013.jpg";

public void createPdf(String dest) throws IOException, DocumentException {
    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(dest));
    document.open();
    document.add(new Paragraph("Portable collection"));
    PdfCollection collection = new PdfCollection(PdfCollection.TILE);
    writer.setCollection(collection);
    PdfFileSpecification fileSpec = PdfFileSpecification.fileEmbedded(
            writer, DATA, "united_states.csv", null);
    writer.addFileAttachment("united_states.csv", fileSpec);
    fileSpec = PdfFileSpecification.fileEmbedded(
            writer, HELLO, "hello.pdf", null);
    writer.addFileAttachment("hello.pdf", fileSpec);
    fileSpec = PdfFileSpecification.fileEmbedded(
            writer, IMG, "berlin2013.jpg", null);
    writer.addFileAttachment("berlin2013.jpg", fileSpec);
    document.close();
}

這里在網站上, 在這里他們的GitHub)

運行該示例的結果是here

(當您使用 iText 標簽而不是 iText7 標簽時,我假設您使用的是 iText 版本 5.5.x。)

這是不可能的,這種數字簽名是專門為保護原始文檔不被以任何方式修改而設計的。

要合並和簽署這兩個文檔,您需要知道用於簽名的密鑰並為新的合並文檔再次生成簽名。

  1. 在 Adob​​e 中打開已簽名的 pdf。

  2. 打開打印對話框( Ctrl + P

  3. 將打印機更改為“Microsoft Print to PDF”,然后打印。

  4. 新創建的 PDF 將具有簽名,並將作為合並/合並活動的普通 pdf。

    在此處輸入圖片說明

注意:此方法將簽名文檔轉換為標准 pdf。 結果顯示簽名信息,但底層數字簽名丟失。 就我而言,原始簽名者理解這種區別。

創建摘要文件是我的目標。 我將各種數字簽名以及其他相關文檔合並到一個摘要 pdf 中。 原始的、數字簽名的文檔被存儲以備將來參考。 我越來越相信,在保留底層數字簽名的同時,不可能將數字簽名的文檔合並成一個單一的摘要 pdf。

需要匯總數據包的用戶將從我建議的方法中受益。 請記住,我的方法在原始數字簽名文檔可按需提供的范圍內仍然“合法有效”。

我掃描了簽名頁並將其保存為 pdf 並替換。 它確實違反了規則,但是當沒有其他方法起作用並且他們要求將所有這些文件合並為一個時,我該怎么辦!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM