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

Free Support Forum - aspose.com

Russian language watermark problem

Hi,
The problem occurs as it is attached to the pdf document when adding watermark in the following way. The Watermark is close to the upper right when it should be in the middle.

fileName = SetWaterMarkForPDF(this.UploadDirectory + fileName.Substring(0, fileName.LastIndexOf(’.’)) + “.pdf”);
API.Global.FileShow(fileName.Substring(0, fileName.LastIndexOf(’.’)) + “.pdf”, this.Response);

   public string SetWaterMarkForPDF(string tempFileName)
   {

        string returnFileName = "";
        string sPDFUzanti = "_.pdf";
        string fileName = tempFileName;
        string kKopya = "ПРОВЕРЕННАЯ КОПИЯ…";

        int iFontSize = 36;

        System.Drawing.Color YaziRengi = new System.Drawing.Color();
        YaziRengi = System.Drawing.Color.LightGreen;
        
        int iAci = 45;

        PdfFileInfo fileInfo = new PdfFileInfo(tempFileName.Substring(0, tempFileName.LastIndexOf('.')) + sPDFUzanti);
        if (!fileInfo.IsPdfFile)
        {
            sPDFUzanti = ".pdf";
            fileInfo = new PdfFileInfo( tempFileName.Substring(0, tempFileName.LastIndexOf('.')) + sPDFUzanti);
        }
        Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp();
        kKopya = kKopya.Replace("ı", "i").Replace("İ", "I").Replace("ş", "s").Replace("Ş", "S").Replace("ğ", "g").Replace("Ğ", "G").Replace("Ü", "U").Replace("ü", "u");
        FormattedText formatText = new FormattedText(kKopya, YaziRengi, Aspose.Pdf.Facades.FontStyle.CourierBold, EncodingType.Cp1252, false, iFontSize);
        aStamp.BindLogo(formatText);


        float vtext = formatText.TextHeight / 2, htext = formatText.TextWidth / 2;

        aStamp.IsBackground = false;

        aStamp.Opacity = 0.4f;

        aStamp.Rotation = iAci;

        string outputFileName = tempFileName.Substring(0, tempFileName.LastIndexOf('.')) + "_2.pdf";
        returnFileName = tempFileName.Substring(0, tempFileName.LastIndexOf('.')) + "_2.pdf";
        
        PdfFileStamp stamper = new PdfFileStamp(tempFileName.Substring(0, tempFileName.LastIndexOf('.')) + sPDFUzanti, outputFileName);


        float iAngel = (float)(Math.PI * iAci / 180.0);
        for (int i = 0; i < fileInfo.Document.Pages.Count; i++)
        {
            int pageNumber = i + 1;
            float fx = 0, fy = 0, cons = 30;
            if (fileInfo.IsPdfFile)
            {
                fx = fileInfo.GetPageWidth(pageNumber) / 2; fy = fileInfo.GetPageHeight(pageNumber) / 2;

                fx = (float)(fx - (System.Math.Cos(iAngel) * htext));
                fy = (float)(fy - (System.Math.Sin(iAngel) * htext));
                if (fx < 0) fx = cons;
                if (fy < 0) fy = cons;

                aStamp.SetOrigin(fx, fy);
                aStamp.Pages = new int[] { pageNumber };
                stamper.AddStamp(aStamp);
            }
        }

        stamper.Close();

        return returnFileName;
   }

watermarkError.zip (109.8 KB)

@srmbimser

Thanks for contacting support.

Please try using following DOM based code snippet using Aspose.PDF for .NET 19.1 (because it is latest version) and in case you still face any issue, please let us know. For you kind reference, an output PDF is also attached.

Aspose.Words.Document doc = new Words.Document(dataDir + "original.docx");
doc.Save(dataDir + "watermarkpdf.pdf", Words.SaveFormat.Pdf);
Document pdfDocument = new Document(dataDir + "watermarkpdf.pdf");
string str = "ПРОВЕРЕННАЯ КОПИЯ…";
str = str.Replace("ı", "i").Replace("İ", "I").Replace("ş", "s").Replace("Ş", "S").Replace("ğ", "g").Replace("Ğ", "G").Replace("Ü", "U").Replace("ü", "u");
Facades.FormattedText text = new Facades.FormattedText(str);
TextStamp textStamp = new TextStamp(text);
// set text properties
//textStamp.TextState.Font = FontRepository.FindFont("Arial");
//string strSize = "12";
//textStamp.TextState.FontSize = Convert.ToSingle(strSize);
//textStamp.TextState.FontStyle = FontStyles.Bold;
//textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGreen);
textStamp.Opacity = 0.5;
textStamp.VerticalAlignment = VerticalAlignment.Center;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.RotateAngle = 45;
            
pdfDocument.Pages[1].AddStamp(textStamp);
pdfDocument.Save(dataDir + "Watermark.pdf");

Watermark.pdf (49.6 KB)