Aspose PDF Opacity & Rotation

Hi Guys,

I needed to be able to add a watermark to a pdf document - rotation is 40 and with 30% opacity.

I have the following code where rotation worked but couldn’t make opacity work.

TextParagraph paragraph = new TextParagraph();
            paragraph.Position = new Position(100, 100);

            //create text fragment
            TextFragment textFragment1 = new TextFragment(watermark);

            //set text properties
            textFragment1.TextState.FontSize = 120.0F;
            textFragment1.TextState.FontStyle = FontStyles.Bold;
            textFragment1.TextState.ForegroundColor = Aspose.Pdf.Color.FromArgb(220, 220, 220, 220);
            textFragment1.TextState.Font = FontRepository.FindFont("Verdana");

            //set rotation
            textFragment1.TextState.Rotation = 40;

            // create TextBuilder object
            TextBuilder textBuilder = new TextBuilder(page);
            // append the text paragraph to the PDF page
            textBuilder.AppendText(textFragment1);

If I couldn’t achieve this using TextFragment+TextBuilder approach, can you provide me please with alternative?

Thank you,
Ruby

@vitro

In order to add watermark with opacity and rotation, TextStamp is recommended. Please check following article in API documentation in order to add text stamp as watermark:

Hi Asad, I already tried TextStamp first before using the TextFragment but the option for rotation is very limited. Here is my code:

TextStamp textStamp = new TextStamp(watermark);
            // Set whether stamp is background
            textStamp.Background = false;
            // Set origin
            textStamp.XIndent = 100;
            textStamp.YIndent = 100;
            // Rotate stamp
            textStamp.Rotate = Rotation.on90;
            // Set text properties
            textStamp.TextState.Font = FontRepository.FindFont("Verdana");
            textStamp.TextState.FontSize = 120.0F;
            textStamp.TextState.FontStyle = FontStyles.Bold;
            textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Gainsboro);
            textStamp.Opacity = 0.3

Using the above code opacity works for couldn’t get the rotation to work to 40 deg or other angle.

Thanks.

Hi Asad, I did a bit of research and found the RotateAngle property which helped me in what I am trying to achieve. Thanks for your help!

@vitro

It is nice to hear that your requirements have been fulfilled. Please keep using our API and in case you face any issue, please feel free to let us know.