Rotate page

Skip Navigation LinksHome  /  Support  /  Forums  /  DynamicPDF CoreSuite for .NET (v7)  /  Re: Rotate page

DynamicPDF CoreSuite for .NET (v7) Forum

 Mar 03 2015 12:39 AM
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.
 Mar 03 2015 12:20 PM
Posted by a ceTe Software moderator
Hello,

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.
 Oct 17 2021 9:59 AM
This 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 ?
 Oct 18 2021 9:37 AM
Posted by a ceTe Software moderator
Hi,

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

All times are US Eastern Standard time. The time now is 5:41 AM.