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

FitToPage on RadPdfViewer doesnt work.

7 Answers 514 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Dustin
Top achievements
Rank 1
Dustin asked on 15 Feb 2017, 09:11 PM
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>

7 Answers, 1 is accepted

Sort by
0
Dustin
Top achievements
Rank 1
answered on 15 Feb 2017, 09:12 PM
I forgot to attach the picture
0
Accepted
Dinko | Tech Support Engineer
Telerik team
answered on 16 Feb 2017, 02:41 PM
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 you to write beautiful native mobile apps using a single shared C# codebase.
0
David
Top achievements
Rank 1
answered on 16 Nov 2017, 06:27 PM

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

0
David
Top achievements
Rank 1
answered on 20 Nov 2017, 10:44 AM

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.

 

0
Anna
Telerik team
answered on 20 Nov 2017, 02:05 PM
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.
0
Scott
Top achievements
Rank 1
answered on 01 May 2019, 07:05 PM
Was this resolved in later builds?  I'm getting the same exception when running the suggested code.
0
Tanya
Telerik team
answered on 02 May 2019, 12:00 PM
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.
Tags
PDFViewer
Asked by
Dustin
Top achievements
Rank 1
Answers by
Dustin
Top achievements
Rank 1
Dinko | Tech Support Engineer
Telerik team
David
Top achievements
Rank 1
Anna
Telerik team
Scott
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or