Using the SystemWeaver Script Language, it's possible to include data coming from a SWExtension in Document or report generation. This article provides an example of how to do this, and which support is offered. 


Example Code

using RemObjects.Hydra; 
using System; 
using System.ComponentModel; 
using System.IO; 
using System.Xml.Linq; 
using SystemWeaver.ExtensionsAPI; 
 
namespace SWExtension.ReportExtension 
{ 
    [Plugin, NonVisualPlugin] 
    public partial class TagWriter : NonVisualPlugin, IswTagWriter 
    { 
        public TagWriter() 
        { 
            InitializeComponent(); 
        } 
 
        public TagWriter(IContainer container) 
        { 
            container.Add(this); 
 
            InitializeComponent(); 
        } 
 
        public string GetTagWriterName() 
        { 
            return "SWExtension.ReportExtension"; 
        } 
 
        public void Write(IswTagWriterWrapper tagWriterWrapper, IswObj obj) 
        { 
            // If you want to access information on an item 
            var item = obj as IswItem; 
            if (item == null) 
                return; 
 
            var tagNodeXml = tagWriterWrapper.GetTagNodeXML(); 
 
            // Get custom attributes 
            int numberOfPictures = GetIntAttribute(tagNodeXml, "numberOfPictures"); 
            int numberOfRandomRows = GetIntAttribute(tagNodeXml, "numberOfRandomRows"); 
 
            for (int i = 0; i < numberOfPictures; i++) 
            { 
 
 // Add an image        
tagWriterWrapper.AddPngImage(ImageToByteArray(System.Drawing.Image.FromFile("GoodStuff.PNG"))); 
            } 
 
            Random rnd = new Random(); 
            string[,] data; 
            data = new string[numberOfRandomRows, 3]; 
            for (int i = 0; i < numberOfRandomRows; i++) 
            { 
                data[i, 0] = (i + 1).ToString(); 
                data[i, 1] = rnd.Next(100).ToString(); 
                data[i, 2] = rnd.Next(100000).ToString(); 
            } 
 
// Add a table 
tagWriterWrapper.AddTable(new string[] { "Header 1", "Header 2", "Header 3" }, data, new int[] { 20, 30, 40 }); 
        } 
 
        private int GetIntAttribute(string tagNodeXml, string attributeName) 
        { 
            try 
            { 
                var doc = XDocument.Parse(tagNodeXml); 
                var attr = doc.Root.Attribute(attributeName); 
 
                return (attr == null || !int.TryParse(attr.Value, out int value)) 
                    ? -1 
                    : value; 
            } 
            catch 
            { 
                return -1; 
            } 
        } 
 
        public byte[] ImageToByteArray(System.Drawing.Image imageIn) 
        { 
            using (var ms = new MemoryStream()) 
            { 
                imageIn.Save(ms, imageIn.RawFormat); 
                return ms.ToArray(); 
            } 
        } 
    } 
} 

Example Report Configuration

A view Extension may define an <Extension> tag to be used for report generation. The report tag typically follows the pattern:


<Extension name="SWExtension.ExtensionName" />

<Report>
  <Section title="Introduction">
  </Section>
  <Section title="Chapter 1" no="5">
    <Section title="This is a section">
    </Section>
    <Section title="This is another section">
    </Section>
  </Section>
  <Description/>
  
  <ForEach select="/ITAP">
    <Extension name="SWExtension.ReportExtension" numberOfPictures="3" numberOfRandomRows="5"/>
  </ForEach>
</Report>

The generated report content, as defined by the specific extension, will be included into the generated report.