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

RadFixedDocument rotate single page

2 Answers 74 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Andri
Top achievements
Rank 1
Andri asked on 05 Aug 2019, 12:59 PM

Hi,
The rotation property of the page object causes me problems.
I want to rotate a specific page in the RadFixedDocument, so i index the right page and rotate it 90 degree and after that i call OnPropertyChanged to update the PdfDocument property.
But when the page was rotated(in the debug mode the value has been changed) the radpdfviewer doesn't display the rotation.

Where could the error be located?
Many thanks in advance for youre suggestions.

MainWindow.xaml.cs:

01.using System;
02.using System.IO;
03.using System.Linq;
04.using System.Windows;
05.using System.Windows.Input;
06.using Telerik.Windows.Documents.Fixed;
07.using Telerik.Windows.Documents.Fixed.FormatProviders;
08.using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
09.using Telerik.Windows.Documents.Fixed.Model;
10.using Telerik.Windows.Documents.UI;
11.using Rotation = Telerik.Windows.Documents.Fixed.Model.Data.Rotation;
12. 
13.namespace TelerikWpfApp1
14.{
15.    /// <summary>
16.    /// Interaction logic for MainWindow.xaml
17.    /// </summary>
18.    public partial class MainWindow : Window
19.    {
20.        private PdfViewModel _pdfViewModel;
21.        public MainWindow()
22.        {
23.            InitializeComponent();
24.            _pdfViewModel = new PdfViewModel();
25.            DataContext = _pdfViewModel;
26.        }
27. 
28.        private void RotateSpecificPage(object sender, RoutedEventArgs e)
29.        {
30.            _pdfViewModel.RotateSpecificPage();
31.        }
32. 
33.        private void DeleteSpecificPage(object sender, RoutedEventArgs e)
34.        {
35.            _pdfViewModel.DeleteSpecificPage();
36.        }
37.    }
38.}

MainWindow.xaml:

01.<Window
02.                xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
03.                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
04.                xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
05.                xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
06.                xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
07.                xmlns:converters="clr-namespace:Telerik.Windows.Documents.Converters;assembly=Telerik.Windows.Controls.FixedDocumentViewers"
08.                xmlns:telerikWpfApp1="clr-namespace:TelerikWpfApp1"
09.                mc:Ignorable="d"
10.                x:Class="TelerikWpfApp1.MainWindow"
11.                Title="MainWindow" Height="Auto" Width="Auto">
12.    <Grid>
13.        <Grid>
14.            <Grid.RowDefinitions>
15.                <RowDefinition Height="Auto" />
16.                <RowDefinition Height="Auto" />
17.                <RowDefinition Height="*" />
18.            </Grid.RowDefinitions>
19.            <Button Grid.Row="0" Click="RotateSpecificPage">RotatePage</Button>
20.            <Button Grid.Row="1" Click="DeleteSpecificPage">DeletePage</Button>
21.            <telerik:RadPdfViewer Grid.Row="2" x:Name="PdfViewer" Document="{Binding Path=PdfDocument, UpdateSourceTrigger=PropertyChanged, Mode=OneWay}"/>
22.        </Grid>
23.    </Grid>
24.</Window>

PdfViewModel.cs:

01.using System;
02.using System.Collections.Generic;
03.using System.ComponentModel;
04.using System.IO;
05.using System.Linq;
06.using System.Runtime.CompilerServices;
07.using System.Text;
08.using System.Threading.Tasks;
09.using System.Windows;
10.using System.Windows.Input;
11.using Telerik.Windows.Documents.Fixed.FormatProviders;
12.using Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
13.using Telerik.Windows.Documents.Fixed.Model;
14.using Telerik.Windows.Documents.Fixed.Model.Data;
15.using TelerikWpfApp1.Annotations;
16. 
17.namespace TelerikWpfApp1
18.{
19.    public class PdfViewModel : INotifyPropertyChanged
20.    {
21.        private string _path = @"test.pdf";
22.        private RadFixedDocument _pdfDocument;
23.        private const int PageNumber = 0;
24. 
25.        public PdfViewModel()
26.        {
27.            PdfDocument = ReadPdf(_pathOne);
28.        }
29.        public RadFixedDocument PdfDocument
30.        {
31.            get => _pdfDocument;
32.            set
33.            {
34.                if (!Equals(value, null))
35.                {
36.                    _pdfDocument = value;
37.                    OnPropertyChanged();
38.                }
39.            }
40.        }
41. 
42.        private RadFixedDocument ReadPdf(string path)
43.        {
44.            using (var stream = File.OpenRead(path))
45.            {
46.                return new PdfFormatProvider(stream, FormatProviderSettings.ReadAllAtOnce).Import();
47.            }
48.        }
49. 
50.        public void RotateSpecificPage()
51.        {
52.            Console.WriteLine(@"Page has been rotated");
53.            if (!Equals(PdfDocument, null))
54.            {
55.                PdfDocument.Pages[PageNumber].Rotation = Rotation.Rotate90;
56.                OnPropertyChanged(nameof(PdfDocument));
57.            }
58.        }
59. 
60.        public void DeleteSpecificPage()
61.        {
62.            Console.WriteLine(@"Page has been deleted");
63.            if (!Equals(PdfDocument, null) && PdfDocument.Pages.Count > 1)
64.            {
65.                PdfDocument.Pages.RemoveAt(PageNumber);
66.                OnPropertyChanged(nameof(PdfDocument));
67.            }
68.        }
69. 
70.        public event PropertyChangedEventHandler PropertyChanged;
71. 
72.        [NotifyPropertyChangedInvocator]
73.        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
74.        {
75.            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
76.        }
77.    }
78.}

2 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 08 Aug 2019, 11:59 AM
Hi Andri,

The RadPdfViewer does not respect the page orientation property if it is changed after importing the document. The PdfViewer provides an API for rotating all the pages in the document, but not a single one, so in order to rotate a single page I could suggest you import the document using RadPdfProcessing then rotate the page and export if, after that to import the document in the viewer. I have attached a sample project using your code with some changes showing how to rotate a single page.

Here you can find more information about the RadPdfProcessing library: https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/overview

Regards,
Nikolay Demirev
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.
0
Andri
Top achievements
Rank 1
answered on 09 Aug 2019, 07:10 AM

Hi Nikolay,

Thank you for youre response.
I was able to implement the rotation.
Andri

Tags
PDFViewer
Asked by
Andri
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Andri
Top achievements
Rank 1
Share this question
or