private void AssertOutputFile(string outputFilePath, FileAuthentication outputAuth, string expectedFilePath, int expectedNumberOfPages, string expectedText) { Assert.IsTrue(File.Exists(outputFilePath)); Assert.AreEqual(expectedFilePath, outputFilePath); PdfComparer.AssertPageCount(outputFilePath, outputAuth, this.authenticationManager, expectedNumberOfPages); PdfComparer.AssertText(outputFilePath, outputAuth, this.authenticationManager, expectedText, null); }
public void AddWatermarkWithAuthentication( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication watermarkAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory); string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Watermark.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); var watermarkPages = string.Empty; ConfigureWatermarkFunctionValues(designer, watermarkAuth, watermarkFilePath, WatermarkPosition.Below, watermarkPages); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <AddWatermarkProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\nWatermark\r\n4\nWatermark", null); }
public void Concatenate() { string inputFilePath1 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate1.pdf", this.inputDirectory); PdfComparer.AssertPageCount(inputFilePath1, FileAuthentication.None, this.authenticationManager, 1); PdfComparer.AssertText(inputFilePath1, FileAuthentication.None, this.authenticationManager, "1", "function Script1()\r\n{}\n"); string inputFilePath2 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate2.pdf", this.inputDirectory); PdfComparer.AssertPageCount(inputFilePath2, FileAuthentication.None, this.authenticationManager, 1); PdfComparer.AssertText(inputFilePath2, FileAuthentication.None, this.authenticationManager, "2", "function Script2()\r\n{}\n"); string outputFilePath = Path.Combine(this.outputDirectory, "Concat.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); designer.Properties[PropertyNames.Operation].Value = Operation.Concatenate; designer.Properties[PropertyNames.InputFiles].Value = new List <string> { inputFilePath1, inputFilePath2 }; designer.Properties[PropertyNames.InputAuthenticationType].Value = AuthenticationType.None; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsTrue(File.Exists(outputFilePath)); PdfComparer.AssertPageCount(outputFilePath, FileAuthentication.None, this.authenticationManager, 2); PdfComparer.AssertText(outputFilePath, FileAuthentication.None, this.authenticationManager, $"1{Environment.NewLine}2", "function Script1()\r\n{}\n\nfunction Script2()\r\n{}\n\n"); }
public void SignAcroWithPageSignature() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.Sign.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Sign.pdf"); int left = 45; int top = 223; int width = 109; int height = 79; int page = 2; this.lockDocument = !this.lockDocument; FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureSignCertificateProperties(designer, FileAuthentication.CertificateFile, this.lockDocument); designer.Properties[PropertyNames.Placement].Value = SignaturePosition.OnPage; designer.Properties[PropertyNames.PositionX].Value = left; designer.Properties[PropertyNames.PositionY].Value = top; designer.Properties[PropertyNames.Width].Value = width; designer.Properties[PropertyNames.Height].Value = height; designer.Properties[PropertyNames.Page].Value = page; 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.AssertPageSignature(outputFilePath, FileAuthentication.None, this.authenticationManager, signName, signLocation, signReason, this.lockDocument, page, Utilities.MillimetersToPoints(left), Utilities.MillimetersToPoints(top), Utilities.MillimetersToPoints(width), Utilities.MillimetersToPoints(height)); }
public void AddWatermark( [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, [Values( WatermarkPosition.Above, WatermarkPosition.Below)] WatermarkPosition position) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Watermark.pdf", this.inputDirectory); string watermarkFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.AddWatermark.Resources.Overlay.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Watermark.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <AddWatermarkProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); var watermarkPages = "4;1-2,2,2"; ConfigureWatermarkFunctionValues(designer, FileAuthentication.None, watermarkFilePath, position, watermarkPages); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <AddWatermarkProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertText(outputFilePath, inputAuth, this.authenticationManager, "1\nWatermark\r\n2\nWatermark\r\n3\r\n4\nWatermark", null); }
public void ProtectWithScreenReaderRestrictions( [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( true, false)] bool allowScreenReaders) { 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, allowScreenReaders: allowScreenReaders); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true, expectedAllowScreenReaders: allowScreenReaders); if (protectAuth == FileAuthentication.Password) { using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword)) { PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true); } } }
public void SignWithInvisibleSignature( [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, [Values( FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication signAuth, [Values( "Sign.pdf", "SignXFA.pdf")] string fileName) { string inputFilePath = ResourceHelpers.WriteResourceToFile($"Twenty57.Linx.Components.Pdf.Tests.Sign.Resources.{fileName}", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, fileName); this.lockDocument = !this.lockDocument; FunctionDesigner designer = ProviderHelpers.CreateDesigner <SignProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); ConfigureSignCertificateProperties(designer, signAuth, this.lockDocument); designer.Properties[PropertyNames.Placement].Value = SignaturePosition.Hidden; designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <SignProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertPageSignature(outputFilePath, inputAuth, this.authenticationManager, signName, signLocation, signReason, this.lockDocument, 1, 0, 0, 0, 0); }
public void ProtectWithPrintRestrictions( [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( Printing.None, Printing.LowResolution, Printing.HighResolution)] Printing printing) { 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, printing: printing); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); bool allowDegradedPrinting = false; bool allowPrinting = false; switch (printing) { case Printing.None: break; case Printing.LowResolution: allowDegradedPrinting = true; break; case Printing.HighResolution: allowDegradedPrinting = true; allowPrinting = true; break; default: throw new NotSupportedException("Invalid Printing specified."); } PdfComparer.AssertProtection(outputFilePath, protectAuth, this.authenticationManager, true, true, expectedAllowDegradedPrinting: allowDegradedPrinting, expectedAllowPrinting: allowPrinting); if (protectAuth == FileAuthentication.Password) { using (var permissionsAuthHelper = new AuthenticationManager(permissionsPassword)) { PdfComparer.AssertProtectionAllRights(outputFilePath, FileAuthentication.Password, permissionsAuthHelper, true, true); } } }
public void FillFormXfa( [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.PdfOperations.Resources.FillFormXFA.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "FillXfa.pdf"); var formData = new { form1_910_93_46FullName_910_93 = "John", form1_910_93_46Surname_910_93 = "Doe", form1_910_93_46Email_910_93 = "*****@*****.**", form1_910_93_46EmailMe_910_93 = true }; FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.Operation].Value = Operation.FillForm; designer.Properties[PropertyNames.FillFormFormData].Value = formData; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); var formValues = new Dictionary <string, string> { { "form1[0].FullName[0]", formData.form1_910_93_46FullName_910_93 }, { "form1[0].Surname[0]", formData.form1_910_93_46Surname_910_93 }, { "form1[0].Email[0]", formData.form1_910_93_46Email_910_93 }, { "form1[0].EmailMe[0]", (formData.form1_910_93_46EmailMe_910_93) ? "Yes" : "No" }, { "form1[0]", "*****@*****.**" } }; PdfComparer.AssertFields(outputFilePath, inputAuth, this.authenticationManager, formValues); }
public void ProtectWithNoRestrictions( [Values( FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication protectAuth) { 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); designer.Properties[Pdf.Common.PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <ChangeProtectionProvider>(); tester.Execute(designer.GetProperties(), designer.GetParameters()); PdfComparer.AssertProtectionAllRights(outputFilePath, protectAuth, this.authenticationManager, true, true); }
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.PdfOperations.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 <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.Operation].Value = Operation.FillForm; designer.Properties[PropertyNames.FillFormFormData].Value = formData; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); 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.PdfOperations.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); ConfigureProtectFunctionValues(designer, FileAuthentication.None, Encryption.AES128, false); designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); 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 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.PdfOperations.Resources.Protect.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Protect.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); ConfigureProtectFunctionValues(designer, protectAuth, Encryption.AES256, true, true, changes: changes); designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); 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); } } }