/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void CheckDocumentAppending(String filename, byte[] password) { String srcFileName = destinationFolder + filename; String outFileName = destinationFolder + "appended_" + filename; PdfReader reader = new PdfReader(srcFileName, new ReaderProperties().SetPassword(password)); PdfDocument document = new PdfDocument(reader, new PdfWriter(outFileName), new StampingProperties().UseAppendMode ()); PdfPage newPage = document.AddNewPage(); newPage.Put(PdfName.Default, new PdfString("Hello world string")); document.Close(); CompareTool compareTool = new CompareTool().EnableEncryptionCompare(); String compareResult = compareTool.CompareByContent(outFileName, sourceFolder + "cmp_appended_" + filename , destinationFolder, "diff_", USER, USER); if (compareResult != null) { NUnit.Framework.Assert.Fail(compareResult); } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/> public virtual void CheckEncryptedWithCertificateDocumentAppending(String filename, X509Certificate certificate ) { String srcFileName = destinationFolder + filename; String outFileName = destinationFolder + "appended_" + filename; PdfReader reader = new PdfReader(srcFileName, new ReaderProperties().SetPublicKeySecurityParams(certificate , GetPrivateKey())); PdfDocument document = new PdfDocument(reader, new PdfWriter(outFileName), new StampingProperties().UseAppendMode ()); PdfPage newPage = document.AddNewPage(); String helloWorldStringValue = "Hello world string"; newPage.Put(PdfName.Default, new PdfString(helloWorldStringValue)); WriteTextBytesOnPageContent(newPage, "Hello world page_2!"); document.Close(); PdfReader appendedDocReader = new PdfReader(outFileName, new ReaderProperties().SetPublicKeySecurityParams (certificate, GetPrivateKey())); PdfDocument appendedDoc = new PdfDocument(appendedDocReader); PdfPage secondPage = appendedDoc.GetPage(2); PdfString helloWorldPdfString = secondPage.GetPdfObject().GetAsString(PdfName.Default); String actualHelloWorldStringValue = helloWorldPdfString != null?helloWorldPdfString.GetValue() : null; NUnit.Framework.Assert.AreEqual(actualHelloWorldStringValue, helloWorldStringValue); appendedDoc.Close(); CompareTool compareTool = new CompareTool().EnableEncryptionCompare(); compareTool.GetOutReaderProperties().SetPublicKeySecurityParams(certificate, GetPrivateKey()); compareTool.GetCmpReaderProperties().SetPublicKeySecurityParams(certificate, GetPrivateKey()); String compareResult = compareTool.CompareByContent(outFileName, sourceFolder + "cmp_appended_" + filename , destinationFolder, "diff_"); if (compareResult != null) { NUnit.Framework.Assert.Fail(compareResult); } }