Skip to content

Latest commit

 

History

History
123 lines (93 loc) · 3.72 KB

create-custom-image-bullets.md

File metadata and controls

123 lines (93 loc) · 3.72 KB
title description type page_title slug position tags res_type
Create Custom Image Bullets
Learn how to create a list that has custom image bullets and use it in a PDF document.
how-to
Create Custom Image Bullets
create-custom-image-bullets
0
bullets, image, listlevel, bulletnumbering, bulletnumberingformat
kb
Product Version Product Author
2020.1.316 RadPdfProcessing Martin Velikov

Description

How to create a custom ListLevel with custom bullets containing images.

Solution

This functionality could be achieved by creating a custom class implementing IBulletNumberingFormat and passing it to BulletNumberingFormat property of the ListLevel class.

[C#]

{{region kb-create-custom-image-bullets1}}

RadFixedDocument document = new RadFixedDocument();

Table table = new Table();
TableRow firstRow = table.Rows.AddTableRow();
TableCell tableCell = firstRow.Cells.AddTableCell();

List list = this.GetCustomBullet();

Block block1 = tableCell.Blocks.AddBlock();
block1.SetBullet(list, 0);
block1.InsertText("Sample block text 1");

Block block2 = tableCell.Blocks.AddBlock();
block2.SetBullet(list, 0);
block2.InsertText("Sample block text 2");

Block block3 = tableCell.Blocks.AddBlock();
block3.SetBullet(list, 0);
block3.InsertText("Sample block text 3");

RadFixedDocumentEditor editor = new RadFixedDocumentEditor(document);
editor.InsertTable(table);

{{endregion}}

[C#] Create custom image numbering bullet

{{region kb-create-custom-image-bullets2}}

private List GetCustomBullet()
{
	List list = new List();

	for (int i = 0; i < 3; i++)
	{
		ListLevel level = list.Levels.AddListLevel();
		level.ParagraphProperties.FirstLineIndent = -72;
		level.ParagraphProperties.LeftIndent = 0;
		int currentLevelIndex = i;

		level.BulletNumberingFormat = new CustomBullet((indexer) =>
		{
			Image image = new Image();

			for (int levelIndex = 0; levelIndex <= currentLevelIndex; levelIndex++)
			{
				image = new Image() { Width = 25, Height = 25 };
				using (Stream stream = new FileStream($"Images/Image{indexer.GetCurrentIndex(levelIndex)}.png", FileMode.Open))
				{
					image.ImageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(stream);
				}
			}

			return image;
		});
	}

	return list;
}

{{endregion}}

[C#] Creating a custom class implementing IBulletNumberingFormat

{{region kb-create-custom-image-bullets2}}

internal class CustomBullet : IBulletNumberingFormat
{
    private readonly Func<IListLevelsIndexer, Image> getBullet;

    public CustomBullet(Func<IListLevelsIndexer, Image> getBullet)
    {
        this.getBullet = getBullet;
    }

    public PositionContentElement GetBulletNumberingElement(IListLevelsIndexer listLevelsIndexer)
    {
        Image positionContentElement = this.getBullet(listLevelsIndexer);
        return positionContentElement;
    }
}

{{endregion}}