LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Rotate a Document in the C# Document Viewer Using GetImage() and SetImage()
#1
Posted
:
Friday, October 18, 2019 1:59:47 PM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 105
Was thanked: 3 time(s) in 3 post(s)
When working with the Document Viewer there are a few options to achieve document page rotation.
You can use Page and View Commands to rotate the document page(s) in the viewer, however these fields rotate the page(s) either clockwise or counter clockwise by 90 degrees:
https://www.leadtools.com/help/l...ent-viewer-commands.htmlIn this post we are going to focus on how to rotate the document page in the viewer by any degrees from 0 to 360 using the RotateCommand.
http://https://www.leadtools.co...ssing-rotatecommand.htmlTo run image pre-processing commands on documents in the Document Viewer you will need to use the GetImage() and SetImage() methods.
https://www.leadtools.com/help/l...mentpage-getimage().htmlhttps://www.leadtools.com/help/l...cumentpage-setimage.htmlThis example is using the DocumentFactory to create a new LEADDocument "virtual document". Then loading in a document into the Document Viewer using LoadFromFile() and SetDocument().
https://www.leadtools.com/help/l...actory-loadfromfile.htmlhttps://www.leadtools.com/help/l...tviewer-setdocument.htmlCode:
private void RotatePage(int angle)
{
documentViewer.BeginUpdate();
var selectedPage = virtualDocument.Pages[documentViewer.CurrentPageNumber - 1];
var rasterImage = selectedPage.GetImage();
RotateCommand command = new RotateCommand();
command.Angle = angle;
command.FillColor = new RasterColor(255, 255, 255);
command.Flags = RotateCommandFlags.Resize;
command.Run(rasterImage);
selectedPage.SetImage(rasterImage);
virtualDocument.Pages.Add(selectedPage);
documentViewer.SetDocument(virtualDocument);
documentViewer.EndUpdate();
}
Attached is a sample project containing the snippet above. After you supply the document you want to use for the viewer, it will load the document. You can then select which page you want to rotate. After you do the rotation you can then save the document out to "C:\Temp\RotatedPage.pdf" and see that not only was the page rotated in the viewer but the page is now rotated in the exported file also.
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Document
Document SDK Examples
HOW TO: Rotate a Document in the C# Document Viewer Using GetImage() and SetImage()
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.