Example #1
0
 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 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");
        }
Example #3
0
        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);
        }
Example #4
0
        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);
        }
Example #5
0
        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);
        }