Hi Team,
I am trying to add text stamp in mixed size of pdf and text font size must be change as per page size like if page is A4 then font size must be 11, A3 must be 19, A2 must be 25, A1 must be 35 and A0 must be 57. In my code before stamping i am checking page size and changing font size but after stamp when I check the PDF then i found font size is same for all pages.
Code Snip
using Aspose.Pdf;
using Aspose.Pdf.Facades;
using System;
namespace PDF_Watermarker
{
class FooterStamp
{
float PDFWidth = 0.0F; float PDFHeight = 0.0F;
string Result = string.Empty; int PdfPageCount = 1;
public void AddFooterwithBCOandDate(string PDFCurrentFile, string WatermarkText)
{
Document pdfDocument = new Document(PDFCurrentFile); //Open PDF
PdfFileInfo info = new PdfFileInfo(PDFCurrentFile);//to Get PDF INFO
if (!string.IsNullOrEmpty(info.Creator) && info.Creator.ToLower().Contains(“adobe livecycle designer 11.0”))
{
Result = "Error - This PDF Created By Adobe LiveCycle Designer 11.0 \nFile at " + PDFCurrentFile;
}
else
{
TextStamp textFooterStamp = new TextStamp(WatermarkText + " Received by Auckland Council " + DateTime.Now.ToString(“dd/MM/yyyy”));
// set properties of the stamp
textFooterStamp.BottomMargin = 7;
textFooterStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center;
textFooterStamp.VerticalAlignment = Aspose.Pdf.VerticalAlignment.Bottom;
// set text properties
textFooterStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont(“Arial”); textFooterStamp.TextState.ForegroundColor = Color.Blue;
textFooterStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold | Aspose.Pdf.Text.FontStyles.Italic;
for (int i = 1; i <= pdfDocument.Pages.Count; i++)
{
PDFWidth = info.GetPageWidth(PdfPageCount);//Get PDF Size
PDFHeight = info.GetPageHeight(PdfPageCount);//Get PDF Size
//Check Page Type and Incresase Font size
if (PDFWidth > 550 && PDFWidth < 900) //A4 Page
{
textFooterStamp.TextState.FontSize = 11;
}
else if (PDFWidth > 900 && PDFWidth < 1350) //A3 Page
{
textFooterStamp.TextState.FontSize = 19;
}
else if (PDFWidth > 1350 && PDFWidth < 1950) //A2 Page
{
textFooterStamp.TextState.FontSize = 25;
}
else if (PDFWidth > 1950 && PDFWidth < 3000) //A1 Page
{
textFooterStamp.TextState.FontSize = 35;
}
else if (PDFWidth > 3000) //A0 Page
{
textFooterStamp.TextState.FontSize = 57;
}
pdfDocument.Pages[PdfPageCount].AddStamp(textFooterStamp); // Add stamp in Footer
PdfPageCount = PdfPageCount + 1; //Increase PDF Page Number for Background watermark
}
pdfDocument.Save(PDFCurrentFile); // Save the Pdf file
Result = "Header stamp added successfully\nFile Save at " + PDFCurrentFile;
}
}
}
}
Request to please help to resolve this issue .