예제 #1
0
        public void UserStyleSheet_WithBodyColorBlue_MakesLettersBlue(string exeFileName)
        {
            HtmlToPdfRunner runner = new HtmlToPdfRunner(exeFileName);

            string html = @"<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
   Test Page
  </body>
</html>";

            string css = @"body { color: blue; }";

            using (TempHtmlFile htmlFile = new TempHtmlFile(html))
            {
                using (TempCssFile cssFile = new TempCssFile(css))
                {
                    using (TempPdfFile pdfFile = new TempPdfFile(this.TestContext))
                    {
                        string             commandLine = $"--user-style-sheet \"{cssFile.FilePath}\" \"{htmlFile.FilePath}\" \"{pdfFile.FilePath}\"";
                        HtmlToPdfRunResult result      = runner.Run(commandLine);
                        Assert.AreEqual(0, result.ExitCode, result.Output);

                        using (var pdfDocument = UglyToad.PdfPig.PdfDocument.Open(pdfFile.FilePath))
                        {
                            Assert.AreEqual(1, pdfDocument.NumberOfPages);
                            Page page = pdfDocument.GetPage(1);
                            Assert.IsTrue(page.Letters.All(x => (RGBColor)x.Color == new RGBColor(0, 0, 1)));
                        }
                    }
                }
            }
        }
예제 #2
0
        public void EnableLocalFileAccess_DoesNotError(string exeFileName)
        {
            HtmlToPdfRunner runner = new HtmlToPdfRunner(exeFileName);

            string css = @"body { color: blue; }";

            using (TempCssFile tempCssFile = new TempCssFile(css))
            {
                // create HTML file
                string html = $@"<!DOCTYPE html>
<html>
<head>
<link href=""file:///{tempCssFile.FilePath}"" rel=""stylesheet"">
</head>
<body>
Page 1
</body>
</html>";

                using (TempHtmlFile htmlFile = new TempHtmlFile(html, this.TestContext))
                {
                    using (TempPdfFile pdfFile = new TempPdfFile(this.TestContext))
                    {
                        string             commandLine = $"--enable-local-file-access \"{htmlFile.FilePath}\" \"{pdfFile.FilePath}\"";
                        HtmlToPdfRunResult result      = runner.Run(commandLine);
                        Assert.AreEqual(0, result.ExitCode, result.Output);

                        using (var pdfDocument = UglyToad.PdfPig.PdfDocument.Open(pdfFile.FilePath))
                        {
                            Assert.AreEqual(1, pdfDocument.NumberOfPages);
                            Page page1 = pdfDocument.GetPage(1);
                            Assert.AreEqual("Page 1", page1.Text);
                        }
                    }
                }
            }
        }