本文整理汇总了C#中IRenderable.GetDocumentOutline方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderable.GetDocumentOutline方法的具体用法?C# IRenderable.GetDocumentOutline怎么用?C# IRenderable.GetDocumentOutline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRenderable
的用法示例。
在下文中一共展示了IRenderable.GetDocumentOutline方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderDocument
public void RenderDocument(IRenderable renderable, Stream stream)
{
Document document = new Document();
PdfWriter.GetInstance(document, stream);
var reportItems = renderable.GetDocumentOutline();
var headerImage = reportItems.FirstOrDefault(iri => iri is HeaderImage) as HeaderImage;
Image img = null;
int pages = 1;
document.Open();
if (headerImage != null)
{
// if we can find the file
if (File.Exists(headerImage.ImagePath))
{
// try and load an image
try
{
img = Image.GetInstance(new FileStream(@headerImage.ImagePath, FileMode.Open));
}
catch
{
img = null;
}
}
// if no valid image, try to get embedded default
if (img == null)
{
// try to get an embedded default
try
{
img = Image.GetInstance(Assembly.GetExecutingAssembly().GetResourceStream(@"Demo.Report.logo-default.png"));
}
catch (Exception ex)
{
img = null;
}
}
// if we have a valid image here, try to add it
if (img != null)
{
img.ScaleToFit(document.PageSize.Width - 72f, 150f);
img.Alignment = Image.TEXTWRAP | Image.ALIGN_CENTER;
document.Add(img);
}
// otherwise, give up
}
foreach (IReportItem iri in reportItems)
{
if (iri is DataTuple)
{
document.Add((iri as DataTuple).GetElement());
continue;
}
if (iri is DataSection)
{
foreach (IElement ie in ((iri as DataSection).GetElements()))
{
document.Add(ie);
}
continue;
}
if (iri is HeaderBase)
{
document.Add((iri as HeaderBase).GetElement());
continue;
}
if (iri is TextSection)
{
document.Add((iri as TextSection).GetElement());
continue;
}
if (iri is PageBreak)
{
if (pages > 1 && img != null)
{
img.ScaleToFit((document.PageSize.Width - 72f) / 2f, 50f);
img.SetAbsolutePosition(document.PageSize.Width - img.ScaledWidth - 10f, 10f);
document.Add(img);
}
document.NewPage();
pages++;
continue;
}
if (iri is LineBreak)
{
int i = (iri as LineBreak).Repeat;
do
{
document.Add(new Chunk(Chunk.NEWLINE));
//.........这里部分代码省略.........