/** Does the actual document manipulation to encrypt it. * @throws DocumentException on error * @throws IOException on error */ protected void go() { body = new PdfBody(HEADER.Length, this, true); os.Write(HEADER, 0, HEADER.Length); PdfObject[] xb = reader.xrefObj; myXref = new int[xb.Length]; int idx = 1; for (int k = 1; k < xb.Length; ++k) { if (xb[k] != null) { myXref[k] = idx++; } } file.reOpen(); for (int k = 1; k < xb.Length; ++k) { if (xb[k] != null) { addToBody(xb[k]); } } file.close(); PdfIndirectReference encryption = null; PdfLiteral fileID = null; if (crypto != null) { PdfIndirectObject encryptionObject = body.Add(crypto.EncryptionDictionary); encryptionObject.writeTo(os); encryption = encryptionObject.IndirectReference; fileID = crypto.FileID; } // write the cross-reference table of the body os.Write(body.CrossReferenceTable, 0, body.CrossReferenceTable.Length); PRIndirectReference iRoot = (PRIndirectReference)reader.trailer.get(PdfName.ROOT); PdfIndirectReference root = new PdfIndirectReference(0, myXref[iRoot.Number]); PRIndirectReference iInfo = (PRIndirectReference)reader.trailer.get(PdfName.INFO); PdfIndirectReference info = null; if (iInfo != null) { info = new PdfIndirectReference(0, myXref[iInfo.Number]); } PdfTrailer trailer = new PdfTrailer(body.Size, body.Offset, root, info, encryption, fileID); byte[] tmp = trailer.toPdf(this); os.Write(tmp, 0, tmp.Length); os.Close(); }