I am trying to create a stimulsoft report for printing a single line of text up to maybe 50 characters on a continuous feed label printer, and I can't get the width or height of a report page to vary with the length of that single line of text.
Anyone have success doing something like I am trying to do?
I have tried a number of permutations of the Report/Page/Databand/TextField object's cangrow/autosize property possiblities, as well as trying to set the page width to the text field's width with C# script code in the various object events, no luck.
You can dynamically set the height of the page, depending on the amount of data on a page.
First set the page size to Custom, then write the following script in the EndRender event of report:
foreach (StiPage page in this.RenderedPages)
{
double max = 0;
foreach (StiComponent comp in page.GetComponents())
{
if (comp.Bottom > max) max = comp.Bottom;
}
page.PageHeight = max + page.Margins.Top + page.Margins.Bottom;
}
Report sample:
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<StiSerializer version="1.02" type="Net" application="StiReport">
<Dictionary Ref="1" type="Dictionary" isKey="true">
<BusinessObjects isList="true" count="0" />
<Databases isList="true" count="0" />
<DataSources isList="true" count="2">
<Products Ref="2" type="DataTableSource" isKey="true">
<Alias>Products</Alias>
<Columns isList="true" count="7">
<value>ProductID,System.Int32</value>
<value>ProductName,System.String</value>
<value>SupplierID,System.Int32</value>
<value>CategoryID,System.Int32</value>
<value>QuantityPerUnit,System.String</value>
<value>UnitPrice,System.Decimal</value>
<value>UnitsInStock,System.Int16</value>
</Columns>
<Dictionary isRef="1" />
<Name>Products</Name>
<NameInSource>Demo.Products</NameInSource>
</Products>
<Categories Ref="3" type="DataTableSource" isKey="true">
<Alias>Categories</Alias>
<Columns isList="true" count="3">
<value>CategoryID,System.Int32</value>
<value>CategoryName,System.String</value>
<value>Description,System.String</value>
</Columns>
<Dictionary isRef="1" />
<Name>Categories</Name>
<NameInSource>Demo.Categories</NameInSource>
</Categories>
</DataSources>
<Relations isList="true" count="1">
<Categories Ref="4" type="DataRelation" isKey="true">
<Alias>Categories</Alias>
<ChildColumns isList="true" count="1">
<value>CategoryID</value>
</ChildColumns>
<ChildSource isRef="2" />
<Dictionary isRef="1" />
<Name>Categories</Name>
<NameInSource>CategoriesProducts</NameInSource>
<ParentColumns isList="true" count="1">
<value>CategoryID</value>
</ParentColumns>
<ParentSource isRef="3" />
</Categories>
</Relations>
<Report isRef="0" />
<Variables isList="true" count="0" />
</Dictionary>
<EndRenderEvent>foreach (StiPage page in this.RenderedPages)
{
double max = 0;
foreach (StiComponent comp in page.GetComponents())
{
if (comp.Bottom > max) max = comp.Bottom;
}
page.PageHeight = max + page.Margins.Top + page.Margins.Bottom;
}
</EndRenderEvent>
<EngineVersion>EngineV2</EngineVersion>
<GlobalizationStrings isList="true" count="0" />
<MetaTags isList="true" count="0" />
<Pages isList="true" count="1">
<Page1 Ref="5" type="Page" isKey="true">
<Border>None;Black;2;Solid;False;4;Black</Border>
<Brush>Transparent</Brush>
<Components isList="true" count="2">
<DataCategories Ref="6" type="DataBand" isKey="true">
<Brush>[157:218:78]</Brush>
<BusinessObjectGuid isNull="true" />
<ClientRectangle>0,0.4,19,0.8</ClientRectangle>
<Components isList="true" count="3">
<DataCategories_CategoryID Ref="7" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>0,0,1.8,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<HorAlignment>Center</HorAlignment>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_CategoryID</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.CategoryID}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_CategoryID>
<DataCategories_CategoryName Ref="8" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>1.8,0,5,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_CategoryName</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.CategoryName}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_CategoryName>
<DataCategories_Description Ref="9" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>6.8,0,12.2,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataCategories_Description</Name>
<Page isRef="5" />
<Parent isRef="6" />
<Text>{Categories.Description}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataCategories_Description>
</Components>
<Conditions isList="true" count="0" />
<DataSourceName>Categories</DataSourceName>
<Filters isList="true" count="0" />
<Name>DataCategories</Name>
<NewPageBefore>True</NewPageBefore>
<Page isRef="5" />
<Parent isRef="5" />
<Sort isList="true" count="0" />
</DataCategories>
<DataProducts Ref="10" type="DataBand" isKey="true">
<Brush>Transparent</Brush>
<BusinessObjectGuid isNull="true" />
<ClientRectangle>0,2,19,0.8</ClientRectangle>
<Components isList="true" count="2">
<DataProducts_ProductID Ref="11" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>0,0,2.8,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<HorAlignment>Center</HorAlignment>
<Margins>0,0,0,0</Margins>
<Name>DataProducts_ProductID</Name>
<Page isRef="5" />
<Parent isRef="10" />
<Text>{Products.ProductID}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataProducts_ProductID>
<DataProducts_ProductName Ref="12" type="Text" isKey="true">
<Brush>Transparent</Brush>
<CanGrow>True</CanGrow>
<ClientRectangle>2.8,0,16.2,0.8</ClientRectangle>
<Conditions isList="true" count="0" />
<Font>Arial,8</Font>
<Margins>0,0,0,0</Margins>
<Name>DataProducts_ProductName</Name>
<Page isRef="5" />
<Parent isRef="10" />
<Text>{Products.ProductName}</Text>
<TextBrush>Black</TextBrush>
<TextOptions>HotkeyPrefix=None, LineLimit=False, RightToLeft=False, Trimming=None, WordWrap=True, Angle=0, FirstTabOffset=40, DistanceBetweenTabs=20,</TextOptions>
<VertAlignment>Center</VertAlignment>
</DataProducts_ProductName>
</Components>
<Conditions isList="true" count="0" />
<DataRelationName>CategoriesProducts</DataRelationName>
<DataSourceName>Products</DataSourceName>
<Filters isList="true" count="0" />
<MasterComponent isRef="6" />
<Name>DataProducts</Name>
<Page isRef="5" />
<Parent isRef="5" />
<Sort isList="true" count="0" />
</DataProducts>
</Components>
<Conditions isList="true" count="0" />
<Guid>f54ce908f78c4855b4d9f0abc8f326b9</Guid>
<Margins>1,1,1,1</Margins>
<Name>Page1</Name>
<PageHeight>29.7</PageHeight>
<PageWidth>21</PageWidth>
<Report isRef="0" />
<Watermark Ref="13" type="Stimulsoft.Report.Components.StiWatermark" isKey="true">
<Font>Arial,100</Font>
<TextBrush>[50:0:0:0]</TextBrush>
</Watermark>
</Page1>
</Pages>
<PrinterSettings Ref="14" type="Stimulsoft.Report.Print.StiPrinterSettings" isKey="true" />
<ReferencedAssemblies isList="true" count="8">
<value>System.Dll</value>
<value>System.Drawing.Dll</value>
<value>System.Windows.Forms.Dll</value>
<value>System.Data.Dll</value>
<value>System.Xml.Dll</value>
<value>Stimulsoft.Controls.Dll</value>
<value>Stimulsoft.Base.Dll</value>
<value>Stimulsoft.Report.Dll</value>
</ReferencedAssemblies>
<ReportAlias>Report</ReportAlias>
<ReportChanged>10/17/2012 3:55:49 PM</ReportChanged>
<ReportCreated>4/19/2011 9:33:49 AM</ReportCreated>
<ReportDescription>Basic reports demonstration.</ReportDescription>
<ReportFile>D:\DropboxFolder\Dropbox\Work\_Report samples\Dynamical page height 1.mrt</ReportFile>
<ReportGuid>ee3572d318fe4031822ddce558c4622a</ReportGuid>
<ReportName>Report</ReportName>
<ReportUnit>Centimeters</ReportUnit>
<ReportVersion>2012.3.1401</ReportVersion>
<Script>using System;
using System.Drawing;
using System.Windows.Forms;
using System.Data;
using Stimulsoft.Controls;
using Stimulsoft.Base.Drawing;
using Stimulsoft.Report;
using Stimulsoft.Report.Dialogs;
using Stimulsoft.Report.Components;
namespace Reports
{
public class Report : Stimulsoft.Report.StiReport
{
public Report() {
this.InitializeComponent();
}
#region StiReport Designer generated code - do not modify
#endregion StiReport Designer generated code - do not modify
}
}
</Script>
<ScriptLanguage>CSharp</ScriptLanguage>
<Styles isList="true" count="0" />
</StiSerializer>