Is it possible to rotate text and images while they are being added to the pdf dynamically?
Something like:
image.rotation = 90;
or text.roration = 180;
Thanks,
Is it possible to rotate text and images while they are being added to the pdf dynamically?
Something like:
image.rotation = 90;
or text.roration = 180;
Thanks,
Hi,
Thank you for considering Aspose.
Rotation in TextFragment class.
Thanks.
Adeel Ahmad
Support Developer
Aspose Changsha Team
Hi,
Hi Rolly,
Hi Rolly,rollyhernando:You don’t understanding my requirements. I’m sure others expecting the same too.I want the TEXT/IMAGE/STAMP to be rotated on DIAGONAL position.What you’re class is dong only vertical and horizontal. Do you know your class? Have you tried using your class?
// Instantiate Document object<o:p></o:p>
Document doc = new Document();<o:p></o:p>
// Add page to PDF document<o:p></o:p>
Page page = doc.Pages.Add();<o:p></o:p>
TextStamp stamp = new TextStamp(“Watermark String”);<o:p></o:p>
stamp.RotateAngle = 45;<o:p></o:p>
//set origin<o:p></o:p>
stamp.XIndent = 100;<o:p></o:p>
stamp.YIndent = 100;<o:p></o:p>
//set text properties<o:p></o:p>
stamp.TextState.Font = FontRepository.FindFont(“Arial”);<o:p></o:p>
stamp.TextState.FontSize = 16.0F;<o:p></o:p>
stamp.TextState.FontStyle = FontStyles.Bold;<o:p></o:p>
stamp.TextState.FontStyle = FontStyles.Italic;<o:p></o:p>
stamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Aqua);<o:p></o:p>
// Add TextStamp to page object<o:p></o:p>
page.AddStamp(stamp);<o:p></o:p>
// Set background of PDF page<o:p></o:p>
page.Background = Aspose.Pdf.Color.LightGray;<o:p></o:p>
// Save the PDF document<o:p></o:p>
doc.Save(“c:/pdftest/Diagnal_StampObject.pdf”);//
Instantiate Document object<o:p></o:p>
Document doc = new Document();
// Add page to PDF document
Page page = doc.Pages.Add();
ImageStamp stamp = new ImageStamp("c:/pdftest/SearchResults.png");
stamp.RotateAngle = 45;
//set origin
stamp.XIndent = 100;
stamp.YIndent = 100;
//set text properties
// Add ImageStamp to page object
page.AddStamp(stamp);
// Set background of PDF page
page.Background = Aspose.Pdf.Color.LightGray;
// Save the PDF document
doc.Save("c:/pdftest/Image_Diagnal_StampObject.pdf");
Yeah! thanks it’s good. My mind was on the .Rotate not .RotateAngle but I tested it.
Hi Rolly,
You can now rotate text inside PDF by setting Rotation property to TextParagraph and TextFragments objects. They expect the value of rotation angle specified in degrees and will work in document generating scenarios. Please consider using following code snippet with latest version of Aspose.PDF for .NET:
//open document
Document pdfDocument = new Document();
//get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
//create text fragment
TextFragment textFragment1 = new TextFragment("main text");
textFragment1.Position = new Position(100, 600);
//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//create rotated text fragment
TextFragment textFragment2 = new TextFragment("rotated text");
textFragment2.Position = new Position(200, 600);
//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment2.TextState.Rotation = 45;
//create rotated text fragment
TextFragment textFragment3 = new TextFragment("rotated text");
textFragment3.Position = new Position(300, 600);
//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
textFragment3.TextState.Rotation = 90;
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text fragment to the PDF page
textBuilder.AppendText(textFragment1);
textBuilder.AppendText(textFragment2);
textBuilder.AppendText(textFragment3);
//save document
pdfDocument.Save("TextFragmentTests_Rotated1.pdf");
//open document
Document pdfDocument = new Document();
//get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
TextParagraph paragraph = new TextParagraph();
paragraph.Position = new Position(200, 600);
//create text fragment
TextFragment textFragment1 = new TextFragment("rotated text");
//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment1.TextState.Rotation = 45;
//create text fragment
TextFragment textFragment2 = new TextFragment("main text");
//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//create text fragment
TextFragment textFragment3 = new TextFragment("another rotated text");
//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment3.TextState.Rotation = -45;
// append the text fragments to the paragraph
paragraph.AppendLine(textFragment1);
paragraph.AppendLine(textFragment2);
paragraph.AppendLine(textFragment3);
// create TextBuilder object
TextBuilder textBuilder = new TextBuilder(pdfPage);
// append the text paragraph to the PDF page
textBuilder.AppendParagraph(paragraph);
//save document
pdfDocument.Save("TextFragmentTests_Rotated2.pdf");
1. Document pdfDocument = new Document();
//get particular page
Page pdfPage = (Page)pdfDocument.Pages.Add();
//create text fragment
TextFragment textFragment1 = new TextFragment("main text");
//set text properties
textFragment1.TextState.FontSize = 12;
textFragment1.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//create text fragment
TextFragment textFragment2 = new TextFragment("rotated text");
//set text properties
textFragment2.TextState.FontSize = 12;
textFragment2.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment2.TextState.Rotation = 315;
//create text fragment
TextFragment textFragment3 = new TextFragment("rotated text");
//set text properties
textFragment3.TextState.FontSize = 12;
textFragment3.TextState.Font = FontRepository.FindFont("TimesNewRoman");
//set rotation
textFragment3.TextState.Rotation = 270;
pdfPage.Paragraphs.Add(textFragment1);
pdfPage.Paragraphs.Add(textFragment2);
pdfPage.Paragraphs.Add(textFragment3);
//save document
pdfDocument.Save("TextFragmentTests_Rotated3.pdf");