Rotate an Image

Hello,

Is there a way to rotate an image? Basically I need to create a pdf of a full page image but it needs to be landscape. I've see how to rotate text but that doesn't seem to work for an image. Can this be done? Thanks

Dennis

Hi,

If you would like to create a PDF in which the page orientation is landscape and add an image to it, then you don’t have to rotate the image simple setting the IsLandscape property of the section will give you the desired result. For example:

Pdf pdfFile = new Pdf();
Section section1 = new Section(pdfFile);
pdfFile.Sections.Add(section1);
section1.IsLandscape = true;
Aspose.Pdf.Image tempImage = new Aspose.Pdf.Image(section1);
section1.Paragraphs.Add(tempImage);
tempImage.ImageInfo.File = "image.jpeg";
tempImage.ImageInfo.ImageFileType = Aspose.Pdf.ImageFileType.Jpeg;
pdfFile.Save("test.pdf");

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

Hi Adeel,

Thank you for the suggestion. The only problem with it is that I have a header and a footer that then also get the landscape format. I'd like to keep my page layout the same but be able to change the direction of the image. Do you know a way that is possible? Thanks again.

Dennis

Hi,

The following code should do what you require:

Pdf pdf = new Pdf();
Section sec = pdf.Sections.Add();
System.Drawing.Image imageFile = System.Drawing.Image.FromFile("image.jpeg");
imageFile.RotateFlip(System.Drawing.RotateFlipType.Rotate90FlipNone);
Aspose.Pdf.Image img = new Aspose.Pdf.Image();
img.ImageInfo.ImageFileType = ImageFileType.Jpeg;
img.ImageInfo.SystemImage = imageFile;
sec.Paragraphs.Add(img);
pdf.Save("test.pdf");

Thanks.

Adeel Ahmad
Support Developer
Aspose Changsha Team
http://www.aspose.com/Wiki/default.aspx/Aspose.Corporate/ContactChangsha.html

Thanks again Adeel that did fix it. I don't know why I didn't think about that before.

Please use Adeel’s suggestion as a workaround. We will support image rotating in Aspose.Pdf in the future version.