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)