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"))
{
pdf.IsPageNumberRestarted = true;
AddendumDSection.IsNewPage = true;
AddendumDSection.IsPageNumberRestarted = true;
PageTitleText = new Text(mySectionName);
PageTitleText.IsHtmlTagSupported = true;
PageTitleText.Margin = ContractMarginInfo;
PageTitleText.TextInfo = PageTitleTextInfo;
AddendumDSection.Paragraphs.Add(PageTitleText);
AddendumDSection.Paragraphs.Add(CreateSpacer());
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);
}
}
Int32 TotalNumPages = FirstPageSection.PageCount + AddendumASection.PageCount + AddendumBSection.PageCount + AddendumCSection.PageCount;
Int32 TotalNumPages2 = FirstPageSection.StartingPageNumber + AddendumASection.StartingPageNumber + AddendumBSection.StartingPageNumber + AddendumCSection.StartingPageNumber;
//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);
ArrayList alSectionNames = new ArrayList();
foreach (DictionaryEntry de in htSections)
{
String mySectionName = string.Empty;
mySectionName = de.Key.ToString();
alSectionNames.Add(mySectionName);
}
alSectionNames.Sort();
foreach (String SectName in alSectionNames)
{
//
if (SectName.Contains("Addendum C"))
{
AddendumCSection.OddHeader = myHeader;
AddendumCSection.EvenHeader = myHeader;
AddendumCSection.OddFooter = myFooter;
AddendumCSection.EvenFooter = myFooter;
pdf.Sections.Add(AddendumCSection);
}
if (SectName.Contains("Addendum D"))
{
pdf.IsPageNumberRestarted = true;
//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;
return pdf;
}
private Text CreateFooterText(String NumPages)
{
String FooterText = string.Empty;
if (String.IsNullOrEmpty(NumPages))
{
String PageNum = "$P";
FooterText = "CONFIDENTIAL Page: $p of $P INITIALS_____";
}
else
{
FooterText = "CONFIDENTIAL Amendment Page: $Sp of $SP INITIALS_____";//Contract Page: $P of $P,
}
Text txtfooter = new Text(FooterText);
txtfooter.TextInfo = DefineTextInfo("Arial", 8, false, AlignmentType.Center);
return txtfooter;
//$P
// Displays total number of pages in the document
//$p
// Displays the page number of current page in the document
//$Sp
// Displays page number in the current section
//$SP
// Displays page count of the current section
//$SN
// Displays section index of the section in the document
//$D
// Displays date and time
//#$NL
// Forces beginning a new line
//#$NP
// Forces beginning a new page
//#$NC
// Forces the text after the symbol to be rendered in next column
//#$TAB
// Sets tab at the start of a segment
//#$REFPAGE(paragraphID)
// Indicates the page number of a specified paragraph
//#$UNICODE(unicodeValue)
// The number in the macro will be translated into Unicode character. For example, #$UNICODE(9633) will be rendered as '?'.
}