PdfLoadedDocument documet = new PdfLoadedDocument(File.Open("../../../rotated.pdf", FileMode.Open));
//Creating header template
PdfTemplate template = new PdfTemplate(new RectangleF(0, 0, 200, 200));
template.Graphics.DrawRectangle(PdfBrushes.Red, new RectangleF(0, 0, 200, 200));
template.Graphics.DrawString("Hello world", new PdfStandardFont(PdfFontFamily.Helvetica, 20), PdfBrushes.White, 0, 0);
foreach (PdfLoadedPage lPage in documet.Pages)
{
//page size is same for all the page 595(Width) X 842(width)
PdfPageRotateAngle angle = lPage.Rotation;
PdfGraphics graphics = lPage.Graphics;
float x = 0, y = 0;
graphics.Save();
//Change the coordination of the page based on the rotation angle
if (angle == PdfPageRotateAngle.RotateAngle90)
{
graphics.TranslateTransform(lPage.Size.Height, 0);
graphics.RotateTransform(90);
}
if(angle==PdfPageRotateAngle.RotateAngle180)
{
graphics.TranslateTransform(lPage.Size.Width, lPage.Size.Height);
graphics.RotateTransform(180);
}
if(angle==PdfPageRotateAngle.RotateAngle270)
{
graphics.TranslateTransform(0,lPage.Size.Width);
graphics.RotateTransform(-90);
}
//Drawing the template
graphics.DrawPdfTemplate(template, new PointF(x,y));
graphics.Restore();
}
using (var memoryStream = File.Open("sample2.pdf", FileMode.OpenOrCreate))
{
documet.Save(memoryStream);
documet.Close(true);
} |
How do u used
PdfDocument to roate left or right I am using
doc.PageSettings.Rotate = angle; to rotate it but dont see an option for l