FitToPage on RadPdfViewer doesnt work.

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

    Posted 15 Feb 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 in reply to Dustin Link to this post

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

    Posted 16 Feb 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.
Back to Top