FitToPage on RadPdfViewer doesnt work.

8 posts, 1 answers
  1. Dustin
    Dustin avatar
    2 posts
    Member since:
    Feb 2017

    Posted 15 Feb 2017 Link to this post

    The error I'm havnig is that the RadViewer will not fit the container that it sits in.  This is going off the assumption that the ScaleMode="FitToPage" fits the parents containers width and height.  Currently the pdf is not fitting to the parent window or even if I set the width and height of the RadPdfViewer itself it still seems to try to display it with no scaling applied.  Attached is how it currently looks.

    <Window x:Class="Views.Dialogs.TelerikPdfDialog"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
            WindowStartupLocation="CenterOwner"
            ShowInTaskbar="False"
            AllowsTransparency="False"
            ResizeMode="NoResize"
            WindowStyle="None"
            mc:Ignorable="d"
            Title="TelerikPdfDialog" MaxWidth="800" MaxHeight="1000">
        



            <Window.Resources>

                <ResourceDictionary>
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="../../Resources/Styles.xaml"/>
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
            </Window.Resources>


            <Border BorderBrush="Black" BorderThickness="10">
                <Grid Background="{StaticResource gsiBackgroundBrush}" >
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto"/>
                        <RowDefinition Height="*"/>
                        <RowDefinition Height="Auto"/>
                    </Grid.RowDefinitions>
                    
                    <Grid Grid.Row="0">
                        <Label HorizontalContentAlignment="Center" Margin="10" FontSize="38" Content="Hearing Test Results"/>
                    </Grid>
                <ContentControl Grid.Row="1" x:Name="contentView" Height="350" Width="700" Background="Blue">

                    <telerik:RadPdfViewer x:Name="pdfViewer"  ScaleMode="FitToPage" DocumentSource="{Binding PatientPdfPath}"/>

                </ContentControl>

                <Grid Grid.Row="2">
                    <Grid VerticalAlignment="Bottom" Margin="0 10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="2*" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <DockPanel Grid.Column="1"  >
                                <Button HorizontalAlignment="Left" Content="Print" Height="35" Width="85"/>
                                <Button Click="Click_Close"   HorizontalAlignment="Right" Content="Cancel" Height="35" Width="85" />
                            </DockPanel>

                        </Grid>
                    </Grid>

                </Grid>
            </Border>

    </Window>
  2. Dustin
    Dustin avatar
    2 posts
    Member since:
    Feb 2017

    Posted 15 Feb 2017 in reply to Dustin Link to this post

    I forgot to attach the picture
  3. Answer
    Dinko
    Admin
    Dinko avatar
    951 posts

    Posted 16 Feb 2017 Link to this post

    Hello Dustin,

    You can try using the FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor. Basically, you can subscribe to the DocumentChanged event of the RadPdfViewer. In its handler, you can execute the FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.

    private void pdfViewer_DocumentChanged(object sender, Telerik.Windows.Documents.Fixed.DocumentChangedEventArgs e)
    {
        var pdf = sender as RadPdfViewer;
        pdf.CommandDescriptors.FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.Command.Execute(null);      
    }

    Hope this information is helpful.

    Regards,
    Dinko
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  4. David
    David avatar
    4 posts
    Member since:
    Oct 2007

    Posted 16 Nov 2017 Link to this post

    Hi,

    I've followed the suggestion in Dinko's answer, however, I am getting the following error:

    "An exception of type 'System.NullReferenceException' occurred in Telerik.Windows.Controls.FixedDocumentViewers.dll but was not handled in user code

    Additional information: Object reference not set to an instance of an object."

    I'm guessing that this is some kind of timing issue because if I put a break point into DocumentChanged event and wait for a bit, it works.

    Any ideas?

    Regards

    David

  5. David
    David avatar
    4 posts
    Member since:
    Oct 2007

    Posted 20 Nov 2017 Link to this post

    Hi,

    Don't worry about this.... I figured it out.

    In my window, the Visibilty property of the RadPdfViewer is set to Collapsed until the DocumentSource is set to the PdfDocumentSource. It dawned on me that the scaling needs to know the size of the viewer and I'm guessing that this wasn't always getting set by the time the DocumentChanged event happened. Tried a few things (including the Command.CanExecuteChanged but this didn't help(?),) so finally used RadPdfViewer.SizeChanged. This worked.

     

  6. Anna
    Admin
    Anna avatar
    136 posts

    Posted 20 Nov 2017 Link to this post

    Hi David,

    I am glad you found a solution which has solved the issue for you. In the meantime we were able to identify a null reference exception in the scenario you described in your first post. We should release a fix in one of the following LIBs, so your initial implementation should also work. Of course, please, let us know if you encounter further problems.

    Regards,
    Anna
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  7. Scott
    Scott avatar
    1 posts
    Member since:
    Aug 2018

    Posted 01 May in reply to Anna Link to this post

    Was this resolved in later builds?  I'm getting the same exception when running the suggested code.
  8. Tanya
    Admin
    Tanya avatar
    856 posts

    Posted 02 May Link to this post

    Hi Scott,

    Yes, a fix is already included in the latest internal build versions and will be also available in the next official release - R2 2019, expected in mid-May. You can test it and please, don't hesitate to let us know if you experience any further issues.

    Regards,
    Tanya
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top