The following method is called by two different web sites; one is an admin tool and the other one is the User web site. Both web sites can generate the pdf with no problem but the admin tool will show the "Draft" image watermark and the other will not. On the one that doesn't display the watermark, I step into the code and see when it does go into the section "if (myeContractStatus != ServiceContractConst.ContractStatus.Completed)
{
pdf.Watermarks.Add(watermark1);
}
" but it will not display the watermark! WEIRD!
I've checked to make sure that the image does exist in the images folder. The only differences that I can identify is that the website where it doesn't display the watermark is that it's using AJAX while the other is not. Could this be the issue?
Here's the method:
public Pdf CreateServiceContract(Hashtable htSections, ServiceContractConst.ContractStatus myeContractStatus)
{
Pdf pdf = new Pdf();
if (htSections == null)
throw new Exception("Error: Tropical.Pricing20.SvcContract.Bus.PDF.AsposePdf.CreateServiceContract() found the Hashtable with the list of template sections null");
if(htSections.Count == 0)
throw new Exception("Error: Tropical.Pricing20.SvcContract.Bus.PDF.AsposePdf.CreateServiceContract() found the Hashtable with the list of template sections empty (count = 0)");
HeaderFooter myHeader = new HeaderFooter();
Text HeaderText;
HeaderFooter myFooter = new HeaderFooter();
Text FooterText;
HeaderFooter myDSectionFooter = new HeaderFooter();
Text DSectionFooterText;
HeaderFooter myDSectionFooterSignature = new HeaderFooter();
myDSectionFooterSignature.IsLastPageOnly = true;
Section FirstPageSection = new Section();
Text FirstPageText;
Section AddendumASection = new Section();
Text AddendumAText;
Section AddendumBSection = new Section();
Text AddendumBText;
Section AddendumCSection = new Section();
Text AddendumCText;
Section AddendumDSection = new Section();
Text AddendumDText;
Section AddendumDSectionSignature = new Section();
Text AddendumDTextSignature;
TextInfo ContractTextInfo = new TextInfo();
ContractTextInfo.FontName = "Arial";
ContractTextInfo.FontSize = 9;
//ContractTextInfo.IsUnicode = true;
MarginInfo ContractMarginInfo = new MarginInfo();
ContractMarginInfo.Left = 5;
ContractMarginInfo.Right = 5;
ContractMarginInfo.Top = 15;
ContractMarginInfo.Bottom = 15;
TextInfo PageTitleTextInfo = new TextInfo();
PageTitleTextInfo.FontName = "Arial";
PageTitleTextInfo.FontSize = 10;
PageTitleTextInfo.IsTrueTypeFontBold = true;
PageTitleTextInfo.Alignment = AlignmentType.Center;
Text PageTitleText;
Aspose.Pdf.Image image1 = new Aspose.Pdf.Image();
image1.ImageInfo.File = @"~/Images/DRAFTWATERMARK.gif";
image1.ImageInfo.ImageFileType = ImageFileType.Png;
image1.ImageWidth = 359;
image1.ImageHeight = 84;
// image1.ImageScale = 0.1f;
image1.Opacity = 0.1F;
image1.ZIndex = 0;
FloatingBox watermark1 = new FloatingBox(200, 100);
watermark1.BoxHorizontalPositioning = BoxHorizontalPositioningType.Page;
watermark1.BoxHorizontalAlignment = BoxHorizontalAlignmentType.Center;
watermark1.BoxVerticalPositioning = BoxVerticalPositioningType.Page;
watermark1.BoxVerticalAlignment = BoxVerticalAlignmentType.Center;
watermark1.Paragraphs.Add(image1);
foreach (DictionaryEntry de in htSections)
{
String mySectionName = de.Key.ToString().ToUpper();
String mySectionText = de.Value.ToString();
if (mySectionName.Contains("HEADER"))
{
myHeader.DistanceFromEdge = 20;
Aspose.Pdf.Image imgTSLogo = new Aspose.Pdf.Image(myHeader);//(sec);
imgTSLogo.ImageInfo.File = @"~/Images/WOS_TSlogo_Mod.jpg";
imgTSLogo.ImageInfo.ImageFileType = ImageFileType.Jpeg;
imgTSLogo.ImageWidth = 150;
imgTSLogo.ImageHeight = 57;
HeaderText = new Text(mySectionText);
TextInfo HdrTxtInfo1 = new TextInfo();
HdrTxtInfo1.FontName = "Arial";
HdrTxtInfo1.FontSize = 10;
HdrTxtInfo1.IsTrueTypeFontBold = true;
HdrTxtInfo1.Alignment = Aspose.Pdf.AlignmentType.Center;
HeaderText.TextInfo = HdrTxtInfo1;
Text txtSpacer = CreateSpacer();
myHeader.Paragraphs.Add(imgTSLogo);
myHeader.Paragraphs.Add(txtSpacer);
myHeader.Paragraphs.Add(HeaderText);
//myHeader.Paragraphs.Add(txtSpacer);
//let's define the footer as well...
FooterText = CreateFooterText("");
myFooter.Paragraphs.Add(FooterText);
}
if (mySectionName.Contains("OPENING AND MIDDLE"))
{
FirstPageText = new Text(mySectionText.Trim());
FirstPageText.Margin = ContractMarginInfo;
FirstPageText.TextInfo = ContractTextInfo;
FirstPageSection.Paragraphs.Add(FirstPageText);
}
if (mySectionName.Contains("ADDENDUM A"))
{
//String myContent = AddendumAText.Segments[0].Content;
AddendumASection.IsNewPage = true;
PageTitleText = new Text(mySectionName.Trim());
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumASection.Paragraphs.Add(PageTitleText);
AddendumAText = new Text(mySectionText.Replace("$", "").Trim());
AddendumAText.Margin = ContractMarginInfo;
AddendumAText.TextInfo = ContractTextInfo;
AddendumASection.Paragraphs.Add(AddendumAText);
}
if (mySectionName.Contains("ADDENDUM B"))
{
AddendumBSection.IsNewPage = true;
PageTitleText = new Text(mySectionName);
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumBSection.Paragraphs.Add(PageTitleText);
AddendumBText = new Text(mySectionText);
AddendumBText.Margin = ContractMarginInfo;
AddendumBText.TextInfo = ContractTextInfo;
AddendumBSection.Paragraphs.Add(AddendumBText);
}
if (mySectionName.Contains("ADDENDUM C"))
{
AddendumCSection.IsNewPage = true;
PageTitleText = new Text(mySectionName);
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumCSection.Paragraphs.Add(PageTitleText);
AddendumCText = new Text(mySectionText);
AddendumCText.Margin = ContractMarginInfo;
AddendumCText.TextInfo = ContractTextInfo;
AddendumCSection.Paragraphs.Add(AddendumCText);
}
if (mySectionName.Contains("ADDENDUM D"))
{
AddendumDSection.IsNewPage = true;
AddendumDSection.IsPageNumberRestarted = true;
PageTitleText = new Text(mySectionName);
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumDSection.Paragraphs.Add(PageTitleText);
AddendumDText = new Text(mySectionText);
AddendumDText.Margin = ContractMarginInfo;
AddendumDText.TextInfo = ContractTextInfo;
AddendumDSection.Paragraphs.Add(AddendumDText);
}
if (mySectionName.Contains("ADDENDUM D SIGNATURE"))
{
AddendumDTextSignature = new Text(mySectionText);
AddendumDTextSignature.Margin = ContractMarginInfo;
AddendumDTextSignature.TextInfo = ContractTextInfo;
//AddendumDSectionSignature.Paragraphs.Add(AddendumDTextSignature);
myDSectionFooterSignature.Paragraphs.Add(AddendumDTextSignature);
}
}
//now let's create this.....
FirstPageSection.OddHeader = myHeader;
FirstPageSection.EvenHeader = myHeader;
FirstPageSection.OddFooter = myFooter;
FirstPageSection.EvenFooter = myFooter;
pdf.Sections.Add(FirstPageSection);
AddendumASection.OddHeader = myHeader;
AddendumASection.EvenHeader = myHeader;
AddendumASection.OddFooter = myFooter;
AddendumASection.EvenFooter = myFooter;
pdf.Sections.Add(AddendumASection);
AddendumBSection.OddHeader = myHeader;
AddendumBSection.EvenHeader = myHeader;
AddendumBSection.OddFooter = myFooter;
AddendumBSection.EvenFooter = myFooter;
pdf.Sections.Add(AddendumBSection);
AddendumCSection.OddHeader = myHeader;
AddendumCSection.EvenHeader = myHeader;
AddendumCSection.OddFooter = myFooter;
AddendumCSection.EvenFooter = myFooter;
pdf.Sections.Add(AddendumCSection);
if (htSections.Contains("Addendum D"))
{
//let's define the addendum d's new footer...
String mySectionId = AddendumDSection.ID;
pdf.Sections.Add(AddendumDSection);
Int32 NumPages = pdf.Sections[mySectionId].PageCount;//AddendumDSection.PageCount;
DSectionFooterText = CreateFooterText(NumPages.ToString());
myDSectionFooter.Paragraphs.Add(DSectionFooterText);
AddendumDSection.OddHeader = myHeader;
AddendumDSection.EvenHeader = myHeader;
AddendumDSection.OddFooter = myDSectionFooter;
AddendumDSection.EvenFooter = myDSectionFooter;
AddendumDSection.AdditionalEvenFooter = myDSectionFooterSignature;
AddendumDSection.AdditionalOddFooter = myDSectionFooterSignature;
}
pdf.TextInfo = ContractTextInfo;
pdf.PageSetup.Margin = ContractMarginInfo;
if (myeContractStatus != ServiceContractConst.ContractStatus.Completed)
{
pdf.Watermarks.Add(watermark1);
}
return pdf;
}