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

9 posts, 0 answers
  1. Robert
    Robert avatar
    2 posts
    Member since:
    Dec 2014

    Posted 21 Jul 2015 Link to this post

    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?  

  2. Robert
    Robert avatar
    2 posts
    Member since:
    Dec 2014

    Posted 21 Jul 2015 in reply to Robert Link to this post

    Just a little more info:

     CustomControl is really an object inheriting RadCartesianChart.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Petya
    Admin
    Petya avatar
    975 posts

    Posted 24 Jul 2015 Link to this post

    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
  5. Daniel
    Daniel avatar
    5 posts
    Member since:
    Apr 2015

    Posted 21 Jan in reply to Petya Link to this post

    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.

  6. Boby
    Admin
    Boby avatar
    595 posts

    Posted 26 Jan Link to this post

    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
  7. Timothy
    Timothy avatar
    3 posts
    Member since:
    Aug 2015

    Posted 02 Nov in reply to Petya Link to this post

    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?
  8. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 04 Nov Link to this post

    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!
  9. Timothy
    Timothy avatar
    3 posts
    Member since:
    Aug 2015

    Posted 04 Nov in reply to Tanya Link to this post

    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.
  10. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 09 Nov Link to this post

    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!
Back to Top
UI for WPF is Visual Studio 2017 Ready