<w:sdt>
<w:sdtPr>
<w:text w:multiLine="1"/>
</w:sdtPr>
<w:sdtContent>
<w:r>
<w:t>Line 1</w:t>
</w:r>
<w:r>
<w:br/>
</w:r>
<w:r>
<w:t>Line 2</w:t>
</w:r>
</w:sdtContent>
</w:sdt>
InvalidCastException is thrown when importing a document with a structure element with an indirect reference to an integer value.
InvalidCastException: 'Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.MarkedContents.StructElementObject'.'
Registering the font used to be enough for resolving the font's characters in .NET Standard
byte[] fontData = File.ReadAllBytes(".\\files\\cour.ttf");
FontFamily courierNewFont = new FontFamily("Courier New");
FontsRepository.RegisterFont(courierNewFont, FontStyles.Normal, FontWeights.Normal, fontData);
However, as of version 2024.2.426 registering the font doesn't produce the correct result anymore and the text got missing in the PDF fields. When the document is opened in Adobe, the following message appears:
The FontsProvider works in both versions (before and after 2024.2.426). It is also required to iterate all widgets and apply the font explicitly to the widget.TextProperties.Font property.
Import/export strips w:colFirst and w:colLast from table's <w:permStart> elements.
Expected:
Actual:
PDF content:
Exported text content:
When you register a font in an ASP.Core project and in a static constructor, the generated PDF document will have this font only the first time you load the web page. Refreshing the page will generate the PDF document but the fonts will be lost.
Note: This worked in the previous version 2025.2.701.
Error message:
Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfInt' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.MarkedContents.StructAttributeObject'.
The TextProperties.FontSize property specifies the font size for text fragments. The property is of type double. The measurement unit used for font size in RadPdfProcessing is Device Independent Pixels (DIPs). You can convert it to points or other units using the Unit class.
However, when using the TextProperties with widgets the font conversion is not correct. Let's consider the case that we build a PDF document with a TextBoxField occupying a specific rectangle. According to the set text value, we should calculate the appropriate font size so the whole content can fit in the widget's rectangle.
/// <summary>
/// Creates a TextBoxField with calculated font size for the given rectangle
/// </summary>
private static TextBoxField CreateTextBoxWithCalculatedFont(string name, string text, Rect rect, double fontSize, FontBase font)
{
TextBoxField field = new TextBoxField(name);
field.TextProperties.FontSize = Unit.DipToPoint(fontSize);
field.TextProperties.Font = font;
field.Value = text;
var widget = field.Widgets.AddWidget();
widget.Rect = rect;
widget.Border.Width = 0;
widget.TextProperties.FontSize = Unit.DipToPoint(fontSize);
widget.TextProperties.Font = font;
return field;
}
/// <summary>
/// Calculates the optimal font size for text to fit within a specific rectangle
/// </summary>
public static double CalculateFontSizeForRectangle(string text, Rect rect, FontBase font)
{
double fontSize = 0;
Size measuredSize = new Size(0, 0);
Size availableSize = rect.Size;
while (measuredSize.Width<availableSize.Width && measuredSize.Height< availableSize.Height)
{
fontSize++;
Block block = new Block();
block.TextProperties.FontSize = fontSize;
block.TextProperties.Font = font;
block.InsertText(text);
measuredSize = block.Measure();
}
return fontSize-1;
}
// Example: Wide textbox with calculated font size
string wideText = "This is a wide textbox that demonstrates horizontal fitting of text content.";
Rect wideRect = new Rect(200, 500, 400, 30);
double wideFontSize = CalculateFontSizeForRectangle(wideText, wideRect, font);
TextBoxField wideTextBoxField = CreateTextBoxWithCalculatedFont("WideTextBox", wideText, wideRect, wideFontSize, font);
document.AcroForm.FormFields.Add(wideTextBoxField);
var wideWidget = wideTextBoxField.Widgets.First();
page.Annotations.Add(wideWidget);
wideWidget.RecalculateContent();
RadFlowDocumentEditor.InsertDocument throws NullReferenceException when inserting a document with incorrectly paired permission range elements.
Valid (Nested):
<w:permStart w:id="1"/>
<w:permStart w:id="2"/>
... content ...
<w:permEnd w:id="2"/>
<w:permEnd w:id="1"/>
Invalid (Overlapped):
<w:permStart w:id="1"/>
<w:permStart w:id="2"/>
<w:permEnd w:id="1"/>
<w:permEnd w:id="2"/>
Workaround - Remove all Permission Ranges before inserting:
var startPermissionRanges = contentDocument.EnumerateChildrenOfType<PermissionRangeStart>().ToList();
var endPermissionRanges = contentDocument.EnumerateChildrenOfType<PermissionRangeEnd>().ToList();
foreach (PermissionRangeStart rangeStart in startPermissionRanges)
{
rangeStart.Paragraph.Inlines.Remove(rangeStart);
}
foreach (PermissionRangeEnd rangeEnd in endPermissionRanges)
{
rangeEnd.Paragraph.Inlines.Remove(rangeEnd);
}
When creating a data bar conditional formatting with middle axis, a plain data bar with left axis is created instead. Using the following code:
var dataBarValueContext = new DataBarValueContext { MaximumValue = new NumericValue(1), MinimumValue = new NumericValue(-1) }; // Create the rule and set the desired formatting var rule = new DataBarRule(dataBarValueContext) { UseGradientFill = false, Direction = DataBarDirection.Context, FillColor = ThemableColor.FromColor(Colors.Green), NegativeFillColor = ThemableColor.FromColor(Colors.Red), ShowBarsOnly = true, AxisPosition = DataBarAxisPosition.Automatic }; var conditionalFormat = new ConditionalFormatting(rule); worksheet.Cells[0, 0, 1, 0].AddConditionalFormatting(conditionalFormat); worksheet.Cells[0, 0].SetValue(0.5); worksheet.Cells[1, 0].SetValue(-0.5);
The expected value is this:
The result value is instead: