public void ControllerInstance_Actions()
        {
            string documentxml = @"<?xml version='1.0' encoding='utf-8' ?>
                                <?scryber parser-mode='Strict' parser-log='false' append-log='false' log-level='Warnings' 
                                          controller='Scryber.Core.UnitTests.Generation.SimpleDocument_Controller, Scryber.UnitTests' ?>
                                <doc:Document xmlns:doc='Scryber.Components, Scryber.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe'
                                              id='outerdoc' auto-bind='true'>
                                  <Pages>

                                    <doc:Page id='titlepage' on-init='handlepageinit' on-loaded='handlepageload'
                                                             on-databinding='handlepagebinding' on-databound='handlepagebound'
                                                             on-prelayout='handleprelayout' on-postlayout='handlepostlayout'
                                                             on-prerender='handleprerender' on-postrender='handlepostrender' >
                                      <Content>
                                        <doc:Label id='mylabel' />
                                      </Content>
                                    </doc:Page>

                                  </Pages>
                                </doc:Document>";

            Document parsed;

            using (System.IO.StringReader sr = new System.IO.StringReader(documentxml))
            {
                parsed = Document.ParseDocument(sr, ParseSourceType.Other);
            }

            Assert.IsNotNull(parsed);
            Assert.IsNotNull(parsed.Controller);
            Assert.AreEqual(typeof(SimpleDocument_Controller), parsed.Controller.GetType());
            TestContext.WriteLine("Controller has been set correctly");

            using (var ms = DocStreams.GetOutputStream("ControllerInstanceActions.pdf"))
            {
                parsed.SaveAsPDF(ms);
            }

            TestContext.WriteLine("Document has been processed");

            Assert.IsNotNull(parsed);
            Assert.IsNotNull(parsed.Controller);

            SimpleDocument_Controller controller = (SimpleDocument_Controller)parsed.Controller;
            List <string>             invoked    = controller.Invoked;

            Assert.AreEqual(8, invoked.Count);
            TestContext.WriteLine("Controller has 8 items in the invoked list. 1 per event.");

            Assert.IsTrue(invoked.Contains("init"));
            Assert.IsTrue(invoked.Contains("load"));
            Assert.IsTrue(invoked.Contains("binding"));
            Assert.IsTrue(invoked.Contains("bound"));
            Assert.IsTrue(invoked.Contains("pre-layout"));
            Assert.IsTrue(invoked.Contains("post-layout"));
            Assert.IsTrue(invoked.Contains("pre-render"));
            Assert.IsTrue(invoked.Contains("post-render"));

            TestContext.WriteLine("All events have been processed and added to the invoked collection");
        }
Exemple #2
0
        public void RemoteCssFileLoading()
        {
            var path = "https://raw.githubusercontent.com/richard-scryber/scryber.core/master/Scryber.Core.UnitTest/Content/HTML/CSS/Include.css";
            var src  = @"<html xmlns='http://www.w3.org/1999/xhtml' >
                            <head>
                                <title>Html document title</title>
                                <link href='" + path + @"' rel='stylesheet' />
                            </head>

                            <body class='grey' style='margin:20px;' >
                                <p id='myPara' >This is a paragraph of content</p>
                            </body>

                        </html>";

            using (var sr = new System.IO.StringReader(src))
            {
                var doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
                Assert.IsInstanceOfType(doc, typeof(HTMLDocument));

                using (var stream = DocStreams.GetOutputStream("HtmlRemoteCSS.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }


                var body = _layoutcontext.DocumentLayout.AllPages[0].ContentBlock;

                Assert.AreEqual("Html document title", doc.Info.Title, "Title is not correct");

                //This has been loaded from the remote file
                Assert.AreEqual((PDFColor)"#808080", body.FullStyle.Background.Color, "Fill colors do not match");
            }
        }
        public void ValidateRequiredItemsSuccess()
        {
            var controllerType = "Scryber.Core.UnitTests.Mocks.MockControllerClass, Scryber.UnitTests";

            var src = @"<?xml version='1.0' encoding='utf-8' ?>
                        <?scryber controller='" + controllerType + @"' ?>

                        <doc:Document xmlns:doc='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Components.xsd'
                                      id='MyDocument' >
                          <Pages>
                          </Pages>

                        </doc:Document>";

            using (var reader = new System.IO.StringReader(src))
            {
                var doc        = Document.ParseDocument(reader, ParseSourceType.DynamicContent);
                var controller = doc.Controller as Mocks.MockControllerClass;
                Assert.IsNotNull(controller);

                var mockresults = controller.Results;


                using (var stream = DocStreams.GetOutputStream("BindingControllerValidated.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
Exemple #4
0
        public void HtmlIFrameFragments()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/BodyFraming.html");

            using (var doc = Document.ParseDocument(path))
            {
                var model = new
                {
                    fragmentContent = "Content for the fragment"
                };
                doc.Params["model"] = model;

                using (var stream = DocStreams.GetOutputStream("BodyFraming.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }
                var para = doc.FindAComponentById("FrameInner") as Paragraph;
                Assert.IsNotNull(para);

                //Get the second paragraph
                para = doc.FindAComponentById("FrameDynamic") as Paragraph;
                Assert.AreEqual(2, para.Contents.Count);

                //Check that the inner text of the para matches the bound value.
                var span = para.Contents[1] as IPDFTextLiteral;
                Assert.AreEqual(model.fragmentContent, span.Text);
            }
        }
Exemple #5
0
        public void SimpleDocumentParsing()
        {
            var src = @"<!DOCTYPE html>
                        <html xmlns='http://www.w3.org/1999/xhtml' >
                            <head>
                                <title>Html document title</title>
                            </head>

                            <body class='strong' style='margin:20px;' >
                                <p id='myPara' style='border: solid 1px blue; padding: 5px;' >This is a paragraph of content</p>
                            </body>

                        </html>";

            using (var sr = new System.IO.StringReader(src))
            {
                var doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
                Assert.IsInstanceOfType(doc, typeof(HTMLDocument));

                using (var stream = DocStreams.GetOutputStream("HtmlSimple.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }


                var body = _layoutcontext.DocumentLayout.AllPages[0].ContentBlock;
                var p    = body.Columns[0].Contents[0] as PDFLayoutBlock;
                Assert.AreEqual("Html document title", doc.Info.Title, "Title is not correct");
            }
        }
Exemple #6
0
        public void TopAndTailed()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/topandtailed.html");

            using (var doc = Document.ParseDocument(path))
            {
                doc.Params["title"] = "Title in code";

                using (var stream = DocStreams.GetOutputStream("topandtailed.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }

                var pg = doc.Pages[0] as Section;
                Assert.IsNotNull(pg.Header);
                Assert.IsNotNull(pg.Footer);

                var body = _layoutcontext.DocumentLayout.AllPages[0];
                Assert.IsNotNull(body.HeaderBlock);
                Assert.IsNotNull(body.FooterBlock);
            }
        }
Exemple #7
0
        public void MarkdownToPDFTest()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/Markdown/Markdown.md");
            path = System.IO.Path.GetFullPath(path);
            var content = System.IO.File.ReadAllText(path);

            var doc = new Document();
            var pg  = new Section();

            pg.FontSize = 12;
            pg.Margins  = new Scryber.Drawing.PDFThickness(20);
            var frag = new HtmlFragment();

            doc.Pages.Add(pg);
            pg.Contents.Add(frag);
            frag.ContentsAsString = content;
            frag.Format           = HtmlFormatType.Markdown;

            using (var output = DocStreams.GetOutputStream("MarkdownTest.pdf"))
            {
                doc.LayoutComplete += Doc_LayoutComplete;
                doc.SaveAsPDF(output);
            }
        }
Exemple #8
0
        public void StandardFonts_Test()
        {
            string documentxml = @"<?xml version='1.0' encoding='utf-8' ?>
                                <?scryber parser-mode='Strict' parser-log='false' append-log='false' log-level='Warnings' ?>
                                <doc:Document xmlns:doc='Scryber.Components, Scryber.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe'
                                              xmlns:styles='Scryber.Styles, Scryber.Styles, Version=1.0.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe'
                                              id='outerdoc' >
                                  <Pages>

                                    <doc:Page id='titlepage' >
                                      <Content>
                                        <doc:Span id='mylabel' styles:font-family='Helvetica' >This is text in the Helvetica font</doc:Span><doc:Br/>
                                        <doc:Span id='mylabel' styles:font-family='Times' >This is text in the Times font</doc:Span><doc:Br/>
                                        <doc:Span id='mylabel' styles:font-family='Courier' >This is text in the Courier font</doc:Span><doc:Br/>
                                        <doc:Span id='mylabel' styles:font-family='Zapf Dingbats' >This is text in the Dingbats font</doc:Span><doc:Br/>
                                        <doc:Span id='mylabel' styles:font-family='Symbol' >This is text in the Symbol font</doc:Span><doc:Br/>
                                        <doc:Span id='mylabel' styles:font-family='Times' styles:font-bold='true' >This is text in the Times font that is bold</doc:Span><doc:Br/>
                                      </Content>
                                    </doc:Page>

                                  </Pages>
                                </doc:Document>";

            Document parsed;

            using (System.IO.StringReader sr = new System.IO.StringReader(documentxml))
            {
                parsed = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
            }

            parsed.LayoutComplete += StandardFont_LayoutComplete;
            using (var ms = DocStreams.GetOutputStream("StandardFont.pdf"))
                parsed.SaveAsPDF(ms);
        }
        public void PageSizeA3()
        {
            Document doc = new Document();
            Page     pg  = new Page();

            pg.PaperSize = PaperSize.A3;
            doc.Pages.Add(pg);

            pg.Contents.Add(new TextLiteral("A3"));
            pg.HorizontalAlignment = HorizontalAlignment.Center;
            pg.VerticalAlignment   = VerticalAlignment.Top;
            pg.FontSize            = 30;
            pg.Margins             = new Scryber.Drawing.PDFThickness(20);

            doc.ViewPreferences.PageLayout = PageLayoutMode.SinglePage;

            using (var ms = DocStreams.GetOutputStream("PageSizeA3.pdf"))
            {
                doc.LayoutComplete += Doc_LayoutDocument;
                doc.SaveAsPDF(ms);
            }

            PDFLayoutPage layoutPg = layoutDoc.AllPages[0];

            Assert.AreEqual((int)layoutPg.Width.ToMillimeters().Value, 297);
            Assert.AreEqual((int)layoutPg.Height.ToMillimeters().Value, 420);
        }
Exemple #10
0
        public void DefaultFont_Test()
        {
            string documentxml = @"<?xml version='1.0' encoding='utf-8' ?>
                                <?scryber parser-mode='Strict' parser-log='false' append-log='false' log-level='Warnings' ?>
                                <doc:Document xmlns:doc='Scryber.Components, Scryber.Components, Version=1.0.0.0, Culture=neutral, PublicKeyToken=872cbeb81db952fe'
                                              id='outerdoc' >
                                  <Pages>

                                    <doc:Page id='titlepage' >
                                      <Content>
                                        <doc:Span id='mylabel' >This is text in the default font</doc:Span>
                                      </Content>
                                    </doc:Page>

                                  </Pages>
                                </doc:Document>";

            Document parsed;

            using (System.IO.StringReader sr = new System.IO.StringReader(documentxml))
            {
                parsed = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
            }

            parsed.LayoutComplete += DefaultFont_LayoutComplete;
            using (var ms = DocStreams.GetOutputStream("DefaultFont.pdf"))
                parsed.SaveAsPDF(ms);
        }
Exemple #11
0
        public void LargeFileTest()

        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/LargeFile.html");

            var data = new
            {
                Items = GetListItems(10)
            };

            using (var doc = Document.ParseDocument(path))
            {
                doc.Params["model"] = data;
                using (var stream = DocStreams.GetOutputStream("LargeFile.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }

            data = new
            {
                Items = GetListItems(10000)
            };
            using (var doc = Document.ParseDocument(path))
            {
                doc.Params["model"] = data;
                using (var stream = DocStreams.GetOutputStream("LargeFile.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
        public void PlaceholderTemplate_ComponentString()
        {
            var src = templateSrc;

            var template = GetTemplateComponentStringData();

            using (System.IO.StringReader sr = new System.IO.StringReader(src))
            {
                Document doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
                doc.Params["datatable"] = template;


                using (var stream = DocStreams.GetOutputStream("PlaceHolderTemplate.pdf"))
                {
                    doc.SaveAsPDF(stream);
                    var placeholder = doc.FindAComponentById("DynamicContent") as PlaceHolder;

                    //placeholder should contain a template instance, that contains the table.

                    Assert.IsTrue(placeholder.Contents.Count > 0);
                    Assert.IsInstanceOfType(placeholder.Contents[0], typeof(TemplateInstance));

                    var instance = placeholder.Contents[0] as TemplateInstance;
                    Assert.IsTrue(instance.HasContent);
                    Assert.IsInstanceOfType(instance.Content[0], typeof(TableGrid));
                }
            }
        }
 public void ProcessHellowWorldCode()
 {
     using (Document doc = this.GenerateHelloWorld())
     {
         using (var ms = DocStreams.GetOutputStream("HelloWorldCode.pdf"))
             doc.SaveAsPDF(ms);
     }
 }
 //[TestMethod()]
 //[TestCategory("Hello World")]
 public void ProcessHelloWorld()
 {
     using (Document doc = Document.ParseDocument("./HelloWorld.pdfx"))
     {
         using (var ms = DocStreams.GetOutputStream("HelloWorld.pdf"))
             doc.SaveAsPDF(ms);
     }
 }
        public void PanelWithMinWidthAndHeight()
        {
            Document doc = new Document();
            Page     pg  = new Page();

            pg.Style.PageStyle.Width  = PageWidth;
            pg.Style.PageStyle.Height = PageHeight;

            doc.Pages.Add(pg);

            int expectedMinWidth  = 200;
            int expectedMinHeight = 50;

            Panel panel = new Panel();

            panel.MinimumWidth  = expectedMinWidth;
            panel.MinimumHeight = expectedMinHeight;
            panel.BorderColor   = Scryber.Drawing.PDFColors.Black;
            pg.Contents.Add(panel);


            Label lbl = new Label()
            {
                Text = "Not wide enough"
            };

            panel.Contents.Add(lbl); //Will not push the panel beyond its minimumn width


            using (var ms = DocStreams.GetOutputStream("PanelsMinWidthAndHeight.pdf"))
            {
                doc.LayoutComplete += Doc_LayoutComplete;
                doc.SaveAsPDF(ms);
            }

            PDFLayoutPage   layoutpg    = layout.AllPages[0];
            PDFLayoutBlock  pgcontent   = layoutpg.ContentBlock;
            PDFLayoutRegion pgregion    = pgcontent.Columns[0];
            PDFLayoutBlock  panelBlock  = pgregion.Contents[0] as PDFLayoutBlock;
            PDFLayoutRegion panelregion = panelBlock.Columns[0];

            Assert.IsNotNull(panelBlock, "The layout block in the page column should not be null");

            //block width and height should be the minimums
            Assert.AreEqual(expectedMinWidth, panelBlock.Width, "Panel block should be " + expectedMinWidth + " wide");
            Assert.AreEqual(expectedMinHeight, panelBlock.Height, "Panel block should be " + expectedMinHeight + " high");

            //Total bounds
            Assert.AreEqual(expectedMinWidth, panelBlock.TotalBounds.Width, "Panel block total width should be " + expectedMinWidth);
            Assert.AreEqual(expectedMinHeight, panelBlock.TotalBounds.Height, "Panel block total height should be " + expectedMinHeight);
            Assert.AreEqual(0, panelBlock.TotalBounds.X, "Panel block total X should be 0");
            Assert.AreEqual(0, panelBlock.TotalBounds.Y, "Panel block total Y should be 0");

            Assert.IsTrue(expectedMinWidth > panelregion.TotalBounds.Width, "Panel region total width should be less than " + expectedMinWidth);
            Assert.IsTrue(expectedMinHeight > panelregion.TotalBounds.Height, "Panel region total height should be less than " + expectedMinHeight);
            Assert.AreEqual(0, panelregion.TotalBounds.X, "Panel region total X should be 0");
            Assert.AreEqual(0, panelregion.TotalBounds.Y, "Panel region total Y should be 0");
        }
Exemple #16
0
        public void BodyTemplatingWithJson()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/bodytemplating.html");

            StringBuilder content = new StringBuilder();


            int total = 0;
            int count = 100;

            for (var i = 0; i < count; i++)
            {
                var val = i + 1;
                if (i > 0)
                {
                    content.Append(",");
                }

                content.Append("{ \"Name\": \"Name " + val.ToString() + "\", \"Cost\": \"£" + val.ToString() + ".00\" }\r\n");

                total += val;
            }

            var modelJson = "{\r\n" +
                            "\"Items\" : [" + content.ToString() +
                            "],\r\n" +
                            "\"Total\" : {\r\n" +
                            "\"Name\" : \"Total\",\r\n" +
                            "\"Cost\" : \"£" + total + ".00\"\r\n" +
                            "}\r\n" +
                            "}";

            var model = Newtonsoft.Json.JsonConvert.DeserializeObject(modelJson);

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("bodytemplatingWithJson.pdf"))
                {
                    doc.Params["model"] = model;
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }
                var pg = doc.Pages[0] as Section;
                Assert.IsNotNull(pg.Header);
                Assert.IsNotNull(pg.Footer);

                var body = _layoutcontext.DocumentLayout.AllPages[0];
                Assert.IsNotNull(body.HeaderBlock);
                Assert.IsNotNull(body.FooterBlock);

                var table = doc.FindAComponentById("grid") as TableGrid;
                Assert.IsNotNull(table);
                Assert.AreEqual(2 + count, table.Rows.Count);
            }
        }
        public void TestSimpleStylePageBreak()
        {
            var src = @"<?xml version='1.0' encoding='UTF-8' ?>
            <doc:Document xmlns:doc='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Components.xsd'
                          xmlns:style='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Styles.xsd'>
              <Pages>
                <doc:Section style:padding='20pt' style:fill-color='#880000' >
                  <Content>
                    <doc:Div id='pg1' style:fill-color='#008800'>
                      This is some content
                    </doc:Div>
                    <doc:Div id='pg2' style:fill-color='#000088'
                             style:page-break-before='true' 
                             style:page-break-after='true' >
                      This should come on the next page
                    </doc:Div>
                    <doc:Div id='pg3'>
                        This should come on the last page
                    </doc:Div>
                  </Content>
                </doc:Section>
              </Pages>
            </doc:Document>";

            using (var ms = new System.IO.StringReader(src))
            {
                var doc = Document.ParseDocument(ms, ParseSourceType.DynamicContent);
                using (var stream = DocStreams.GetOutputStream("PageBreaksInline.pdf"))
                    doc.SaveAsPDF(stream);

                var arrange = doc.Pages[0].GetFirstArrangement() as PDFComponentMultiArrangement;
                Assert.IsNotNull(arrange, "The page arrangement should be a multi page arrangement");
                Assert.AreEqual(0, arrange.PageIndex, "First arrangement should be on page 0");

                arrange = arrange.NextArrangement;
                Assert.IsNotNull(arrange, "Should be a second arrangement on the page");
                Assert.AreEqual(1, arrange.PageIndex, "Second arrangement should be page 1");

                arrange = arrange.NextArrangement;
                Assert.IsNotNull(arrange, "Should be a third arrangement on the page");
                Assert.AreEqual(2, arrange.PageIndex, "Third arrangement should be page 2");

                var pg1 = doc.FindAComponentById("pg1");
                var pg2 = doc.FindAComponentById("pg2");
                var pg3 = doc.FindAComponentById("pg3");

                var divArrange = pg1.GetFirstArrangement();
                Assert.AreEqual(0, divArrange.PageIndex, "First arrangement should be on page 0");

                divArrange = pg2.GetFirstArrangement();
                Assert.AreEqual(1, divArrange.PageIndex, "Second arrangement should be on page 1");

                divArrange = pg3.GetFirstArrangement();
                Assert.AreEqual(2, divArrange.PageIndex, "Third arrangement should be on page 2");
            }
        }
Exemple #18
0
        public void SectionOverflow()
        {
            const int PageWidth  = 200;
            const int PageHeight = 300;

            Document doc     = new Document();
            Section  section = new Section();

            section.Style.PageStyle.Width  = PageWidth;
            section.Style.PageStyle.Height = PageHeight;
            doc.Pages.Add(section);

            Div top = new Div()
            {
                Height = PageHeight - 100
            };

            section.Contents.Add(top);

            //div is too big for the remaining space on the page
            Div tooverflow = new Div()
            {
                Height = 150
            };

            section.Contents.Add(tooverflow);

            using (var ms = DocStreams.GetOutputStream("SectionOverflow.pdf"))
            {
                doc.LayoutComplete += Doc_LayoutComplete;
                doc.SaveAsPDF(ms);
            }

            Assert.AreEqual(2, layout.AllPages.Count);


            //Check that the first page has the same dimensions.
            PDFLayoutPage firstpage = layout.AllPages[0];

            Assert.AreEqual(PageWidth, firstpage.Width);
            Assert.AreEqual(PageHeight, firstpage.Height);


            //Check that the overflowed page has the same dimensions.
            PDFLayoutPage lastpage = layout.AllPages[1];

            Assert.AreEqual(PageWidth, lastpage.Width);
            Assert.AreEqual(PageHeight, lastpage.Height);

            //Check that the block has overflowed to 0 y offset
            PDFLayoutBlock overflowedblock = lastpage.ContentBlock.Columns[0].Contents[0] as PDFLayoutBlock;

            Assert.AreEqual(0, overflowedblock.TotalBounds.Y);
            Assert.AreEqual(150, overflowedblock.Height);
        }
Exemple #19
0
        public void SimpleDocumentParsing2()
        {
            var src = @"<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
    <meta charset='utf-8' />
    <title>First Test</title>

    <style >
        body {
            background-color:#CCC;
            padding:20pt;
            font-size:medium;
            margin:0pt;
            font-family: 'Segoe UI';
        }

        h1{
            font-size:30pt;
            font-weight:normal;
        }

    </style>
</head>
<body>
    <div>Above the heading
        <h1>This is my first heading</h1>
        <div>And this is the content below the heading that should flow across multiple lines within the page and flow nicely along those lines.</div>
    </div>
</body>
</html>";

            using (var sr = new System.IO.StringReader(src))
            {
                var doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent);
                doc.RenderOptions.Compression = OutputCompressionType.None;

                Assert.IsInstanceOfType(doc, typeof(HTMLDocument));

                using (var stream = DocStreams.GetOutputStream("HtmlSimple2.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }

                var page = doc.Pages[0] as Page;
                var div  = page.Contents[0] as Div;
                var h1   = div.Contents[1] as HTMLHead1;
                Assert.IsNotNull(h1, "No heading found");
                Assert.AreEqual(1, h1.Contents.Count);
                var content = h1.Contents[0];
            }
        }
Exemple #20
0
        public void DisplayNoneHidden()
        {
            dynamic[] all   = new dynamic[100];
            int       total = 0;

            for (var i = 0; i < 100; i++)
            {
                var val = i + 1;
                //Hide every tenth one.
                var vis = (i % 10 == 0) ? "display:none" : "";

                all[i] = new { Name = "Name " + val.ToString(), Cost = "£" + val + ".00", Style = vis };
                if (i % 10 != 0)
                {
                    total += val;
                }
            }

            var model = new
            {
                Items = all,
                Total = new
                {
                    Name = "Total",
                    Cost = "£" + total + ".00"
                }
            };


            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/displaynone.html");

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("htmlDisplayNone.pdf"))
                {
                    doc.Params["model"] = model;
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }
                var layout = this._layoutcontext.DocumentLayout;
                var pDiv   = layout.AllPages[0].ContentBlock.Columns[0].Contents[0] as PDFLayoutBlock;
                Assert.AreEqual(pDiv.Columns[0].Contents.Count, 2, "There should be only 2 layout items in the set of paragraphs");

                var p1 = pDiv.Columns[0].Contents[0] as PDFLayoutBlock;
                Assert.AreEqual("pshow1", p1.Owner.ID);

                var p2 = pDiv.Columns[0].Contents[1] as PDFLayoutBlock;
                Assert.AreEqual("pshow2", p2.Owner.ID);
            }
        }
        public void SVGFSimple()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/SVG/SVGSimple.html");

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("SVGSimple.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
        public void PanelBeyondMinWidthAndHeight()
        {
            Document doc = new Document();
            Page     pg  = new Page();

            pg.Style.PageStyle.Width  = PageWidth;
            pg.Style.PageStyle.Height = PageHeight;
            pg.Style.Font.FontSize    = 18;

            doc.Pages.Add(pg);

            int expectedMinWidth  = 200;
            int expectedMinHeight = 100;

            Panel panel = new Panel();

            panel.MinimumWidth  = expectedMinWidth;
            panel.MinimumHeight = expectedMinHeight;
            panel.BorderColor   = Scryber.Drawing.PDFColors.Black;
            pg.Contents.Add(panel);

            Label lbl = new Label()
            {
                Text = "This label is wide enough to go beyond the 200pt minimum width of the panel " +
                       "and also the width of the page, so should flow onto the next line and keep going beyond the minimum height of the " +
                       "panel. Therefore extending beyond the bounds of both min- values."
            };

            panel.Contents.Add(lbl); //WILL push the panel beyond its minimumn width


            using (var ms = DocStreams.GetOutputStream("PanelsBeyondMinWidthAndHeight.pdf"))
            {
                doc.LayoutComplete += Doc_LayoutComplete;
                doc.SaveAsPDF(ms);
            }

            PDFLayoutPage   layoutpg    = layout.AllPages[0];
            PDFLayoutBlock  pgcontent   = layoutpg.ContentBlock;
            PDFLayoutRegion pgregion    = pgcontent.Columns[0];
            PDFLayoutBlock  panelBlock  = pgregion.Contents[0] as PDFLayoutBlock;
            PDFLayoutRegion panelregion = panelBlock.Columns[0];

            Assert.IsNotNull(panelBlock, "The layout block in the page column should not be null");

            //block width and height should be greater than the minimum width, but not beyond the height.
            Assert.IsTrue(expectedMinWidth < panelBlock.Width, "Panel block should be greater than " + expectedMinWidth + " wide");
            Assert.IsTrue(PageWidth > panelBlock.Width, "Panel block should not go beyond the page width");
            Assert.IsTrue(expectedMinHeight < panelBlock.Height, "Panel block should be greater than " + panelBlock.Height + " high");
        }
Exemple #23
0
        public void InvalidBackgroundImage()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/InvalidBackgroundImage.html");
            bool error = false;

            try
            {
                using (var doc = Document.ParseDocument(path))
                {
                    doc.ConformanceMode = ParserConformanceMode.Strict;
                    using (var stream = DocStreams.GetOutputStream("InvalidBackgroundImage.pdf"))
                    {
                        doc.LayoutComplete += SimpleDocumentParsing_Layout;
                        doc.SaveAsPDF(stream);
                    }
                }
            }
            catch (Exception ex)
            {
                error = true;
            }

            Assert.IsTrue(error, "An error was not raised when a background image was not available in Strict mode");


            error = true;
            try
            {
                using (var doc = Document.ParseDocument(path))
                {
                    using (var stream = DocStreams.GetOutputStream("InvalidBackgroundImage.pdf"))
                    {
                        //Set the conformance to lax
                        doc.ConformanceMode = ParserConformanceMode.Lax;

                        doc.LayoutComplete += SimpleDocumentParsing_Layout;
                        doc.SaveAsPDF(stream);
                    }
                }
                error = false;
            }
            catch (Exception ex)
            {
                error = true;
            }

            Assert.IsFalse(error, "An error was raised when a background image was not available in Lax mode");
        }
Exemple #24
0
        public void HelloWorld()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/HelloWorld.html");

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("HelloWorld.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
Exemple #25
0
        public void BordersAndSides()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/BorderSides.html");

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("BorderSides.pdf"))
                {
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }
            }
        }
Exemple #26
0
        public void DocumentationOutput()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/documentation.html");
            Document doc;

            using (doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("documentation.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
        public void SVGComponents()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/SVG/SVGComponents.html");

            using (var doc = Document.ParseDocument(path))
            {
                doc.RenderOptions.Compression = OutputCompressionType.None;

                using (var stream = DocStreams.GetOutputStream("SVGComponents.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
Exemple #28
0
        public void RestrictedProtectedHtml()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/RestrictedHtml.html");

            using (var doc = Document.ParseDocument(path))
            {
                doc.PasswordProvider = new Scryber.Secure.DocumentPasswordProvider("Password", "Password");
                doc.Params["title"]  = "Hello World";
                using (var stream = DocStreams.GetOutputStream("ProtectedHtml.pdf"))
                {
                    doc.SaveAsPDF(stream);
                }
            }
        }
Exemple #29
0
        public void BodyTemplating()
        {
            var path = System.Environment.CurrentDirectory;

            path = System.IO.Path.Combine(path, "../../../Content/HTML/bodytemplating.html");

            dynamic[] all   = new dynamic[100];
            int       total = 0;

            for (var i = 0; i < 100; i++)
            {
                var val = i + 1;
                all[i] = new { Name = "Name " + val.ToString(), Cost = "£" + val + ".00" };
                total += val;
            }

            var model = new
            {
                Items = all,
                Total = new
                {
                    Name = "Total",
                    Cost = "£" + total + ".00"
                }
            };

            using (var doc = Document.ParseDocument(path))
            {
                using (var stream = DocStreams.GetOutputStream("bodytemplating.pdf"))
                {
                    doc.Params["model"] = model;
                    doc.LayoutComplete += SimpleDocumentParsing_Layout;
                    doc.SaveAsPDF(stream);
                }
                var pg = doc.Pages[0] as Section;
                Assert.IsNotNull(pg.Header);
                Assert.IsNotNull(pg.Footer);

                var body = _layoutcontext.DocumentLayout.AllPages[0];
                Assert.IsNotNull(body.HeaderBlock);
                Assert.IsNotNull(body.FooterBlock);

                var table = doc.FindAComponentById("grid") as TableGrid;
                Assert.IsNotNull(table);
                Assert.AreEqual(2 + model.Items.Length, table.Rows.Count);
            }
        }
        public void StylePriorityNested_Test()
        {
            //Checks that the nested values are used in a style stack
            //for inherited styles

            var src = @"<?xml version='1.0' encoding='UTF-8' ?>
            <doc:Document xmlns:doc='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Components.xsd'
                          xmlns:style='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Styles.xsd'>
              <Pages>
                <doc:Section id='pg' style:padding='20pt' style:fill-color='#880000' style:bg-color='#FF0000' >
                  <Content>
                    <doc:Div id='first' style:fill-color='#008800' style:bg-color='#00FF00' >
                      This should be green
                    </doc:Div>
                    <doc:Div id='second' style:fill-color='#000088' style:bg-color='#0000FF'  >
                      This should be blue
                    </doc:Div>
                    This should be red
                  </Content>
                </doc:Section>
              </Pages>
            </doc:Document>";

            using (var ms = new System.IO.StringReader(src))
            {
                var doc = Document.ParseDocument(ms, ParseSourceType.DynamicContent);

                using (var stream = DocStreams.GetOutputStream("StylePriorityNested.pdf"))
                    doc.SaveAsPDF(stream);

                var pg     = doc.FindAComponentById("pg");
                var first  = doc.FindAComponentById("first");
                var second = doc.FindAComponentById("second");

                var style = pg.GetFirstArrangement().FullStyle;
                Assert.AreEqual((PDFColor)"#880000", style.Fill.Color, "Page fill color incorrect");
                Assert.AreEqual((PDFColor)"#FF0000", style.Background.Color, "Page bg color incorrect");

                style = first.GetFirstArrangement().FullStyle;
                Assert.AreEqual((PDFColor)"#008800", style.Fill.Color, "First Div fill color incorrect");
                Assert.AreEqual((PDFColor)"#00FF00", style.Background.Color, "First div bg color incorrect");

                style = second.GetFirstArrangement().FullStyle;
                Assert.AreEqual((PDFColor)"#000088", style.Fill.Color, "Second Div fill color incorrect");
                Assert.AreEqual((PDFColor)"#0000FF", style.Background.Color, "Second Div bg color incorrect");
            }
        }