hey i am using the following code for watermark of pdf
/************************************************************************
*
* Function Name : setWatermarkPdf()
* Description : This function changes the Watermark of the pdf document
* according to the value of the Watermark of PrintParams Object
*
*/
static com.aspose.pdf.Document setWatermarkPdf(com.aspose.pdf.Document pdf1, String watermark)
{
if (!watermark.equals(""))
{
com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp(watermark);
// Giving the look of a watermark
textStamp = WatermarkShapeSet(textStamp);
// Adding the textStamp on all the pages of the pdf document
for (int Page_counter = 1 ; Page_counter <= pdf1.getPages().size() ; Page_counter++)
{
pdf1.getPages().get_Item(Page_counter).addStamp(textStamp);
}
}
return pdf1;
}
/
*
* Function Name : WatermarkShapeSet()
Description : It changes the watermark related shaped accordingly to give
* it the required look of a watermark
*
*************************************************************************/
private static TextStamp WatermarkShapeSet(TextStamp textStamp)
{
// PdfWatermarkValues object is required to access needed constant values for constructing watermark
PdfWatermarkValues PWV = new PdfWatermarkValues();
textStamp.setBackground(true);
textStamp.setXIndent(PWV.textStampXIndent);
textStamp.setYIndent(PWV.textStampYIndent );
textStamp.setRotate(com.aspose.pdf.Rotation.on90);
new com.aspose.pdf.FontRepository();
textStamp.getTextState().setFont(FontRepository.findFont(PWV.textStampFont));
textStamp.getTextState().setFontSize(PWV.textStampFontSize);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
textStamp.getTextState().setForegroundColor(com.aspose.pdf.Color.getGray());
return textStamp;
}
and its giving the results attached… the original pdf and after watermark pdf with watermark text as “Hello Dude” is attached.
Please can you help to make it look better like a proper watermark, transparent grey in color placed in the middle.
Thanks
hey i am using the following code for watermark of pdf
/************************************************************************
*
* Function Name : setWatermarkPdf()
* Description : This function changes the Watermark of the pdf document
* according to the value of the Watermark of PrintParams Object
*
*/
static com.aspose.pdf.Document setWatermarkPdf(com.aspose.pdf.Document pdf1, String watermark)
{
if (!watermark.equals(""))
{
com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp(watermark);
// Giving the look of a watermark
textStamp = WatermarkShapeSet(textStamp);
// Adding the textStamp on all the pages of the pdf document
for (int Page_counter = 1 ; Page_counter <= pdf1.getPages().size() ; Page_counter++)
{
pdf1.getPages().get_Item(Page_counter).addStamp(textStamp);
}
}
return pdf1;
}
/
*
* Function Name : WatermarkShapeSet()
Description : It changes the watermark related shaped accordingly to give
* it the required look of a watermark
*
*************************************************************************/
private static TextStamp WatermarkShapeSet(TextStamp textStamp)
{
// PdfWatermarkValues object is required to access needed constant values for constructing watermark
PdfWatermarkValues PWV = new PdfWatermarkValues();
textStamp.setBackground(true);
textStamp.setXIndent(PWV.textStampXIndent);
textStamp.setYIndent(PWV.textStampYIndent );
textStamp.setRotate(com.aspose.pdf.Rotation.on90);
new com.aspose.pdf.FontRepository();
textStamp.getTextState().setFont(FontRepository.findFont(PWV.textStampFont));
textStamp.getTextState().setFontSize(PWV.textStampFontSize);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
textStamp.getTextState().setForegroundColor(com.aspose.pdf.Color.getGray());
return textStamp;
}
and its giving the results attached… the original pdf and after watermark pdf with watermark text as “Hello Dude” is attached.
Please can you help to make it look bette rlike a proper watermark, transparent grey in color placed in the middle.
Thanks
hey i am using the following code for watermark of pdf
/************************************************************************
*
* Function Name : setWatermarkPdf()
* Description : This function changes the Watermark of the pdf document
* according to the value of the Watermark of PrintParams Object
*
*/
static com.aspose.pdf.Document setWatermarkPdf(com.aspose.pdf.Document pdf1, String watermark)
{
if (!watermark.equals(""))
{
com.aspose.pdf.TextStamp textStamp = new com.aspose.pdf.TextStamp(watermark);
// Giving the look of a watermark
textStamp = WatermarkShapeSet(textStamp);
// Adding the textStamp on all the pages of the pdf document
for (int Page_counter = 1 ; Page_counter <= pdf1.getPages().size() ; Page_counter++)
{
pdf1.getPages().get_Item(Page_counter).addStamp(textStamp);
}
}
return pdf1;
}
/
*
* Function Name : WatermarkShapeSet()
Description : It changes the watermark related shaped accordingly to give
* it the required look of a watermark
*
*************************************************************************/
private static TextStamp WatermarkShapeSet(TextStamp textStamp)
{
// PdfWatermarkValues object is required to access needed constant values for constructing watermark
PdfWatermarkValues PWV = new PdfWatermarkValues();
textStamp.setBackground(true);
textStamp.setXIndent(PWV.textStampXIndent);
textStamp.setYIndent(PWV.textStampYIndent );
textStamp.setRotate(com.aspose.pdf.Rotation.on90);
new com.aspose.pdf.FontRepository();
textStamp.getTextState().setFont(FontRepository.findFont(PWV.textStampFont));
textStamp.getTextState().setFontSize(PWV.textStampFontSize);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
textStamp.getTextState().setForegroundColor(com.aspose.pdf.Color.getGray());
return textStamp;
}
and its giving the results attached… the original pdf and after watermark pdf with watermark text as “Hello Dude” is attached.
Please can you help to make it look better like a proper watermark, transparent grey in color placed in the middle.
Thanks
Hi Hafsa,
The real document is test.pdf
and the After Watermark.pdf is also attached
The watermark text ="Hello Dude"
You can put any…
Means it will depend on user
Just need it in the center, rotated and transparent grey shade. Thankyou
Hi Hafsa,
private static TextStamp
WatermarkShapeSet(TextStamp textStamp)<o:p></o:p>
{
// PdfWatermarkValues object is required to access needed constant values for constructing watermark
//PdfWatermarkValues PWV = new PdfWatermarkValues();
textStamp.setBackground(true);
textStamp.setVerticalAlignment(com.aspose.pdf.VerticalAlignment.Center);
// textStamp.setXIndent(PWV.textStampXIndent);
// textStamp.setYIndent(PWV.textStampYIndent );
textStamp.setHorizontalAlignment(com.aspose.pdf.HorizontalAlignment.Center);
textStamp.setRotateAngle(45);
new com.aspose.pdf.FontRepository();
textStamp.getTextState().setFont(FontRepository.findFont("Arial"));
textStamp.getTextState().setFontSize(20);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Bold);
textStamp.getTextState().setFontStyle(com.aspose.pdf.FontStyles.Italic);
textStamp.getTextState().setForegroundColor(com.aspose.pdf.Color.getGray());
return textStamp;
}
I have tried the code and its working, but the problem is that it is appearing before the images … Is it any way that it can be at front and transparent grey in color. please suggest.
Hi Hafsa,Hafsa101:I have tried the code and its working, but the problem is that it is appearing before the images ... Is it any way that it can be at front and transparent grey in color. please suggest.