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"); }
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"); } }
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); }
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]; } }
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 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"); }
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); } } }
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"); }
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 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 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); } } }
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); } } }
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); } } }
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"); } }
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 DataImageFactory_Test() { var html = @"<html xmlns='http://www.w3.org/1999/xhtml' ><body style='padding:20pt;' > <img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==' alt='Red dot' /> </body></html>"; using (var sr = new System.IO.StringReader(html)) { using (var doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent)) { using (var stream = DocStreams.GetOutputStream("DataImage.pdf")) { doc.SaveAsPDF(stream); } } } }
public void MissingImageException_Test() { var service = Scryber.ServiceProvider.GetService <IScryberConfigurationService>(); var prev = service.ImagingOptions.AllowMissingImages; service.ImagingOptions.AllowMissingImages = false; var pdfx = @"<?xml version='1.0' encoding='utf-8' ?> <doc:Document xmlns:doc='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Components.xsd' xmlns:styles='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Styles.xsd' xmlns:data='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Data.xsd' > <Params> <doc:Object-Param id='MyImage' /> </Params> <Pages> <doc:Page styles:margins='20pt'> <Content> <doc:Image id='LoadedImage' src='DoesNotExist.png' /> </Content> </doc:Page> </Pages> </doc:Document>"; bool caught = false; try { Document doc; using (var reader = new System.IO.StringReader(pdfx)) doc = Document.ParseDocument(reader, ParseSourceType.DynamicContent); using (var stream = DocStreams.GetOutputStream("MissingImagesDisAllowed.pdf")) doc.SaveAsPDF(stream); } catch (Exception) { caught = true; } service.ImagingOptions.AllowMissingImages = prev; Assert.IsTrue(caught, "No Exception was raised for a missing image"); }
public void RestrictedWithoutPasswordHtml() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/RestrictedHtml.html"); using (var doc = Document.ParseDocument(path)) { //Need to set this, otherwise the doc.ConformanceMode = ParserConformanceMode.Lax; doc.Params["title"] = "Hello World"; using (var stream = DocStreams.GetOutputStream("RestrictedNoPasswordHtml.pdf")) { doc.SaveAsPDF(stream); } } }
public void AbsolutelyPositioned() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/HtmlAbsolutePositioned.html"); using (var doc = Document.ParseDocument(path)) { //pass paramters as needed, supporting simple values, arrays or complex classes. using (var stream = DocStreams.GetOutputStream("HtmlAbsolutePositioned.pdf")) { doc.SaveAsPDF(stream); } } }
public void BodyWithMultipleColumns() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/bodyWithMultipleColumns.html"); using (var doc = Document.ParseDocument(path)) { //pass paramters as needed, supporting simple values, arrays or complex classes. using (var stream = DocStreams.GetOutputStream("bodyWithMultipleColumns.pdf")) { doc.SaveAsPDF(stream); } } }
public void ValidateSelectorUse() { string sansFontFamily = "\"Does not exist\", Futura, Arial, sans-serif"; string serifFontFamily = "\"ITC Clearface\", Romana, serif "; 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' > <Styles> <styles:Style match='doc:Span.sans' > <styles:Font family='" + sansFontFamily + @"'/> </styles:Style> <styles:Style match='doc:Span.serif' > <styles:Font family='" + serifFontFamily + @"'/> </styles:Style> </Styles> <Pages> <doc:Page id='titlepage' > <Content> <doc:Span id='mylabel' styles:class='sans' >This is text in the Sans family font that will flow across multiple lines and show the expected default leading for the font</doc:Span><doc:Br/> <doc:Span id='mylabel' styles:class='serif' >This is text in the Times font that will flow across multiple lines and show the expected default leading for the font</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 += SelectorFont_LayoutComplete; using (var ms = DocStreams.GetOutputStream("FontSelectorChoice.pdf")) parsed.SaveAsPDF(ms); }
public void MissingImageException_Test() { ConfigClassInitialize(); var pdfx = @"<?xml version='1.0' encoding='utf-8' ?> <doc:Document xmlns:doc='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Components.xsd' xmlns:styles='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Styles.xsd' xmlns:data='http://www.scryber.co.uk/schemas/core/release/v1/Scryber.Data.xsd' > <Params> <doc:Object-Param id='MyImage' /> </Params> <Pages> <doc:Page styles:margins='20pt'> <Content> <doc:Image id='LoadedImage' src='DoesNotExist.png' /> </Content> </doc:Page> </Pages> </doc:Document>"; bool caught = false; try { Document doc; using (var reader = new System.IO.StringReader(pdfx)) doc = Document.ParseDocument(reader, ParseSourceType.DynamicContent); using (var stream = DocStreams.GetOutputStream("MissingImageTest.pdf")) doc.SaveAsPDF(stream); } catch (Exception) { caught = true; } Assert.IsFalse(caught, "An Exception was raised for a missing image"); ConfigClassCleanup(); }
public void READMESample() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/READMESample.html"); //pass paramters as needed, supporting arrays or complex classes. var items = new[] { new { name = "First item" }, new { name = "Second item" }, new { name = "Third item" }, }; var model = new{ titlestyle = "color:#ff6347", title = "Hello from scryber", items = items }; using (var doc = Document.ParseDocument(path)) { //pass paramters as needed, supporting simple values, arrays or complex classes. doc.Params["author"] = "Scryber Engine"; doc.Params["model"] = model; using (var stream = DocStreams.GetOutputStream("READMESample.pdf")) { doc.SaveAsPDF(stream); } } using (var doc = Document.ParseDocument(path)) { //pass paramters as needed, supporting simple values, arrays or complex classes. doc.Params["author"] = "Scryber Engine"; doc.Params["model"] = model; using (var stream = DocStreams.GetOutputStream("READMESample2.pdf")) { doc.SaveAsPDF(stream); } } }
public void BasePath() { var path = "https://raw.githubusercontent.com/richard-scryber/scryber.core/master/Scryber.Core.UnitTest/Content/HTML/Images/Toroid24.png"; var src = @"<html xmlns='http://www.w3.org/1999/xhtml' > <head> <title>Html document title</title> <base href='https://raw.githubusercontent.com/richard-scryber/scryber.core/master/Scryber.Core.UnitTest/Content/HTML/' /> <link rel='stylesheet' href='CSS/Include.css' media='print' /> </head> <body class='grey' style='margin:20px;' > <p id='myPara' >This is a paragraph of content</p> <img id='myToroid' src='./Images/Toroid24.png' style='width:100pt' /> <embed id='myDrawing' src='../HTML/Fragments/MyDrawing.svg' /> </body> </html>"; using (var sr = new System.IO.StringReader(src)) { var doc = Document.ParseDocument(sr, ParseSourceType.DynamicContent); doc.RenderOptions.AllowMissingImages = false; //Will error if the image is not found Assert.IsInstanceOfType(doc, typeof(HTMLDocument)); Assert.AreEqual("https://raw.githubusercontent.com/richard-scryber/scryber.core/master/Scryber.Core.UnitTest/Content/HTML/", doc.LoadedSource, "Loaded Source is not correct"); using (var stream = DocStreams.GetOutputStream("DynamicBasePath.pdf")) { doc.LayoutComplete += SimpleDocumentParsing_Layout; doc.SaveAsPDF(stream); } Assert.AreEqual(1, doc.Styles.Count, "Remote styles were not loaded"); Assert.IsInstanceOfType(doc.Styles[0], typeof(StyleGroup), "The remote styles is not a group"); var img = doc.FindAComponentById("myToroid") as Image; Assert.IsNotNull(img.XObject, "The image was not loaded from the remote source"); var embed = doc.FindAComponentById("myDrawing") as SVGCanvas; Assert.IsNotNull(embed); Assert.AreNotEqual(0, embed.Contents.Count, "SVG drawing was not loaded from the source"); } }
public void SVGTransform() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/SVG/SVGTransform.html"); using (var doc = Document.ParseDocument(path)) { Div div; if (doc.TryFindAComponentByID("mydiv", out div)) { div.Style.SetValue(StyleKeys.TransformRotateKey, 90); } using (var stream = DocStreams.GetOutputStream("Transform.pdf")) { doc.SaveAsPDF(stream); } } }
public void LocalAndRemoteImages() { var imagepath = "https://raw.githubusercontent.com/richard-scryber/scryber.core/master/docs/images/ScyberLogo2_alpha_small.png"; var client = new System.Net.WebClient(); var data = client.DownloadData(imagepath); var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/LocalAndRemoteImages.html"); Assert.IsTrue(System.IO.File.Exists(path)); using (var doc = Document.ParseDocument(path)) { using (var stream = DocStreams.GetOutputStream("LocalAndRemoteImages.pdf")) { doc.LayoutComplete += SimpleDocumentParsing_Layout; doc.SaveAsPDF(stream); } } }
public void Html5Tags() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/Html5AllTags.html"); using (var doc = Document.ParseDocument(path)) { var model = new { fragmentContent = "Content for the fragment" }; doc.Params["model"] = model; using (var stream = DocStreams.GetOutputStream("Html5AllTags.pdf")) { doc.LayoutComplete += SimpleDocumentParsing_Layout; doc.SaveAsPDF(stream); } } }
public void BodyWithPageNumbers() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/bodyWithPageNums.html"); var model = new { headerText = "Bound Header", footerText = "Bound Footer", content = "This is the bound content text", bodyStyle = "background-color:red; color:#FFF; padding: 20pt", bodyClass = "top" }; using (var doc = Document.ParseDocument(path)) { using (var stream = DocStreams.GetOutputStream("bodyWithPageNums.pdf")) { doc.Params["model"] = model; doc.AutoBind = true; doc.LayoutComplete += SimpleDocumentParsing_Layout; doc.SaveAsPDF(stream); } var pg = doc.Pages[0] as Section; Assert.IsNotNull(pg.Header); Assert.IsNotNull(pg.Footer); var p2ref = doc.FindAComponentById("secondParaPage") as HTMLPageNumber; var p3ref = doc.FindAComponentById("thirdParaPage") as HTMLPageNumber; var p3act = doc.FindAComponentById("thirdPageValue") as HTMLPageNumber; Assert.AreEqual("2", p2ref.OutputValue, "The P2 reference was not valid"); Assert.AreEqual("3", p3ref.OutputValue, "The P3 reference was not valid"); Assert.AreEqual("3", p3act.OutputValue, "The P3 actual was not valid"); } }
public void BodyAsASection() { var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/bodyheadfoot.html"); using (var doc = Document.ParseDocument(path)) { using (var stream = DocStreams.GetOutputStream("bodyheadfoot.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); } }