Hello,
I have a very basic statement for adding InlineUIContainers to my RadRichTextBox:
var customControl = new CustomControl((CustomObject)container.SelectedObject) { Height = 480, Width = 270 };
var uiContainer = new InlineUIContainer(customControl , new Size(480,270));
this.SelectedView.TelerikRichTextBox.InsertInline(uiContainer);
The custom control successfully displays within the RadRichTextbox, and can be size accordingly. The problem is when I export as PDF, the resulting render control to image becomes distorted and no longer acceptable for document presentation. The export code is as follows:
public byte[] ExportPDF()
{
PdfFormatProvider provider = new PdfFormatProvider();
provider.ExportSettings = new PdfExportSettings();
provider.ExportSettings.InlineUIContainersExportMode = PdfInlineUIContainersExportMode.Image;
return provider.Export(this.TelerikRichTextBox.Document);
}
Are there properties that I am unaware of that will aid in proper rendering of the control?
8 Answers, 1 is accepted
Just a little more info:
CustomControl is really an object inheriting RadCartesianChart.
The export to PDF logic of InlineUIContainers is pretty straight-forward - a snapshot of the container is made and the bitmap is added to the exported document. That said, this most likely comes down to taking the image at the proper time.
Could you confirm the document containing the UI container is in the visual tree at the time of the export? This should ensure the chart is properly measured and arranged, so taking a picture of it would work fine. Additionally, could you share the OS you are trying this with?
I will greatly appreciate if you can send over some snapshots if the result and if possible, a sample application demonstrating the problem. What I tried locally is to insert an InlineUIContainer in a RadRichTextBox with this code:
RadCartesianChart chart =
new
RadCartesianChart() { Width = 480, Height = 270 };
CategoricalAxis catAxis =
new
CategoricalAxis();
LinearAxis lineAxis =
new
LinearAxis();
chart.HorizontalAxis = catAxis;
chart.VerticalAxis = lineAxis;
BarSeries barSeries =
new
BarSeries();
barSeries.DataPoints.Add(
new
CategoricalDataPoint() { Category =
"Apples"
, Value = 20 });
barSeries.DataPoints.Add(
new
CategoricalDataPoint() { Category =
"Bananas"
, Value = 28 });
barSeries.DataPoints.Add(
new
CategoricalDataPoint() { Category =
"Oranges"
, Value = 17 });
barSeries.DataPoints.Add(
new
CategoricalDataPoint() { Category =
"Strawberries"
, Value = 30 });
chart.Series.Add(barSeries);
var uiContainer =
new
InlineUIContainer(chart,
new
Size(480, 270));
this
.radRichTextBox.InsertInline(uiContainer);
And then export it to PDF with the method you sent us. This, however, works perfectly on my end, so maybe I'm missing something important in your setup.
Regards,
Petya
Telerik
Hi,
And what about export to docx.
I have a section with FloatingUIContainer with brown Border inside. When I export it to PDF the border is there, but when I export it to docx it is not. I have also FloatingImageBlock and it is imported to both pdf and docx.
Actually what I really need is a background of the cover page (first and last section) but the section has no background.
Exporting FloatingUIContainers to docx is currently not supported, as UI containers are not natively supported by the format.
Thinking about your scenario - would setting the image as watermark work for you? Oddly, but (as in MS Word) watermarks as bound to page headers, so if you change the section to has different first page header, the watermark will be visualized only for the first section page.
Regards,
Boby
Telerik
Could you please confirm that the InlineUIContainer objects have their size set? These objects are not resizable by design and you should apply their desired size while creating them to ensure that they are properly rendered and exported.
If this is not the case, you can try the PdfFormatProvider's MeasuringPanel property. If you are exporting from RadRichTextBox, MeasuringPanel is automatically set from the RadRichTextBox prior to the export to a Canvas (this is configurable in RadRichTextBox template, with a part named "MeasuringPanel"), which is always kept in the visual tree.
If you are exporting through the format provider itself, (that is invoking PdfFormatProvider.Export method directly, you can set an ordinary Canvas to the PdfFormatProvider.MeasuringPanel property, while ensuring that this canvas is in the visual tree during the export (it could even be hidden behind some other UI elements).
Hope this is helpful.
Regards,
Tanya
Telerik by Progress
Please, excuse me if I was not clear enough.
To export a document, you can use both - the UI of RadRichTextBox, by clicking the Save button, which triggers the SaveCommand, and using the format providers in code-behind. In the biggest part of cases, both actions have the same behavior, however, they slightly differ in specific scenarios. As described in the previous reply, when you use the Save button, the MeasuringPanel is automatically set to a Canvas prior to exporting.
Hope this makes things clear.
Regards,
Tanya
Telerik by Progress