We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Watermark problems

Hey i have set watermark through the following code and then saving file to pdf
Can you tell me how to make the text transparent and also tell me why there is a grey line appearing on the slides after placing watermark…I am attaching the original and the resulted output pdf

private static IPresentation setWatermarkSlides(IPresentation pres,String WatermarkText)
{
if(!WatermarkText.equals(""))
{
// Getting the height and width of slides
int s = pres.getSlides().size();
ISlideSize h = pres.getSlideSize();
double H = h.getSize().getHeight();
double W = h.getSize().getWidth();
float Hf = (float) H;
float Wf = (float) W;

// Accesssing every slide
for (int i = 0 ; i < s ; i++)
{
ISlide sld = pres.getSlides().get_Item(i);

// Adding a shape to add watermark text on each slide
IAutoShape ashp = sld.getShapes().addAutoShape(ShapeType.RECTANGLE, 0.0f, 0.0f, Wf, Hf);
ashp.addTextFrame(WatermarkText);

// Giving watermark shape optimum look
ashp = WatermarkShapeSet(ashp, pres);

// Reorder to bring the shape at the back of all other shapes
sld.getShapes().reorder(sld.getShapes().size()-1, ashp);
}

}
return pres;
}
private static IAutoShape WatermarkShapeSet(IAutoShape ashp,IPresentation pres)
{
// Construct SlidesWatermarkValues to get the required constant values for formating a watermark
SlidesWatermarkValues SWV = new SlidesWatermarkValues();

ashp.getFillFormat().setFillType(FillType.NoFill);
ashp.setHeight(SWV.GetShapeHeight((float)pres.getSlideSize().getSize().getHeight()));
ashp.setWidth(SWV.GetShapeWidth((float)pres.getSlideSize().getSize().getWidth()));
ashp.setRotation(SWV.ShapeRotation);
IPortion port = ashp.getTextFrame().getParagraphs().get_Item(0).getPortions().get_Item(0);
port.getPortionFormat().setLatinFont(new FontData(SWV.PortionTextFont));
port.getPortionFormat().setFontBold(NullableBool.True);
port.getPortionFormat().setFontHeight(SWV.PortionFontSize);
port.getPortionFormat().getFillFormat().setFillType(FillType.Solid);
port.getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.lightGray);

return ashp;
}
public class SlidesWatermarkValues
{
Float ShapeRotation = -40f;
String PortionTextFont =“Arial”;
Float PortionFontSize =64f;
float GetShapeHeight(float h)
{
return (h) ;
}
float GetShapeWidth(float w)
{
return (w ) ;
}

}


Hi Hafsa,

I have observed the presentation file shared and like to share that the line that is appearing is in fact the line of auto shape. Please add the following line after adding the Autoshape.

ashp.getLineFormat().getFillFormat().setFillType(FillType.NoFill);

Please share, if I may help you further in this regard.

Many Thanks,

Yes , its solved,
thank you

Also tell me how to make text transparent

Hi Hafsa,

You can please try using the following sample code on your end to serve the purpose.

public static void TestTransparent()
{
Presentation presentation = new Presentation();

for (ISlide slide : presentation.getSlides())
{

IAutoShape shape = slide.getShapes().addAutoShape(ShapeType.Rectangle, 700, 100, 200, 80);
shape.getFillFormat().setFillType(FillType.NoFill);


ITextFrame textFrame = shape.addTextFrame(" ");

IPortion portion = textFrame.getParagraphs().get_Item(0).getPortions().get_Item(0);//.PortionFormat;

portion.setText( “Test Frame…water mark”);

portion.getPortionFormat().getFillFormat().setFillType (FillType.Solid);

java.awt.Color col= new java.awt.Color(255,0,0,30);
// System.Drawing.Color.FromArgb(30, System.Drawing.Color.Silver)
portion.getPortionFormat().getFillFormat().getSolidFillColor().setColor(col);
}

presentation.save(“D:\Aspose Data\Dest.pptx”, SaveFormat.Pptx);

}

Many Thanks,

Ok Thank You

The color is a bit too light…
can you tell me a bit more apparent color in greyish shade

File is attached

Hi Hafsa,

I have observed your question and like to share that I have shared the way of doing thing and selecting the choice of color is upto you and requirements of your application. Actually, the following code line create the color in the shared sample example.

java.awt.Color col= new java.awt.Color(0,0,0,255)

The last arguments is alpha value and you can switch it between 255 to 0. 255 is completely opaque and 0 is completely transparent. You can set the R, G, B values to 0 and set the appropriate alpha value to get the grey shade. You can take help from color picker in Ms Paint as well to get the RGB values for desired color and put them in above sample line to see what is best for you.

Many Thanks,