日期:2014-05-17 浏览次数:21520 次
#region 添加水印文字
private void DoWaterMatkText(String waterMarkName, PdfContentByte under)
{
bool bRet = false;
try
{
// 设置字体
// BaseFont basefont = BaseFont.CreateFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);//字体:宋体
BaseFont basefont = BaseFont.CreateFont(@"c:/windows/fonts/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
//透明度
PdfGState gstate = new PdfGState();
gstate.FillOpacity = (1f);
gstate.StrokeOpacity = (1f);
//水印文字长度
int j = waterMarkName.Length;
under.BeginText();
//字体设计
under.SetFontAndSize(basefont, 30);
under.SetGState(gstate);
//under.SetTextMatrix(
under.SaveState();
// 画一个圆
// under.ellipse(250, 450, 350, 550);
// under.setLineWidth(1f);
// under.stroke();
float mPageW = under.PdfDocument.Right + under.PdfDocument.RightMargin;
float mPageH = under.PdfDocument.Top + under.PdfDocument.TopMargin;
float rotation = 45f;
float x = mPageW / 2;
float y = mPageH / 2;
under.SetRGBColorFillF(0.8f, 0.8f, 0.8f);
if (j >= 25)
{
//总行数
int a = j / 25 + 1;
for (int k = 0; k < a; k++)
{
if (k == 0)
{
under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, waterMarkName.Substring(0, 24), x, y - 80, rotation);
}
else
{
string b = waterMarkName.Substring(j - (j - (24 * k)));
under.ShowTextAligned(PdfContentByte.ALIGN_RIGHT, b, x, y - (80 + (50 * k)), rotation);
}
}
}
else
{
under.ShowTextAligned(PdfContentByte.ALIGN_CENTER, waterMarkName, x, y - 80, rotation);
}
under.EndText();
under.RestoreState();
bRet = true;
}
catch (DocumentException de)
{
}
}
#endregion