public void ReadXfaFormDataWithCustomTypeOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; ITypeReference dataType = TypeReference.CreateGeneratedType( new TypeProperty("form1_910_93_46FullName_910_93", typeof(string)), new TypeProperty("form1_910_93_46Surname_910_93", typeof(string)), new TypeProperty("form1_910_93_46Email_910_93", typeof(string)), new TypeProperty("form1_910_93_46EmailMe_910_93", typeof(string))); designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType; designer.Properties[PropertyNames.FormDataType].Value = dataType; var tester = new FunctionTester<ReadProvider>(); tester.CustomTypes.Add(dataType); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93); Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93); Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93); Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93); }
public void ReadAcroFormDataWithCustomTypeOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; ITypeReference dataType = TypeReference.CreateGeneratedType( new TypeProperty("First_32Name", typeof(string)), new TypeProperty("Surname", typeof(string)), new TypeProperty("Gender", typeof(string)), new TypeProperty("AcceptTCs", typeof(string))); designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.CustomType; designer.Properties[PropertyNames.FormDataType].Value = dataType; var tester = new FunctionTester<ReadProvider>(); tester.CustomTypes.Add(dataType); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("Jeremy", result.Value.FormData.First_32Name); Assert.AreEqual("Woods", result.Value.FormData.Surname); Assert.AreEqual("Male", result.Value.FormData.Gender); Assert.AreEqual("Yes", result.Value.FormData.AcceptTCs); }
public void ReadXfaFormDataWithListOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); List<KeyValuePair<string, string>> dataList = result.Value.FormDataList; Assert.AreEqual(5, dataList.Count); KeyValuePair<string, string> item = dataList[0]; Assert.AreEqual("form1[0].FullName[0]", item.Key); Assert.AreEqual("John", item.Value); item = dataList[1]; Assert.AreEqual("form1[0].Surname[0]", item.Key); Assert.AreEqual("Doe", item.Value); item = dataList[2]; Assert.AreEqual("form1[0].EmailMe[0]", item.Key); Assert.AreEqual("1", item.Value); item = dataList[3]; Assert.AreEqual("form1[0].Email[0]", item.Key); Assert.AreEqual("*****@*****.**", item.Value); item = dataList[4]; Assert.AreEqual("form1[0]", item.Key); Assert.AreEqual("*****@*****.**", item.Value); }
public void ReadAcroFormDataWithListOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.List; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); List<KeyValuePair<string, string>> dataList = result.Value.FormDataList; Assert.AreEqual(4, dataList.Count); KeyValuePair<string, string> item = dataList[0]; Assert.AreEqual("First Name", item.Key); Assert.AreEqual("Jeremy", item.Value); item = dataList[1]; Assert.AreEqual("Surname", item.Key); Assert.AreEqual("Woods", item.Value); item = dataList[2]; Assert.AreEqual("Gender", item.Key); Assert.AreEqual("Male", item.Value); item = dataList[3]; Assert.AreEqual("AcceptTCs", item.Key); Assert.AreEqual("Yes", item.Value); }
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 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 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 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 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 ReadSignature() { var store = new X509Store(StoreName.TrustedPeople, StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); store.Add(this.authenticationManager.Certificate); store.Close(); string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Signature.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadSignature].Value = true; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsTrue(result.Value.Signatures.IsSigned); AssertSignature(result.Value.Signatures.LatestSignature, false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1, "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false); dynamic allSignatures = result.Value.Signatures.AllSignatures; Assert.AreEqual(2, allSignatures.Count); AssertSignature(allSignatures[0], false, "I created the doc", "Office location 1", "John Smith", new DateTime(2016, 8, 8, 15, 12, 14, DateTimeKind.Utc), true, 1, string.Empty, true); AssertSignature(allSignatures[1], false, "I moderated the doc", "Office location 2", "Jane Doe", new DateTime(2016, 8, 8, 15, 12, 57, DateTimeKind.Utc), true, 1, "A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.\r\n", false); store.Open(OpenFlags.ReadWrite); store.Remove(this.authenticationManager.Certificate); store.Close(); }
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 ReadText( [Values( TextSplit.Never, TextSplit.Page)] TextSplit splitText) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.ReadPdf.Resources.Text.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner <ReadPdfProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadText].Value = true; designer.Properties[PropertyNames.SplitText].Value = splitText; var tester = new FunctionTester <ReadPdfProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); switch (splitText) { case TextSplit.Never: Assert.AreEqual("Text on page 1\nFooter text on page 1\r\nText on page 2\r\nText on page 3", result.Value.Text); break; case TextSplit.Page: Assert.AreEqual(new List <string> { "Text on page 1\nFooter text on page 1", "Text on page 2", "Text on page 3" }, result.Value.Text); break; } }
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 ReadSignatureWithUnsignedDocument() { string blankPdfFile = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); designer.Properties[PropertyNames.ReadSignature].Value = true; designer.Properties[PropertyNames.PdfFilePath].Value = blankPdfFile; designer.Properties[PropertyNames.AuthenticationType].Value = AuthenticationType.None; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.IsFalse(result.Value.Signatures.IsSigned); Assert.AreEqual(0, result.Value.Signatures.AllSignatures.Count); AssertSignature(result.Value.Signatures.LatestSignature, true, string.Empty, string.Empty, string.Empty, DateTime.MinValue.ToUniversalTime(), true, 0, "No certificate found.", false); }
public void ReadWithNoOutput( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication inputAuth) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.Blank.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.ReadText].Value = false; designer.Properties[PropertyNames.ReadFormData].Value = false; designer.Properties[PropertyNames.ReadSignature].Value = false; var tester = new FunctionTester<ReadProvider>(); Assert.DoesNotThrow(() => tester.Execute(designer.GetProperties(), designer.GetParameters())); }
public void Split( [Values( FileAuthentication.None, FileAuthentication.Password, FileAuthentication.CertificateFile, FileAuthentication.CertificateStore)] FileAuthentication inputAuth, [Values( true, false)] bool loopResults) { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Split.pdf", this.inputDirectory); string outputFilePath = Path.Combine(this.outputDirectory, "Split.pdf"); FunctionDesigner designer = ProviderHelpers.CreateDesigner <PdfOperationsProvider>(); ConfigureInputFileFunctionValues(designer, inputAuth, inputFilePath); designer.Properties[PropertyNames.Operation].Value = Operation.Split; designer.Properties[PropertyNames.SplitLoopResults].Value = loopResults; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; var tester = new FunctionTester <PdfOperationsProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual(2, result.Value.NumberOfPages); if (loopResults) { Assert.AreEqual(2, result.ExecutionPathResult.Count()); NextResult nextResult = result.ExecutionPathResult.ElementAt(0); Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name); AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1"); nextResult = result.ExecutionPathResult.ElementAt(1); Assert.AreEqual(ExecutionPathNames.PageFiles, nextResult.Name); AssertOutputFile(nextResult.Value, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2"); } else { Assert.AreEqual(2, result.Value.PageFiles.Count); string pageFile = result.Value.PageFiles[0]; AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_1.pdf"), 1, "1"); pageFile = result.Value.PageFiles[1]; AssertOutputFile(pageFile, inputAuth, Path.Combine(this.outputDirectory, "Split_2.pdf"), 1, "2"); } }
public void ReadXfaFormDataWithInferredOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormDataXFA.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.Infer; string inferFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.InferFieldsXFA.pdf", this.inputDirectory); designer.Properties[PropertyNames.SamplePdf].Value = inferFilePath; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("John", result.Value.FormData.form1_910_93_46FullName_910_93); Assert.AreEqual("Doe", result.Value.FormData.form1_910_93_46Surname_910_93); Assert.AreEqual("*****@*****.**", result.Value.FormData.form1_910_93_46Email_910_93); Assert.AreEqual("1", result.Value.FormData.form1_910_93_46EmailMe_910_93); }
public void ReadAcroFormDataWithInferredOutput() { string inputFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); ConfigureInputFileFunctionValues(designer, FileAuthentication.None, inputFilePath); designer.Properties[PropertyNames.ReadFormData].Value = true; designer.Properties[PropertyNames.ReturnFormDataAs].Value = FormExtraction.Infer; string inferFilePath = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.Read.Resources.FormData.pdf", this.inputDirectory); designer.Properties[PropertyNames.SamplePdf].Value = inferFilePath; var tester = new FunctionTester<ReadProvider>(); FunctionResult result = tester.Execute(designer.GetProperties(), designer.GetParameters()); Assert.AreEqual("Jeremy", result.Value.FormData.First_32Name); Assert.AreEqual("Woods", result.Value.FormData.Surname); Assert.AreEqual("Male", result.Value.FormData.Gender); Assert.AreEqual("Yes", result.Value.FormData.AcceptTCs); }
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 ReadWithNoInputFileSpecified([Values(null, "")] string inputFile) { FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); designer.Properties[PropertyNames.PdfFilePath].Value = inputFile; Assert.That(() => new FunctionTester<ReadProvider>().Execute(designer.GetProperties(), designer.GetParameters()), Throws.Exception.TypeOf<ExecuteException>() .With.Property("Message").EqualTo("Value cannot be null.\r\nParameter name: PDF_32file_32path\r\nSee Code and Parameter properties for more information.")); }
public void ConcatenameWithInvalidInputFileSpecified() { string inputFilePath1 = ResourceHelpers.WriteResourceToFile("Twenty57.Linx.Components.Pdf.Tests.PdfOperations.Resources.Concatenate1.pdf", this.inputDirectory); string invalidFilePath = Path.Combine(this.inputDirectory, Path.GetRandomFileName()); 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, invalidFilePath }; designer.Properties[PropertyNames.InputAuthenticationType].Value = AuthenticationType.None; designer.Properties[PropertyNames.OutputFilePath].Value = outputFilePath; Assert.That(() => new FunctionTester <PdfOperationsProvider>().Execute(designer.GetProperties(), designer.GetParameters()), Throws.Exception.TypeOf <ExecuteException>() .With.Property("Message").EqualTo($"File [{invalidFilePath}] does not exist.\r\nSee Code and Parameter properties for more information.")); }
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); } } }
public void ReadWithInvalidInputFileSpecified() { string invalidFilePath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); Assert.IsFalse(File.Exists(invalidFilePath)); FunctionDesigner designer = ProviderHelpers.CreateDesigner<ReadProvider>(); designer.Properties[PropertyNames.PdfFilePath].Value = invalidFilePath; Assert.That(() => new FunctionTester<ReadProvider>().Execute(designer.GetProperties(), designer.GetParameters()), Throws.Exception.TypeOf<ExecuteException>() .With.Property("Message").EqualTo($"File [{invalidFilePath}] does not exist.\r\nSee Code and Parameter properties for more information.")); }