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

RadPdfViewer Fit to page not working.

1 Answer 500 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
n/a
Top achievements
Rank 1
n/a asked on 04 Sep 2018, 02:54 PM

So, I went out and specifically bought Telerik UI for WPF because we needed a good PDF Viewer.

My structure is rather simple

WPF:

<Window
        xmlns:local="clr-namespace:Catalogo"
        xmlns:controls="clr-namespace:Controls;assembly=Controls"
        xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" x:Class="Catalogo.Catalogos"
        mc:Ignorable="d"
        Title="Catalogo" WindowStartupLocation="CenterScreen" SnapsToDevicePixels="False"
        VisualEdgeMode="Aliased"
        ResizeMode="NoResize"
        Height="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenHeightKey}}"
        Width="{DynamicResource {x:Static SystemParameters.MaximizedPrimaryScreenWidthKey}}" WindowStyle="None"
        Loaded="Window_Loaded" Background="{DynamicResource primary_dark}">
    <Window.Resources>
        <ResourceDictionary Source="/Styles;component/Merged.xaml"/>
    </Window.Resources>
    <Grid>
        <telerik:RadBook RightPageIndex="1" BorderBrush="Transparent" >
            <telerik:RadBookItem Width="960" Height="1060" >
                <Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <telerik:RadPdfViewerToolBar RadPdfViewer="{Binding ElementName=pdfViewerIzq, Mode=OneTime}"/>
                        <telerik:RadPdfViewer x:Name="pdfViewerIzq" DataContext="{Binding CommandDescriptors, ElementName=pdfViewerIzq}" Grid.Row="1"/>
                    </Grid>
 
                </Grid>
            </telerik:RadBookItem>
            <telerik:RadBookItem  Width="960" Height="1060">
 
                <Grid>
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <telerik:RadPdfViewerToolBar Name="barraDer" RadPdfViewer="{Binding ElementName=pdfViewerDer, Mode=OneTime}"/>
                        <telerik:RadPdfViewer x:Name="pdfViewerDer" DataContext="{Binding CommandDescriptors, ElementName=pdfViewerDer}" Grid.Row="1"/>
                    </Grid>
 
                </Grid>
            </telerik:RadBookItem>
        </telerik:RadBook>
    </Grid>
</Window>

 

Then I have two methods for setting the source for the left and right viewers:

public void setPageIzq(string ruta)
        {
            pdfViewerIzq.DocumentSource = new PdfDocumentSource(new System.Uri(ruta));
            pdfViewerIzq.FitToPage();
            pdfViewerIzq.Mode = Telerik.Windows.Documents.Fixed.UI.FixedDocumentViewerMode.TextSelection;
            pdfViewerIzq.CommandDescriptors.FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.IsEnabled = true;
            pdfViewerIzq.CommandDescriptors.FitToPageFixedDocumentSinglePageViewPresenterCommandDescriptor.Command.Execute(null);
            pdfViewerIzq.ScaleMode = Telerik.Windows.Documents.Fixed.UI.ScaleMode.FitToPage;
        }
 
        public void setPageDer(string ruta)
        {
            pdfViewerDer.DocumentSource = new PdfDocumentSource(new System.Uri(ruta));
            pdfViewerIzq.CommandDescriptors.FitToPageCommandDescriptor.IsEnabled = true;
            pdfViewerIzq.CommandDescriptors.FitToPageCommandDescriptor.Command.Execute(null);
        }

 

 

As you can see, I tried a bunch of different ways to set the viewer to fit to page. If I use the navbar up top, I can make it fit to page, but none of the methods I tried worked for my manual setting.

 

I had to take this approach because we need to display the document two pages at a time, any good ideas?

1 Answer, 1 is accepted

Sort by
1
Accepted
Anna
Telerik team
answered on 07 Sep 2018, 01:27 PM
Hello Andrei,

Thank you for considering our controls, more specifically RadPdfViewer.

What happens in this situation is that when the document is loaded, the ScaleMode of the viewer is reset. So we'll need something along these lines:

public void setPageIzq(string ruta)
{
    pdfViewerIzq.DocumentSource = new PdfDocumentSource(new System.Uri(ruta));
    pdfViewerIzq.DocumentChanged += PdfViewerIzq_DocumentChanged;
}
 
private void PdfViewerIzq_DocumentChanged(object sender, DocumentChangedEventArgs e)
{
    pdfViewerIzq.FitToPage();
}

Please, don't hesitate to let us know if you have any questions.

Regards,
Anna
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
n/a
Top achievements
Rank 1
Answers by
Anna
Telerik team
Share this question
or