public void FillFormAcro( [Values( FileAuthentication.None, FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication inputAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.FillForm.Resources.FillForm.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Fill.pdf"); var formData = new { First_32Name = "Jane", Surname = "Woods", Gender = "Female", AcceptTCs = true }; FunctionDesigner designer = ProviderHelpers.CreateDesigner <FillFormProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.FillFormFormData].Value = formData; designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <FillFormProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); var formValues = new Dictionary <string, string> { { "First Name", formData.First_32Name }, { "Surname", formData.Surname }, { "Gender", formData.Gender }, { "AcceptTCs", (formData.AcceptTCs)? "Yes" : "No" } }; PdfComparer.AssertFields(outputFilePath, inputAuth, this.authenticationManager, formValues); }
public void ProtectWithRemoveProtection( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication inputAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); ConfigureProtectFunctionValues(designer, FileAuthentication.None, Encryption.AES128, false); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, "Text on page 1", null); }
public void SignAcroWithFieldSignature() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Sign.pdf"); string fieldName = "SignatureField"; this.lockDocument = !this.lockDocument; FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureSignCertificateProperties(designer, FileAuthentication.CertificateStore, this.lockDocument); designer.Properties[PropertyNames.Placement].Value = SignaturePosition.FormField; designer.Properties[PropertyNames.FieldName].Value = fieldName; designer.Properties[PropertyNames.BackgroundImage].Value = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign_Image.png", this.inputDirectory); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <SignProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertFieldSignature(outputFilePath, FileAuthentication.None, this.authenticationManager, fieldName, signName, signLocation, signReason, this.lockDocument); }
public void ReadText( [Values( TextSplit.Never, TextSplit.Page)] TextSplit splitText) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Text.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadText].Value = true; designer.Properties[PropertyNames.SplitText].Value = splitText; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); switch (splitText) { case TextSplit.Never: Assert.AreEqual("Text on page 1\r\nFooter text on page 1\r\n\r\nText on page 2\r\n\r\nText on page 3\r\n", result.Value.Text); break; case TextSplit.Page: Assert.AreEqual(new List<string> { "Text on page 1\r\nFooter text on page 1\r\n", "Text on page 2\r\n", "Text on page 3\r\n" }, result.Value.Text); break; } }
public void ProtectWithChangeRestrictions( [Values( FileAuthentication.Password /*, * Ignore: http://stackoverflow.com/questions/40045745/itextsharp-object-reference-error-on-pdfstamper-for-certificate-protected-file * FileAuthentication.CertificateFile, * FileAuthentication.CertificateStore*/)] FileAuthentication protectAuth, [Values( Changes.None, Changes.Assembly, Changes.FillIn, Changes.AnnotateAndFillIn, Changes.AnyExpectExtract)] Changes changes) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ChangeProtection.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ChangeProtectionProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, changes: changes); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); bool allowAssembly = false; bool allowFillIn = false; bool allowModifyAnnotations = false; bool allowModifyContents = false; switch (changes) { case Changes.None: break; case Changes.Assembly: allowAssembly = true; break; case Changes.FillIn: allowFillIn = true; break; case Changes.AnnotateAndFillIn: allowModifyAnnotations = true; allowFillIn = true; break; case Changes.AnyExpectExtract: allowModifyContents = true; allowModifyAnnotations = true; allowFillIn = true; break; default: throw new NotSupportedException("Invalid Changes specified."); } PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true, expectedAllowAssembly: allowAssembly, expectedAllowFillIn: allowFillIn, expectedAllowModifyAnnotations: allowModifyAnnotations, expectedAllowModifyContents: allowModifyContents); if (protectAuth == FileAuthentication.Password) { using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword)) { PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true); } } }