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

how to rotate individual pages

2 Answers 302 Views
PdfViewer and PdfViewerNavigator
This is a migrated thread and some comments may be shown as answers.
Moe
Top achievements
Rank 1
Iron
Iron
Veteran
Moe asked on 19 Aug 2019, 10:00 AM

Hi admin,

 

I want to rotate individual pages. Not radpdfviewer of rotation. I found individual page logic but exactly not correct . please see attach file.

 

 

Thanks

Moe

2 Answers, 1 is accepted

Sort by
0
Vladislav
Telerik team
answered on 21 Aug 2019, 03:24 PM
Hello Moe,

RadPdfViewer is intended for visualizing the documents and does not respect changes in its content, including the rotation of the pages, after importing the document. What is allowed to be edited are only the interactive forms inside the document. To accomplish the same goal, I can suggest you using PdfProcessing for the modifications. This approach involves rotating the chosen page (or pages) and then exporting and re-importing the document in order for the viewer to show the modified version. There is a post in the forums with some sample code that you can find helpful. Please, note that the forum topic concerns the PdfViewer control from the UI for WPF suite, but it should be pretty (if not absolutely) similar.

I hope this information helps. 
 
Regards,
Vladislav
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.
Moe
Top achievements
Rank 1
Iron
Iron
Veteran
commented on 26 Aug 2019, 01:49 AM

Hi Vladislav,

I am using winform form and vb.net.

Please can you provide to me for example code with vb using winform?

 

Thanks

Moe

0
Vladislav
Telerik team
answered on 28 Aug 2019, 09:58 AM

Hi Moe,

The idea of the procedure is the following:

  1. Load the PDF file
  2. Rotate the page(s) you want like this:
  3. document.Pages(PageNumber).Rotation = Rotation.Rotate90
  4. Export the document to a temporary stream
  5. Import the document from the stream

The code for the WinForms control shouldn't be different. I have prepared a sample project fro your reference. 

Please do not hesitate to ask if any additional questions arise.

Regards,

Vladislav

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.


n/a
Top achievements
Rank 1
commented on 08 Feb 2022, 03:46 PM | edited

I try to rotate page but page is rotate but not updating ,when i click zoom in and fittowidth buton then update page and showing rotated page. if any solution for this not updating page automatcally. (using winform)

 int  pageIndex =Convert.ToInt32(PdfViewerNavigator.CurrentPageTextBox.Text);

  DocumentViewer.Document.Pages[pageIndex -1].Rotation = Telerik.Windows.Documents.Fixed.Model.Data.Rotation.Rotate90;

Vladislav
Telerik team
commented on 10 Feb 2022, 10:24 AM

Hello,

You are probably missing the reloading of the document. What you need to do is call these two lines right after the rotation:

PdfFormatProvider provider = new PdfFormatProvider();
DocumentViewer.LoadDocument(new MemoryStream(provider.Export(DocumentViewer.Document)));

Furthermore, if you want to retain the current scroll position you will need to do it like this:

currentScrollOffset = DocumentViewer.PdfViewerElement.GetScrollOffset();

PdfFormatProvider provider = new PdfFormatProvider();
DocumentViewer.LoadDocument(new MemoryStream(provider.Export(DocumentViewer.Document)));

DocumentViewer.DocumentLoaded += DocumentViewer_DocumentLoaded;

And inside the DocumentViewer_DocumentLoaded event handler you will have this:

private void DocumentViewer_DocumentLoaded(object sender, EventArgs e)
{
    DocumentViewer.PdfViewerElement.ScrollTo(currentScrollOffset.X, currentScrollOffset.Y);

    DocumentViewer.DocumentLoaded -= DocumentViewer_DocumentLoaded;
}

I hope this helps.

Tags
PdfViewer and PdfViewerNavigator
Asked by
Moe
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Vladislav
Telerik team
Share this question
or