This is a migrated thread and some comments may be shown as answers.

PdfFormatProvider using PdfInlineUIContainersExportMode.Image doesn't render the correct size

8 Answers 141 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 21 Jul 2015, 10:52 PM

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

Sort by
0
Robert
Top achievements
Rank 1
answered on 21 Jul 2015, 10:59 PM

Just a little more info:

 CustomControl is really an object inheriting RadCartesianChart.

0
Petya
Telerik team
answered on 24 Jul 2015, 11:49 AM
Hello Robert,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Daniel
Top achievements
Rank 1
answered on 21 Jan 2016, 02:15 PM

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.

0
Boby
Telerik team
answered on 26 Jan 2016, 09:48 AM
Hi Daniel,

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
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Timothy
Top achievements
Rank 1
answered on 02 Nov 2016, 08:49 PM
How is one supposed to ensure that an InlineUIContainer is in the visual tree at the time of export?  If I produce a RadDocument with a RadChartView in an InlineUIContainer, but that InlineUIContainer is off the page at the time of export, it is not loaded because of UI virtualization, correct?  How do I export to PDF reliably when the user doesn't scroll all the way through the document?
0
Tanya
Telerik team
answered on 04 Nov 2016, 02:18 PM
Hello Timothy,

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
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Timothy
Top achievements
Rank 1
answered on 04 Nov 2016, 04:03 PM
I did have the sizes set.  Creating a blank canvas behind the RadRichTextBox and assigning that canvas to the provider.MeasuringPanel works as a workaround.  I'm not sure what you mean by "exporting from RadRichTextBox" vs. "exporting through the format provider".  The only way I see in the documentation is to create the PDFFormatProvider and export, as described at http://docs.telerik.com/devtools/wpf/controls/radrichtextbox/import-export/features-import-export and http://docs.telerik.com/devtools/wpf/controls/radrichtextbox/document-elements/features-inlineuicontainer.
0
Tanya
Telerik team
answered on 09 Nov 2016, 11:38 AM
Hello Timothy,

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
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Tags
RichTextBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Robert
Top achievements
Rank 1
Petya
Telerik team
Daniel
Top achievements
Rank 1
Boby
Telerik team
Timothy
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or