Watermark shows up on NON-AJAX website and on AJAX web site the watermark doesn't show up! WEIRD

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;

}

Hello Darlene,

We're looking into the details of this problem and will keep you updated with the status of correction. Please spare us little time and we will get back to you, shortly.

We apologize for your inconvenience.

As an update to this post, I created a work around by adding the Text "Draft" using the Text object, so it seems that the problem is further isolated to watermarks. Here's the revised code:

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 = 8;
//ContractTextInfo.IsUnicode = true;

MarginInfo ContractMarginInfo = new MarginInfo();
ContractMarginInfo.Left = 10F;
ContractMarginInfo.Right =10F;
ContractMarginInfo.Top = 10;
ContractMarginInfo.Bottom = 10;

TextInfo PageTitleTextInfo = new TextInfo();
PageTitleTextInfo.FontName = "Arial";
PageTitleTextInfo.FontSize = 9;
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.Gif;
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);

Text DraftText = new Text("CONTRACT IS IN " + myeContractStatus.ToString().ToUpper()+" STATUS");
TextInfo DraftTextInfo = new TextInfo();
DraftTextInfo.FontName = "Arial";
DraftTextInfo.FontSize = 10;
DraftTextInfo.IsTrueTypeFontBold = true;
DraftTextInfo.Alignment = AlignmentType.Center;
Aspose.Pdf.Color myDraftTextColor = new Aspose.Pdf.Color("Red");
DraftTextInfo.Color = myDraftTextColor;
DraftText.TextInfo = DraftTextInfo;

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 = 9;
HdrTxtInfo1.IsTrueTypeFontBold = true;
HdrTxtInfo1.Alignment = Aspose.Pdf.AlignmentType.Center;
HeaderText.TextInfo = HdrTxtInfo1;

Text txtSpacer = CreateSpacer1();

myHeader.Paragraphs.Add(imgTSLogo);
myHeader.Margin = ContractMarginInfo;

myHeader.Paragraphs.Add(txtSpacer);
myHeader.Paragraphs.Add(HeaderText);
myHeader.Paragraphs.Add(txtSpacer);

//let's define the footer as well...
FooterText = CreateFooterText("");
if (myeContractStatus != ServiceContractConst.ContractStatus.Completed)
{
myFooter.Paragraphs.Add(DraftText);
}

myFooter.Paragraphs.Add(FooterText);
myFooter.Margin = ContractMarginInfo;

}
if (mySectionName.Contains("OPENING AND MIDDLE"))
{

FirstPageText = new Text(mySectionText.Trim());
FirstPageText.Margin = ContractMarginInfo;
FirstPageText.TextInfo = ContractTextInfo;

FirstPageSection.Paragraphs.Add(FirstPageText);
FirstPageSection.PageInfo.Margin = ContractMarginInfo;

}
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.Trim());//.Replace("$", "").Trim());
AddendumAText.Margin = ContractMarginInfo;
AddendumAText.TextInfo = ContractTextInfo;
AddendumASection.Paragraphs.Add(AddendumAText);
AddendumASection.PageInfo.Margin = ContractMarginInfo;
}
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);
AddendumBSection.PageInfo.Margin = ContractMarginInfo;
}
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);
AddendumCSection.PageInfo.Margin = ContractMarginInfo;
}
if (mySectionName.Contains("ADDENDUM D"))
{
AddendumDSection.IsNewPage = true;
AddendumDSection.IsPageNumberRestarted = true;

PageTitleText = new Text(mySectionName);
PageTitleText.IsHtmlTagSupported = true;
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumDSection.Paragraphs.Add(PageTitleText);

AddendumDText = new Text(mySectionText);
AddendumDText.Margin = ContractMarginInfo;
AddendumDText.TextInfo = ContractTextInfo;
AddendumDSection.Paragraphs.Add(AddendumDText);
AddendumDSection.PageInfo.Margin = ContractMarginInfo;
}
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);

if (htSections.Contains("Addendum C"))
{

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);
if (myeContractStatus != ServiceContractConst.ContractStatus.Completed)
{
myDSectionFooter.Paragraphs.Add(DraftText);
}

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);
}

PageSetup myPageSetup = new PageSetup();
myPageSetup.Margin = ContractMarginInfo;

//pdf.PageSetup = new PageSetup();

return pdf;

}

Hello Darlene,

Sorry for replying you late.

I've tested the scenario using Aspose.Pdf for .NET 4.1.2 and I'm unable to notice the problem. I've simply created a web project, used the same code that you've shared and have set the value of String mySectionName to "HEADER"; The watermark is being displayed properly. The resultant PDF is also in attachment.

Can you please share which version of Aspose.Pdf for .NET you're using. If you still face any further problems, can you please share some more details regarding your working environment. If possible, please share the complete project so that we can test the scenario and figure out the actual reasons of problem.

We apologize for your inconvenience.

The version of Aspose.Pdf I'm using is the latest one which is 4.1.2.0, which is the same as what you have using Visual Studio 2008, on the 3.5 .Net platform. The web app that the watermark doesn't work is an ASP.NET web application that is "I-Framed" within Microsoft CRM and is using the AjaxControlToolkit.dll version 3.0.30512.1 . The web app that does work is also an ASP.NET web application but is served on it's own.

As I had mentioned previously, given the time constraints, I created a work around by simply adding the text "Draft" in red instead of using the image (see above code snippet with additions highlighted in red).

Unfortunately I am not permitted to send you an entire project so I guess I will have to figure this one on my own. I will try to create a brand new project and start adding on the different dll's to see which one is the culprit...