コード例 #1
0
        public async Task ShouldReturnExceptionWhenInputEmpty(byte[] input)
        {
            var wkHtmlToPdfBinary = Substitute.For <IWkHtmlToPdfBinary>();

            wkHtmlToPdfBinary.Execute(Arg.Any <byte[]>(), Arg.Any <TimeSpan>()).Returns(Task.FromResult(new ExecutionResult()));

            var pdf = new PdfGenerator(wkHtmlToPdfBinary);

            await Assert.ThrowsAsync <PdfConvertException>(() => pdf.Generate(input));
        }
コード例 #2
0
 private void GeneratePdf()
 {
     try
     {
         PdfGenerator pdfGenerator = new PdfGenerator(MainSourceFile, UI, Project);
         pdfGenerator.Generate();
     }
     catch (Exception ex)
     {
         UI.Log(ex);
     }
 }
コード例 #3
0
ファイル: Program.cs プロジェクト: Khaleesy/Csharp
        static void Main(string[] args)
        {
            PdfGenerator pdf = new PdfGenerator();

            PdfByte.ByteToPdfDisc(
                pdf.Generate(words[2], ImageByte.ImageToByteArray(images[0]), ImageByte.ImageToByteArray(images[1]),
                            ImageByte.ImageToByteArray(images[2]), ImageByte.ImageToByteArray(images[3])
                ), words[0], words[1]
            );

            Console.WriteLine(string.Format("Utworzono plik PDF.\nNazwa: {1}.pdf\nLokacja: {0}\nPelna sciezka: {0}{1}.pdf", words[0], words[1]));
            Console.ReadLine();
        }
コード例 #4
0
        public async Task ShouldReturnExceptionWhenProcessFailsOrTimesout()
        {
            var wkHtmlToPdfBinary = Substitute.For <IWkHtmlToPdfBinary>();

            wkHtmlToPdfBinary.Execute(Arg.Any <byte[]>(), Arg.Any <TimeSpan>()).Returns(Task.FromResult(new ExecutionResult
            {
                Success = false,
            }));

            var pdf = new PdfGenerator(wkHtmlToPdfBinary);

            await Assert.ThrowsAsync <PdfConvertException>(async() => await pdf.Generate(TestStdin));
        }
コード例 #5
0
        public async Task ShouldReturnExceptionWhenStderrExistsAndExitCodeNonZero()
        {
            var wkHtmlToPdfBinary = Substitute.For <IWkHtmlToPdfBinary>();

            wkHtmlToPdfBinary.Execute(Arg.Any <byte[]>(), Arg.Any <TimeSpan>()).Returns(Task.FromResult(new ExecutionResult
            {
                Stderr   = Encoding.UTF8.GetBytes("an error occurred"),
                ExitCode = 1
            }));

            var pdf = new PdfGenerator(wkHtmlToPdfBinary);

            await Assert.ThrowsAsync <PdfConvertException>(() => pdf.Generate(TestStdin));
        }
コード例 #6
0
        public void PDFCreatorTest()
        {
            Matrix matrix = new Matrix(new int[, ] {
                { 0, 1, 2, 3 },
                { 1, 0, 1, 2 },
                { 2, 1, 0, 4 },
                { 3, 2, 4, 0 }
            });

            (this.graph, this.edgeCost) = GraphCreator.Create(matrix);
            TryFunc <int, IEnumerable <Edge <int> > > tryGetPath = graph.ShortestPathsDijkstra(this.edgeCost, 0);

            PdfGenerator.Generate(DotGenerator <int, Edge <int> > .GetDotCode(this.graph, tryGetPath), "test");
            Assert.IsTrue(File.Exists("test.pdf"));
            File.Delete("test.pdf");
        }
コード例 #7
0
        public async Task ShouldReturnPdfBytesWhenStderrExistsButExitCodeZeroAndProcessSuccessful()
        {
            var expectedBytes = Encoding.UTF8.GetBytes("test-pdf");

            var wkHtmlToPdfBinary = Substitute.For <IWkHtmlToPdfBinary>();

            wkHtmlToPdfBinary.Execute(Arg.Any <byte[]>(), Arg.Any <TimeSpan>()).Returns(Task.FromResult(new ExecutionResult
            {
                Stderr   = new byte[] { 70 },
                Stdout   = expectedBytes,
                Success  = true,
                ExitCode = 0
            }));

            var pdf    = new PdfGenerator(wkHtmlToPdfBinary);
            var result = await pdf.Generate(TestStdin);

            Assert.Equal(result, expectedBytes);
        }
コード例 #8
0
        public void CanGeneratePdf()
        {
            var scenario = new SbeScenario {
                Title = "Scenario Title", Outcome = Outcome.Passed
            };
            var feature = new SbeFeature(title: "Feature Title", scenarios: new[] { scenario });

            feature.FeatureText = @"@current
Feature: Implemented Feature
	Some description

Scenario: Add two numbers for implemented calculator
	Given I have entered 50 into the calculator
	And I have entered 70 into the calculator
	When I press add
	Then the result should be 120 on the screen"    ;

            var collectedTests = new SbeAssembly[]
            {
                new SbeAssembly(
                    name: "some.strange.assembly",
                    epics: new[] { new SbeEpic(name: "Some Epic", features: new[] { feature }) })
            };

            string outputFileName = null;

            byte[] outputContent = null;

            var generator = new PdfGenerator("testing", OutputFilter.All, (file, bytes) => { outputFileName = file; outputContent = bytes; });

            generator.Generate(collectedTests);

            Assert.That(outputFileName, Is.EqualTo("\\some.strange.assembly.testing.sbe.pdf"), "FileName");

            var firstFourBytes = Convert.ToBase64String(outputContent.Take(4).ToArray());

            Assert.That(firstFourBytes, Is.EqualTo("JVBERg=="));
        }
コード例 #9
0
        protected void Generate(string docxSampleFileName)
        {
            if (!Directory.Exists(_outputFolder))
            {
                Directory.CreateDirectory(_outputFolder);
            }

            var outputFileName = $"{_outputFolder}/{docxSampleFileName}.pdf";

            if (File.Exists(outputFileName))
            {
                File.Delete(outputFileName);
            }

            var inputFileName = $"{_samplesFolder}/{docxSampleFileName}.docx";

            using var docxStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read);

            var pdfGenerator = new PdfGenerator();
            var pdf          = pdfGenerator.Generate(docxStream, this.Options);

            pdf.Save(outputFileName);
        }