I'm generating certificate documents for different clients. I have different pdf documents that I use as a template and fill in the relevant info for the client.
I also add in a logo specific to the client. I currently remove a layer that contains only the logo in my template pdf and add in the new logo.
//Apply Logos
if (_CertificateLogo != "" || _ExpiryDate.HasValue)
{
foreach (string key in layers.Keys.ToList())
{
if (key.ToLower().Equals("logo") && _CertificateLogo != "")
{
PdfLayer logoLayer = (PdfLayer)layers[key];
logoLayer.On = false;
logoLayer.OnPanel = false;
logoLayer.View = false;
}
else if (key.ToLower().Equals("expiry") && !(_ExpiryDate.HasValue))
{
PdfLayer expirylayer = (PdfLayer)layers[key];
expirylayer.On = false;
expirylayer.OnPanel = false;
expirylayer.View = false;
}
}
try
{
string certLogoPath = HttpContext.Current.Server.MapPath("\\Player\\" + _CertificateLogo);
Image imgCertLogo = Image.GetInstance(File.ReadAllBytes(certLogoPath));
Rectangle pageSize = reader.GetPageSizeWithRotation(1);
PdfSize = pageSize;
imgCertLogo.SetAbsolutePosition(
(imgCertLogo.ScaledWidth / 2) + 10,
pageSize.Height - 60 - imgCertLogo.ScaledHeight
);
pdfContentByte.AddImage(imgCertLogo, true);
}
catch
{
//No branded certificate for you!
}
}
The problem is different certificate templates will have the logo positioned differently.
Is there a way I can get the absolute position of the current image on the logo layer, and use that to set the position of the new image I am adding in?