I need to rotate a page in a pdf document , and I am able to do it first time.
MemoryStream oMStream = new MemoryStream(File.ReadAllBytes(oSourceFilePath));
PdfDocument oDocX = new PdfDocument(oMStream);
MergeDocument oMergeDoc = new MergeDocument(oDocX);
oMergeDoc.Pages[0].Rotate = 90;
oRotateFile = oMergeDoc.Draw();
oRotateFile= oMergeDoc.Draw();
File.WriteAllBytes(oFilePath, oRotateFile);
Issue is , if I am again rotate the same file to 90 degree again , nothing is happening.
Rotate page
Re: Rotate page
Support · Mar 3, 2015Hello,
You are seeing this behavior because you are just resetting the rotation to 90 when the page is already rotated by 90 degrees. If you want to rotate it by another 90 degrees, add 90 to the existing Rotate value. Below is the code sample for it.
string sFilePath = @"C:\temp\Mydocument1.pdf";
string sOutputPath = @"C:\temp\Mydocument2.pdf";
byte[] oRotateFile = null;
MemoryStream oMStream = new MemoryStream(File.ReadAllBytes(sFilePath));
PdfDocument oDocX = new PdfDocument(oMStream);
MergeDocument oMergeDoc = new MergeDocument(oDocX);
oMergeDoc.Pages[0].Rotate = oMergeDoc.Pages[0].Rotate + 90;
oRotateFile = oMergeDoc.Draw();
File.WriteAllBytes(sOutputPath, oRotateFile);
Thanks,
ceTe software Support Team.
Re: Rotate page
Forum member · Oct 17, 2021This will rote header & footer also. In my case content (body) only needs to be rotate (ABC pdf tool will do) , Is it possible in Dynamic PDF ?
Re: Rotate page
Support · Oct 18, 2021Hi,
You can rotate most page elements by setting the Angle property. Using this property, you can rotate only the content you need. Here is an example of rotating a Table2 page element:
Document document = new Document();
Page page = new Page();
document.Pages.Add(page);
//Create TableA...................
Table2 tableA = new Table2(0, 0, 200, 600);
// Add columns to the table
tableA.Columns.Add(100);
tableA.Columns.Add(100);
// Add rows to the table and add cells to the rows
Row2 row1 = tableA.Rows.Add();
Cell2 cellR1C1 = row1.Cells.Add("Item 1");
Cell2 cellR1C2 = row1.Cells.Add("Item 2");
//Rotate Table by setting Angle to it.
tableA.Angle = 90;
// Add the table to the page
page.Elements.Add(tableA);
// Save the PDF
string pdfFilePath = @"C:\Temp\MyTable.pdf";
document.Draw(pdfFilePath);
Thanks,
ceTe Software Support Team