using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.IO;
using System.Collections;
using HtmlAgilityPack;
using Aspose.Words;
using Aspose.Words.Tables;
using Aspose.Words.Drawing;
using PageFinder;
using Aspose.Words.Fields;
using IRIS.CoreServices.Logging;
namespace IRIS.CoreServices.Utility.Common
{
public class
CommonUtil
{
static int UnprocessedFinancialTable = 1;
static int ProcessedFinancialTable = 2;
static int NumericFinancialTable = 3;
static int NestedTable = 4;
static int NonFinancialTable = 0;
static bool isDev = false;
static string[] CurrencySymbols = ("£,€,¥,₡,₹,₩,฿,元,₪,¢,₵,₣,₲,₴,₭,₺,₦,₱,₸,₮,₧,₢,₤,₥,₫,₯,₰,₳,CHF,Rs").Split(',');
static string[] fontSizeInPoints = ("7,8,9,10,12,16,20,30").Split(',');
public static MemoryStream
ApplyCommonRulesForSpecialObjects(MemoryStream
objStream)
{
try
{
}
catch
(Exception ex)
{
}
return
objStream;
}
#region Carbon HTML specific Aspose Formation methods By
Shrikant
public static Document
CarbonHTMLspecificAsposeFormation(Document
objDocument, IRIS.CoreServices.Common.UserContext
user, IRIS.CoreServices.Logging.Logger
logger)
{
try
{
objDocument =
ManageHeaderFooters(objDocument, user, logger);
objDocument =
ManageFonts(objDocument, user, logger);
objDocument =
ManageImages(objDocument, "Main",
user, logger);
objDocument =
ExcelTableMarking(objDocument, user, logger);
objDocument =
ManageFixedTableWidths(objDocument, user, logger);
//CreateFormattingOfComments(ref
objDocument, ref commentData);
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"CarbonHTMLspecificAsposeFormation", "0", ex.Message,
"");//
if
(logger != null)
logger.Log(ex.Message.ToString(), LogLevel.DEBUG,
Guid.NewGuid());
}
return
objDocument;
}
#region CarbonHTMLspecificAsposeFormation : Used methods
public static Document
ExcelTableMarking(Document doc,
IRIS.CoreServices.Common.UserContext user,
IRIS.CoreServices.Logging.Logger logger)
{
string
extension = string.Empty;
string
FileName = string.Empty;
string
FilePath = string.Empty;
DocumentBuilder
builder = new DocumentBuilder(doc);
NodeCollection
Shapes = doc.GetChildNodes(NodeType.Shape, true);
// Look
through all comments and gather information about them.
int
ExcelNo = 1;
try
{
foreach
(Aspose.Words.Drawing.Shape shape in Shapes)
{
if
(shape.OleFormat != null)
{
try
{
extension =
shape.OleFormat.SuggestedExtension.ToString();
if ((extension.Contains(".xls")
|| extension.Contains(".xlsx"))
&& shape.OleFormat.IsLink == false)
{
shape.AlternativeText = "$EXCEL$"
+ ExcelNo;
ExcelNo += 1;
}
}
catch
{
}
}
}
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"ExcelTableMarking", "0", ex.Message, "");//
if
(logger != null)
logger.Log(ex.Message.ToString(),
LogLevel.DEBUG, Guid.NewGuid());
}
return
doc;
}
static Document ManageHeaderFooters(Document doc, IRIS.CoreServices.Common.UserContext user, IRIS.CoreServices.Logging.Logger logger)
{
int
ImageNo = 1;
doc = SetSectionPageHeaders(doc);
//
SetSectionPageFooters(ref doc);
doc =
IdentifyAndTagSectionHeaderFooterImages(doc, ref
ImageNo);
if
(ImageNo > 1)
doc =
CreateBlankImagePlaceHolderOnAllPages(doc);
return
doc;
}
static Document IdentifyAndTagSectionHeaderFooterImages(Document doc, ref int ImageNo)
{
HeaderFooter
Primary = null;
NodeCollection
Nodes = null;
try
{
for
(int secIndex = 0; secIndex <
doc.Sections.Count; secIndex++)
{
#region "Identify Header Image &
Shapes By Shrikant"
Primary = doc.Sections[secIndex].HeadersFooters[HeaderFooterType.HeaderPrimary];
if
(Primary != null)
{
Nodes =
Primary.GetChildNodes(NodeType.Shape, true);
foreach (Shape obj in Nodes)
{
obj.AlternativeText
= "#HeaderShapeImage#" + (secIndex
+ 1).ToString() + "#" +
ImageNo.ToString() + "#";
ImageNo += 1;
}
Nodes =
Primary.GetChildNodes(NodeType.DrawingML, true);
foreach (DrawingML obj in Nodes)
{
obj.AlternativeText
= "#HeaderDrawingImage#" +
(secIndex + 1).ToString() + "#" +
ImageNo.ToString() + "#";
ImageNo += 1;
}
#region Remove Page Headers &
DateTime also Do alignment
Nodes =
Primary.GetChildNodes(NodeType.Paragraph, true);
foreach
(Paragraph obj in
Nodes)
{
obj.ParagraphFormat.Alignment = ParagraphAlignment.Center;
if (obj.ChildNodes.Count > 1)
{
bool
startFound = false;
bool endFound = false;
for (int child = 0;
child < obj.ChildNodes.Count; child++)
{
if (obj.ChildNodes[child].NodeType == NodeType.FieldStart)
startFound = true;
if (obj.ChildNodes[child].NodeType == NodeType.FieldStart)
endFound = true;
if (obj.ChildNodes[child].NodeType == NodeType.Run)
{
if (((Run)obj.ChildNodes[child]).Text.ToLower().Replace("page", "").Replace("mergeformat", "").Replace("\\*", "").Trim().Length
> 5)
{
startFound = false; endFound = false;
}
}
}
if (startFound && endFound)
{
obj.Remove();
}
}
}
#endregion
}
#endregion
#region "Identify Footer Image &
Shapes By Shrikant"
Primary = doc.Sections[secIndex].HeadersFooters[HeaderFooterType.FooterPrimary];
if
(Primary != null)
{
Nodes =
Primary.GetChildNodes(NodeType.Shape, true);
foreach (Shape obj in Nodes)
{
obj.AlternativeText
= "#FooterShapeImage#" + (secIndex
+ 1).ToString() + "#" +
ImageNo.ToString() + "#";
ImageNo += 1;
}
Nodes =
Primary.GetChildNodes(NodeType.DrawingML, true);
foreach (DrawingML obj in Nodes)
{
obj.AlternativeText
= "#FooterDrawingImage#" +
(secIndex + 1).ToString() + "#" +
ImageNo.ToString() + "#";
ImageNo += 1;
}
#region Remove Page Headers &
DateTime also Do alignment
Nodes =
Primary.GetChildNodes(NodeType.Paragraph, true);
foreach (Paragraph obj in Nodes)
{
obj.ParagraphFormat.Alignment = ParagraphAlignment.Center;
if (obj.ChildNodes.Count > 1)
{
bool startFound = false;
bool endFound = false;
for (int child = 0;
child < obj.ChildNodes.Count; child++)
{
if (obj.ChildNodes[child].NodeType == NodeType.FieldStart)
startFound = true;
if (obj.ChildNodes[child].NodeType == NodeType.FieldEnd)
endFound = true;
if (obj.ChildNodes[child].NodeType == NodeType.Run)
{
if (((Run)obj.ChildNodes[child]).Text.ToLower().Replace("page", "").Replace("mergeformat", "").Replace("\\*", "").Replace(" ", "").Trim().Length
> 10)
{
startFound = false; endFound = false;
}
}
}
if (startFound && endFound)
{
obj.Remove();
}
}
}
#endregion
}
#endregion
}
}
catch
{
}
return
doc;
}
static bool isContentOfFirstHeader(Document
doc, string text)
{
bool
isBlank = true;
int
trialCount = 0;
NodeCollection
Nodes = null;
try
{
Nodes =
doc.Sections[0].GetChildNodes(NodeType.Run, true);
foreach
(Run txt in
Nodes)
{
if
(txt.Text.Trim() != "")
isBlank = false;
if
(!isBlank)
{
if (txt.Text.Trim() == text)
return true;
trialCount++;
}
if
(trialCount > 3)
return false;
}
}
catch
{
}
return
false;
}
static bool isBlank(HeaderFooter
headerFooterHeaderFirst)
{
NodeCollection
Nodes = null;
try
{
Nodes =
headerFooterHeaderFirst.GetChildNodes(NodeType.Run,
true);
foreach
(Run txt in
Nodes)
{
if
(txt.Text.Trim() != "")
{
return false;
}
}
Nodes =
headerFooterHeaderFirst.GetChildNodes(NodeType.Shape,
true);
foreach
(Shape shape in
Nodes)
{
if
(shape != null)
{
return false;
}
}
Nodes =
headerFooterHeaderFirst.GetChildNodes(NodeType.DrawingML,
true);
foreach
(DrawingML drawing in
Nodes)
{
if
(drawing != null)
{
return false;
}
}
}
catch
{
}
return
true;
}
static Document SetSectionPageHeaders(Document doc)
{
//First
page Header & Image
try
{
for
(int secid = 0; secid < doc.Sections.Count;
secid++)
{
bool
HeaderPrimaryFound = false;
bool
AllowNewNodeAddition = true;
foreach
(HeaderFooter headerFooterHeaderFirst in doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderFirst.HeaderFooterType == HeaderFooterType.HeaderFirst)
{
foreach (HeaderFooter
headerFooterHeaderEvenPrimary in
doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderEvenPrimary.HeaderFooterType ==
HeaderFooterType.HeaderPrimary)
{
if (headerFooterHeaderFirst.ChildNodes.Count > 0)
{
bool AllowCreation = false;
bool AllowAppend = false;
//int HeaderFirstChildCount = 0;
if (headerFooterHeaderFirst.ChildNodes[0].NodeType ==
NodeType.Paragraph ||
headerFooterHeaderFirst.ChildNodes[0].NodeType == NodeType.StructuredDocumentTag)
{
if (headerFooterHeaderFirst.ChildNodes.Count ==
headerFooterHeaderEvenPrimary.ChildNodes.Count)
{
bool AllMatched = true;
for (int
i = 0; i < headerFooterHeaderEvenPrimary.ChildNodes.Count; i++)
{
if (headerFooterHeaderEvenPrimary.ChildNodes[i].NodeType
!= headerFooterHeaderFirst.ChildNodes[i].NodeType)
{
AllMatched = false; break;
}
}
if (!AllMatched)
{
AllowAppend = true; AllowCreation = true;
}
}
//if (headerFooterHeaderFirst.ChildNodes[0].NodeType ==
NodeType.Paragraph)
//{
// Paragraph
HeaderPara = (Paragraph)headerFooterHeaderFirst.ChildNodes[0];
//
HeaderFirstChildCount = HeaderPara.ChildNodes.Count;
//}
//else
//{
//
Aspose.Words.Markup.StructuredDocumentTag StructureDoc =
(Aspose.Words.Markup.StructuredDocumentTag)headerFooterHeaderFirst.ChildNodes[0];
//
HeaderFirstChildCount = StructureDoc.ChildNodes.Count;
//}
}
if (!isBlank(headerFooterHeaderFirst))
{
AllowCreation = true;
}
//if (headerFooterHeaderFirst.ChildNodes.Count >=
headerFooterHeaderEvenPrimary.ChildNodes.Count)
//{
// if (HeaderFirstChildCount > 0)
//
AllowCreation = true;
//}
if (AllowCreation)
{
if (!AllowAppend)
headerFooterHeaderEvenPrimary.RemoveAllChildren();
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if
(headerFooterHeaderFirst.ChildNodes[0] != null)
{
headerFooterHeaderEvenPrimary.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
}
}
HeaderPrimaryFound = true;
}
}
if (headerFooterHeaderFirst.FirstChild != null)
{
if (headerFooterHeaderFirst.FirstChild.NodeType == NodeType.Paragraph && !HeaderPrimaryFound
&& doc.Sections.Count > 1 && secid == 0)
{
try
{
if (doc.Sections[0].Body.FirstChild.NodeType == NodeType.Paragraph)
{
Paragraph para = (Paragraph)doc.Sections[0].Body.FirstChild;
if (para.ChildNodes.Count > 0)
{
if (para.FirstChild.NodeType == NodeType.Run)
{
Run objText = (Run)para.FirstChild;
if (objText.Text.Trim() == "Be") ////if
(!isContentOfFirstHeader(doc, objText.Text))
{
AllowNewNodeAddition = false;
}
}
}
}
}
catch
{
}
}
}
if (!HeaderPrimaryFound &&
AllowNewNodeAddition)
{
HeaderFooter NewHeader = new
HeaderFooter(doc, HeaderFooterType.HeaderPrimary);
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if (headerFooterHeaderFirst.ChildNodes[0] != null)
{
NewHeader.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
doc.Sections[secid].HeadersFooters.Add(NewHeader);
}
headerFooterHeaderFirst.RemoveAllChildren();
break;
}
}
}
#region Clear All Text Of other headers
for all sections except First
//if
(doc.Sections.Count > 1)
//{
// for (int i = 1; i < doc.Sections.Count;
i++)
// {
// foreach (HeaderFooter headerFooter in
doc.Sections[i].HeadersFooters)
// {
// if (headerFooter.HeaderFooterType
== HeaderFooterType.HeaderPrimary)
// {
// if
(headerFooter.ChildNodes.Count > 0)
// {
// NodeCollection objTexts =
headerFooter.GetChildNodes(NodeType.Run, true);
// foreach (Run objText in objTexts)
// {
// objText.Remove();
// }
// }
// }
// }
// }
//}
#endregion
}
catch
(Exception ex)
{
}
return
doc;
}
static Document SetSectionPageHeaders_old(Document doc)
{
//First
page Header & Image
try
{
for
(int secid = 0; secid < doc.Sections.Count;
secid++)
{
bool
HeaderPrimaryFound = false;
bool
AllowNewNodeAddition = true;
foreach
(HeaderFooter headerFooterHeaderFirst in doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderFirst.HeaderFooterType == HeaderFooterType.HeaderFirst)
{
foreach (HeaderFooter
headerFooterHeaderEvenPrimary in
doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderEvenPrimary.HeaderFooterType ==
HeaderFooterType.HeaderPrimary)
{
if (headerFooterHeaderFirst.ChildNodes.Count > 0)
{
bool
AllowCreation = false;
bool AllowAppend = false;
int HeaderFirstChildCount = 0;
if (headerFooterHeaderFirst.ChildNodes[0].NodeType ==
NodeType.Paragraph ||
headerFooterHeaderFirst.ChildNodes[0].NodeType == NodeType.StructuredDocumentTag)
{
if (headerFooterHeaderFirst.ChildNodes.Count ==
headerFooterHeaderEvenPrimary.ChildNodes.Count)
{
bool AllMatched = true;
for (int
i = 0; i < headerFooterHeaderEvenPrimary.ChildNodes.Count; i++)
{
if
(headerFooterHeaderEvenPrimary.ChildNodes[i].NodeType !=
headerFooterHeaderFirst.ChildNodes[i].NodeType)
{
AllMatched = false; break;
}
}
if (!AllMatched)
{
AllowAppend = true; AllowCreation = true;
}
}
if (headerFooterHeaderFirst.ChildNodes[0].NodeType ==
NodeType.Paragraph)
{
Paragraph HeaderPara = (Paragraph)headerFooterHeaderFirst.ChildNodes[0];
HeaderFirstChildCount = HeaderPara.ChildNodes.Count;
}
else
{
Aspose.Words.Markup.StructuredDocumentTag
StructureDoc = (Aspose.Words.Markup.StructuredDocumentTag)headerFooterHeaderFirst.ChildNodes[0];
HeaderFirstChildCount = StructureDoc.ChildNodes.Count;
}
}
if
(headerFooterHeaderFirst.ChildNodes.Count >=
headerFooterHeaderEvenPrimary.ChildNodes.Count)
{
if (HeaderFirstChildCount > 0)
AllowCreation = true;
}
if (AllowCreation)
{
if (!AllowAppend)
headerFooterHeaderEvenPrimary.RemoveAllChildren();
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if
(headerFooterHeaderFirst.ChildNodes[0] != null)
{
headerFooterHeaderEvenPrimary.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
}
}
HeaderPrimaryFound = true;
}
}
if (headerFooterHeaderFirst.FirstChild != null)
{
if (headerFooterHeaderFirst.FirstChild.NodeType == NodeType.Paragraph && !HeaderPrimaryFound
&& doc.Sections.Count > 1 && secid == 0)
{
try
{
if (doc.Sections[0].Body.FirstChild.NodeType == NodeType.Paragraph)
{
Paragraph para = (Paragraph)doc.Sections[0].Body.FirstChild;
if (para.ChildNodes.Count > 0)
{
if (para.FirstChild.NodeType == NodeType.Run)
{
Run
objText = (Run)para.FirstChild;
if (objText.Text.Trim() == "Be") ////if
(!isContentOfFirstHeader(doc, objText.Text))
{
AllowNewNodeAddition = false;
}
}
}
}
}
catch
{
}
}
}
if (!HeaderPrimaryFound &&
AllowNewNodeAddition)
{
HeaderFooter NewHeader = new
HeaderFooter(doc, HeaderFooterType.HeaderPrimary);
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if (headerFooterHeaderFirst.ChildNodes[0] != null)
{
NewHeader.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
doc.Sections[secid].HeadersFooters.Add(NewHeader);
}
headerFooterHeaderFirst.RemoveAllChildren();
break;
}
}
}
#region Clear All Text Of other headers
for all sections except First
//if
(doc.Sections.Count > 1)
//{
// for (int i = 1; i < doc.Sections.Count;
i++)
// {
// foreach (HeaderFooter headerFooter in
doc.Sections[i].HeadersFooters)
// {
// if (headerFooter.HeaderFooterType
== HeaderFooterType.HeaderPrimary)
// {
// if (headerFooter.ChildNodes.Count
> 0)
// {
// NodeCollection objTexts =
headerFooter.GetChildNodes(NodeType.Run, true);
// foreach (Run objText in
objTexts)
// {
// objText.Remove();
// }
// }
// }
// }
// }
//}
#endregion
}
catch
(Exception ex)
{
}
return
doc;
}
static Document SetSectionPageFooters(Document doc)
{
//First
page Header & Image
//Claer
All other pages text (for all section)
try
{
for
(int secid = 0; secid < doc.Sections.Count;
secid++)
{
bool
HeaderPrimaryFound = false;
foreach
(HeaderFooter headerFooterHeaderFirst in doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderFirst.HeaderFooterType == HeaderFooterType.FooterFirst)
{
foreach (HeaderFooter
headerFooterHeaderEvenPrimary in
doc.Sections[secid].HeadersFooters)
{
if (headerFooterHeaderEvenPrimary.HeaderFooterType ==
HeaderFooterType.FooterPrimary)
{
if (headerFooterHeaderFirst.ChildNodes.Count > 0)
{
bool AllowCreation = false;
bool AllowAppend = false;
int HeaderFirstChildCount = 0;
if (headerFooterHeaderFirst.ChildNodes[0].NodeType ==
NodeType.Paragraph)
{
Paragraph HeaderPara = (Paragraph)headerFooterHeaderFirst.ChildNodes[0];
HeaderFirstChildCount = HeaderPara.ChildNodes.Count;
}
else if
(headerFooterHeaderFirst.ChildNodes[0].NodeType == NodeType.StructuredDocumentTag)
{
Aspose.Words.Markup.StructuredDocumentTag
StructureDoc = (Aspose.Words.Markup.StructuredDocumentTag)headerFooterHeaderFirst.ChildNodes[0];
HeaderFirstChildCount = StructureDoc.ChildNodes.Count;
AllowAppend = true;
AllowCreation = true;
}
if (headerFooterHeaderFirst.ChildNodes.Count >=
headerFooterHeaderEvenPrimary.ChildNodes.Count)
{
if (HeaderFirstChildCount > 0)
AllowCreation = true;
}
if (AllowCreation)
{
if (!AllowAppend)
headerFooterHeaderEvenPrimary.RemoveAllChildren();
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if
(headerFooterHeaderFirst.ChildNodes[0] != null)
{
headerFooterHeaderEvenPrimary.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
}
}
HeaderPrimaryFound = true;
}
}
if (!HeaderPrimaryFound)
{
HeaderFooter NewHeader = new
HeaderFooter(doc, HeaderFooterType.FooterPrimary);
while (headerFooterHeaderFirst.ChildNodes.Count >
0)
{
if (headerFooterHeaderFirst.ChildNodes[0] != null)
{
NewHeader.AppendChild(headerFooterHeaderFirst.ChildNodes[0]);
}
}
doc.Sections[secid].HeadersFooters.Add(NewHeader);
}
headerFooterHeaderFirst.RemoveAllChildren();
break;
}
}
}
}
catch
(Exception ex)
{
}
return
doc;
}
static Document CreateBlankImagePlaceHolderOnAllPages(Document doc)
{
try
{
PageNumberFinder
finder = new PageNumberFinder(doc);
Section
LastSection = null;
Paragraph
LastPara = null;
int
SectionIndex = 1;
bool
StartOfSection = false;
for
(int page = 1; page <= doc.PageCount;
page++)
{
ArrayList
pageNodes = finder.RetrieveAllNodesOnPages(page, page, NodeType.Paragraph);
//ArrayList
pageNodes = finder.RetrieveAllNodesOnPages(page,page);
if
(pageNodes.Count > 0)
{
Paragraph Para = null;
Paragraph
NewParaForHeaders = null;
Shape obj = null;
// Run objtest = null;
#region Set Image Place Holder For
Header#
#region Paragraph Selection
if (LastPara == ((Paragraph)pageNodes[0]))
{
if (pageNodes.Count > 1)
Para = ((Paragraph)pageNodes[1]);
else
continue; //AllowCreation =
false;
}
else
{
Para = ((Paragraph)pageNodes[0]);
}
#endregion
#region Section Detection
StartOfSection = false;
if (LastSection == null)
{
LastSection = Para.ParentSection;
StartOfSection = true;
}
else if (LastSection !=
Para.ParentSection)
{
LastSection = Para.ParentSection;
StartOfSection = true;
SectionIndex += 1;
}
#endregion
#region Page Blank Check
if (IsPageBlank(finder, page, LastPara)) continue;
#endregion
if (!StartOfSection) //&&
AllowCreation
{
NewParaForHeaders =
new Paragraph(doc);
obj = new
Shape(doc, ShapeType.Image);
obj.AlternativeText
= "#EachPageHeaderImage#" +
(SectionIndex).ToString() + "#";
NewParaForHeaders.AppendChild(obj);
//objtest = new Run(doc);
//objtest.Text = "#EachPageHeaderImage#" +
(SectionIndex).ToString() + "#";
//NewParaForHeaders.AppendChild(objtest);
if (Para.ParentNode.NodeType == NodeType.Cell)
{
try
{
Para.ParentNode.ParentNode.ParentNode.ParentNode.InsertBefore(NewParaForHeaders,
Para.ParentNode.ParentNode.ParentNode);
}
catch
{
}
}
else
{
Para.ParentNode.InsertBefore(NewParaForHeaders,
Para);
}
}
#endregion
#region Set Image Place Holder For
Footer#
Para = ((Paragraph)pageNodes[pageNodes.Count - 1]);
LastPara = Para;
if (IsPageBlank(finder, page + 1, LastPara)) continue;
if (!Para.IsEndOfSection) //&&
AllowCreation
{
if (LastSection == null)
LastSection =
Para.ParentSection;
else if (LastSection
!= Para.ParentSection)
{
LastSection =
Para.ParentSection;
SectionIndex +=
1;
}
NewParaForHeaders =
new Paragraph(doc);
obj = new Shape(doc, ShapeType.Image);
obj.AlternativeText
= "#EachPageFooterImage#" +
(SectionIndex).ToString() + "#";
NewParaForHeaders.AppendChild(obj);
//objtest = new Run(doc);
//objtest.Text = "#EachPageFooterImage#" +
(SectionIndex).ToString() + "#";
//NewParaForHeaders.AppendChild(objtest);
if (Para.ParentNode.NodeType == NodeType.Cell)
{
try
{
Para.ParentNode.ParentNode.ParentNode.ParentNode.InsertAfter(NewParaForHeaders,
Para.ParentNode.ParentNode.ParentNode);
}
catch
{
}
}
else
{
Para.ParentNode.InsertAfter(NewParaForHeaders,
Para);
}
}
#endregion
}
}
}
catch
(Exception ex)
{
}
return
doc;
}
static bool IsSpecialFont(string
Text)
{
Text = Text.Replace(" ", "").Trim();
if
(Text.StartsWith("&#")
&& Text.EndsWith(";"))
{
Text = Text.Replace("&#", "").Replace(";", "");
if
(Text.Replace("1", "").Replace("2",
"").Replace("3", "").Replace("4", "").Replace("5", "").Replace("6", "").Replace("7", "").Replace("8", "").Replace("9", "")
== "")
return
true;
}
return
false;
}
static bool IsPageBlank(PageNumberFinder
finder, int Page, Paragraph
LastPara)
{
try
{
#region Page Blank Check
ArrayList
pageNodes = finder.RetrieveAllNodesOnPages(Page, Page, NodeType.Paragraph);
int
StartIndex = 0;
bool
AllBlank = true;
if
(pageNodes.Count > 0)
{
if
(LastPara == ((Paragraph)pageNodes[0]))
StartIndex = 1;
for
(; StartIndex < pageNodes.Count; StartIndex++)
{
if (((Paragraph)pageNodes[StartIndex]).ChildNodes.Count
> 0)
{
AllBlank = false;
}
}
if
(AllBlank)
return true;
}
#endregion
}
catch
(Exception ex)
{
}
return
false;
}
static string TableAlignment(HtmlNode
table)
{
try
{
if
(table.ParentNode != null)
{
if
(table.ParentNode.Name.ToLower() == "div")
{
if (table.ParentNode.Attributes.Count > 0)
{
if (table.ParentNode.Attributes.ToList().Select(x
=> x.Name == "align").ToList().Count
> 0)
{
table.SetAttributeValue("align",
table.ParentNode.Attributes["align"].Value);
table.ParentNode.SetAttributeValue("align",
"");
}
if (table.ParentNode.Attributes["style"].Value.Contains("text-align"))
{
table.SetAttributeValue("align",
table.ParentNode.Attributes["text-align"].Value);
table.ParentNode.SetAttributeValue("style",
"");
}
}
}
}
}
catch
(Exception ex)
{
}
return
table.InnerHtml;
}
static Document ManageFonts(Document
doc, IRIS.CoreServices.Common.UserContext
user, IRIS.CoreServices.Logging.Logger
logger)
{
try
{
NodeCollection
textObjects = doc.GetChildNodes(NodeType.Run,
true);
foreach
(Run textObject in
textObjects)
{
if
(textObject.Font.Engrave)
{
textObject.Font.Engrave = false;
textObject.Font.Color =
System.Drawing.Color.Black;
}
if
(textObject.Font.Emboss)
{
textObject.Font.Emboss = false;
textObject.Font.Color =
System.Drawing.Color.Black;
}
if
(textObject.Font.Shadow)
{
textObject.Font.Shadow
= false;
}
if
(textObject.Font.Outline)
{
textObject.Font.Outline
= false;
}
if
(textObject.Font.Hidden)
{
textObject.Font.Hidden = false;
}
}
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"ManageFonts", "0", ex.Message, "");//
if
(logger != null)
logger.Log(ex.Message.ToString(), LogLevel.DEBUG,
Guid.NewGuid());
}
return
doc;
}
static Document ManageTableCellBorders(Document doc, IRIS.CoreServices.Common.UserContext user, IRIS.CoreServices.Logging.Logger logger)
{
bool
isLineCreated = false;
try
{
NodeCollection
paraObjects = doc.GetChildNodes(NodeType.Paragraph,
true);
foreach
(Paragraph paraObject in paraObjects)
{
isLineCreated = false;
#region "Table Cell Line Style
handling"
try
{
if (paraObject.ParentNode.NodeType == NodeType.Cell)
{
if (paraObject.ParagraphFormat.Borders.LineStyle == LineStyle.Double ||
paraObject.ParagraphFormat.Borders.Bottom.LineStyle == LineStyle.Double)
{
Run objText = new Run(doc);
objText.Text = "@#double#@";
paraObject.AppendChild(objText);
isLineCreated =
true;
}
else if
(paraObject.ParagraphFormat.Borders.Top.LineStyle == LineStyle.Double)
{
Run objText = new Run(doc);
if (paraObject.PreviousSibling != null)
objText.Text = "@#double#@";
else
objText.Text = "@#doubletop#@";
paraObject.AppendChild(objText);
isLineCreated =
true;
}
else
{
NodeCollection textObjects =
paraObject.GetChildNodes(NodeType.Run, true);
foreach (Run
textObject in textObjects)
{
if (textObject.Font.Border.LineStyle == LineStyle.Double || textObject.Font.Underline == Underline.Double)
{
if (textObject.Text.Length > 20)
textObject.Text
= "@#double#@" +
textObject.Text.Replace(" ", " @#double#@") + "@#double#@";
else
textObject.Text = "@#double#@"
+ textObject.Text + "@#double#@";
isLineCreated = true;// break;
}
}
}
if (isLineCreated) continue;
if (paraObject.ParagraphFormat.Borders.LineStyle == LineStyle.Single ||
paraObject.ParagraphFormat.Borders.Bottom.LineStyle == LineStyle.Single)
{
Run objText = new Run(doc);
objText.Text = "@#single#@";
paraObject.AppendChild(objText);
isLineCreated =
true;
}
else if (paraObject.ParagraphFormat.Borders.Top.LineStyle
== LineStyle.Single)
{
Run objText = new Run(doc);
if (paraObject.PreviousSibling != null)
objText.Text = "@#single#@";
else
objText.Text = "@#singletop#@";
paraObject.AppendChild(objText);
isLineCreated = true;
}
else
{
NodeCollection textObjects =
paraObject.GetChildNodes(NodeType.Run, true);
foreach
(Run textObject in
textObjects)
{
if (textObject.Font.Border.LineStyle == LineStyle.Single || textObject.Font.Underline == Underline.Single)
{
textObject.Text = "@#single#@@#u#@"
+ textObject.Text;
isLineCreated = true; //break;
}
}
}
if (isLineCreated) continue;
}
else
{
#region Double border changes for other
paragraphs
if (paraObject.ParagraphFormat.Borders.LineStyle == LineStyle.Double ||
paraObject.ParagraphFormat.Borders.Bottom.LineStyle == LineStyle.Double)
{
Run objText = new Run(doc);
objText.Text = "@#double#@";
paraObject.AppendChild(objText);
}
else
{
NodeCollection
textObjects = paraObject.GetChildNodes(NodeType.Run,
true);
foreach (Run
textObject in textObjects)
{
if (textObject.Font.Border.LineStyle == LineStyle.Double || textObject.Font.Underline == Underline.Double)
{
if (textObject.Text.Length > 20)
textObject.Text = "@#double#@"
+ textObject.Text.Replace(" ", " @#double#@") + "@#double#@";
else
textObject.Text = "@#double#@"
+ textObject.Text + "@#double#@";
}
}
}
#endregion
}
}
catch
{
}
#endregion
}
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"ManageTableCellBorders", "0", ex.Message,
"");//
logger.Log(ex.Message.ToString(), LogLevel.DEBUG,
Guid.NewGuid());
}
return
doc;
}
public string ParseSpecialObjects(Aspose.Words.Document doc)
{
string
strError = "";
Dictionary<string, int>
spCount = new Dictionary<string, int>();
try
{
Aspose.Words.NodeCollection Shapes =
doc.GetChildNodes(Aspose.Words.NodeType.Shape,
true);
foreach
(Aspose.Words.Drawing.Shape objShape in Shapes)
{
if
(objShape.IsWordArt)
{
bool headerContent = false;
if (objShape.ParentNode != null)
{
if (objShape.ParentNode.ParentNode != null)
{
if (objShape.ParentNode.ParentNode.NodeType ==
Aspose.Words.NodeType.HeaderFooter)
{
headerContent = true;
}
else if
(objShape.ParentNode.ParentNode.ParentNode != null)
{
if
(objShape.ParentNode.ParentNode.ParentNode.NodeType == Aspose.Words.NodeType.HeaderFooter)
{
headerContent = true;
}
}
}
}
if (!objShape.AlternativeText.StartsWith("#")
&& !objShape.AlternativeText.EndsWith("#"))
{
if (headerContent)
{
if (!spCount.ContainsKey("Header
WordArt"))
spCount.Add("Header WordArt",
1);
else
spCount["Header WordArt"] = spCount["Header WordArt"] + 1;
}
else
{
if (!spCount.ContainsKey("WordArt"))
spCount.Add("WordArt", 1);
else
spCount["WordArt"] = spCount["WordArt"] + 1;
}
}
}
else
if (objShape.ShapeType == Aspose.Words.Drawing.ShapeType.OleObject)
{
if (objShape.OleFormat != null)
{
try
{
if (objShape.OleFormat.SuggestedExtension.Contains(".htm") ||
objShape.OleFormat.SourceFullName.EndsWith(".htm")
|| objShape.OleFormat.SourceFullName.EndsWith(".html"))
{
if (!spCount.ContainsKey("htm"))
spCount.Add("htm", 1);
else
spCount["htm"] = spCount["htm"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".pdf")
|| objShape.OleFormat.SourceFullName.EndsWith(".pdf"))
{
if (!spCount.ContainsKey("PDF"))
spCount.Add("PDF", 1);
else
spCount["PDF"] = spCount["PDF"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".xls"))
{
if (objShape.OleFormat.IsLink)
{
if
(!spCount.ContainsKey("Linked file"))
spCount.Add("Linked file",
1);
else
spCount["Linked file"] =
spCount["Linked file"] + 1;
}
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".ppt"))
{
if
(!spCount.ContainsKey("PPT Presentation"))
spCount.Add("PPT Presentation",
1);
else
spCount["PPT Presentation"]
= spCount["PPT Presentation"] + 1;
}
else if
(objShape.OleFormat.ProgId.ToLower().Contains(".chart."))
{
if (!spCount.ContainsKey("Graph"))
spCount.Add("Graph", 1);
else
spCount["Graph"] = spCount["Graph"] + 1;
}
else if (objShape.OleFormat.ProgId.ToLower().Contains("powerpoint.slide"))
{
if (!spCount.ContainsKey("PPT
Slide"))
spCount.Add("PPT Slide",
1);
else
spCount["PPT Slide"] =
spCount["PPT Slide"] + 1;
}
else if
(objShape.OleFormat.ProgId.ToLower().Contains("wordpad"))
{
if (!spCount.ContainsKey("Wordpad"))
spCount.Add("Wordpad", 1);
else
spCount["Wordpad"]
= spCount["Wordpad"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".avi")
|| objShape.OleFormat.SuggestedExtension.Contains(".vlc")
|| objShape.OleFormat.SuggestedExtension.Contains(".dat"))
{
if (!spCount.ContainsKey("Video
File"))
spCount.Add("Video File",
1);
else
spCount["Video File"] =
spCount["Video File"] + 1;
}
else if
(objShape.OleFormat.IsLink)
{
if (!spCount.ContainsKey("Linked
file"))
spCount.Add("Linked file",
1);
else
spCount["Linked file"] =
spCount["Linked file"] + 1;
}
}
catch
{
if (objShape.OleFormat.ProgId.ToLower().Contains("package"))
{
if (!spCount.ContainsKey("Linked
file"))
spCount.Add("Linked file",
1);
else
spCount["Linked
file"] = spCount["Linked
file"] + 1;
}
else
{
objShape.AlternativeText = "#Custom
object#";
if (!spCount.ContainsKey("Custom
object"))
spCount.Add("Custom object",
1);
else
spCount["Custom object"] =
spCount["Custom object"] + 1;
}
}
}
}
else
if (objShape.ShapeType == Aspose.Words.Drawing.ShapeType.Image)
{
if (!objShape.AlternativeText.StartsWith("#")
&& !objShape.AlternativeText.EndsWith("#"))
{
if (objShape.ParentNode != null)
{
if
(objShape.ParentNode.NodeType == Aspose.Words.NodeType.HeaderFooter)
continue;
if (objShape.ParentNode.ParentNode != null)
{
if (objShape.ParentNode.ParentNode.NodeType ==
Aspose.Words.NodeType.HeaderFooter)
continue;
}
}
if (objShape.ImageData.ImageType ==
Aspose.Words.Drawing.ImageType.Wmf)
{
if (!spCount.ContainsKey("Clipart"))
spCount.Add("Clipart", 1);
else
spCount["Clipart"] = spCount["Clipart"] + 1;
}
//else
//
objShape.AlternativeText = "#Shape Image#";
}
}
//else
if (objShape.ShapeType == Aspose.Words.Drawing.ShapeType.CustomShape)
//{
// if (!spCount.ContainsKey("Shape
Image"))
// spCount.Add("Shape Image",
1);
// else
// spCount["Shape Image"] =
spCount["Shape Image"] + 1;
//}
}
}
catch
(Exception ex)
{
}
Aspose.Words.NodeCollection imgs =
doc.GetChildNodes(Aspose.Words.NodeType.DrawingML,
true);
foreach
(DrawingML objShape in
imgs)
{
if
(objShape.AlternativeText.ToLower().Contains("wmf")
|| objShape.AlternativeText.ToLower().Contains(".eps"))
{
if
(!spCount.ContainsKey("Clipart"))
spCount.Add("Clipart", 1);
else
spCount["Clipart"] = spCount["Clipart"] + 1;
}
else
if (objShape.Name.ToUpper().StartsWith("CHART"))
{
if
(!spCount.ContainsKey("Graph"))
spCount.Add("Graph", 1);
else
spCount["Graph"] = spCount["Graph"] + 1;
}
}
string
str = "Please note that the document you wish
to upload contains the following special text objects -\n\r";
string
str1 = "";
string strTrackChanges = string.Empty;
int
nestedCount = ValidateNestedTables(doc);
if
(spCount.Count > 0)
{
foreach
(string strkey in
spCount.Keys)
{
if
(str1 == "")
{
str1 =
spCount[strkey].ToString() + " " +
strkey;
}
else
{
str1 += ", " + spCount[strkey].ToString() + " " + strkey;
}
}
}
if
(nestedCount > 0)
{
if
(str1 == "")
{
str1 =
nestedCount.ToString() + " Nested Table";
}
else
{
str1 += ", " + nestedCount.ToString() + " Nested Table";
}
}
if
(doc.HasRevisions)
strTrackChanges = "\n\rDocument also contains Tracked changes which
will be accepted upon conversion.";
if
(str1.Trim() != "")
{
str += str1;
str += "
which may not render properly.";
if
(strTrackChanges.Trim() != "")
str += strTrackChanges;
str += "
You can preview the HTML document once the conversion is completed. This may
take some time.\n\r Alternatively, you can replace/remove these special text
objects manually and re-upload the document.";
str += "\n\r
Do you want to continue with conversion?\n\r ";
strError = str;
}
else
if (strTrackChanges.Trim() != "")
{
strError = "Document contains Tracked changes which will be
accepted upon conversion.\n\r Do you want to continue with
conversion?\n\r";
}
return
strError;
}
static Document ManageInvalidObjects(Document doc, ref List<IRIS.CoreServices.Utility.Error> objError, IRIS.CoreServices.Common.UserContext user, IRIS.CoreServices.Logging.Logger logger)
{
//if
(isDev)
//{
// CommonUtil obj = new CommonUtil();
// string a = obj.ParseSpecialObjects(doc);
// a = a.Replace("\n\r",
"*").Replace("/", " or ");
//}
// int
idCount = 1;
//Dictionary<string,
int> spCount = new Dictionary<string, int>();
try
{
NodeCollection
Shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach
(Shape objShape in
Shapes)
{
if
(objShape.IsWordArt)
{
bool headerContent = false;
if
(objShape.ParentNode != null)
{
if (objShape.ParentNode.ParentNode != null)
{
if (objShape.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent = true;
}
else if
(objShape.ParentNode.ParentNode.ParentNode != null)
{
if
(objShape.ParentNode.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent = true;
}
}
}
}
if (!objShape.AlternativeText.StartsWith("#")
&& !objShape.AlternativeText.EndsWith("#"))
{
//idCount = idCount + 1;
if (headerContent)
{
objShape.AlternativeText = "#Header
WordArt#";//~" + "I" +
idCount.ToString();
AddErrorToErrorList(ref objError, objShape.AlternativeText.Replace("#", ""),
0, objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Header WordArt"))
//
spCount.Add("Header WordArt", 1);
//else
//
spCount["Header WordArt"] = spCount["Header
WordArt"] + 1;
}
else
{
objShape.AlternativeText = "#WordArt#";//~" + "I" + idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Header WordArt"))
//
spCount.Add("WordArt", 1);
//else
//
spCount["WordArt"] = spCount["WordArt"] + 1;
}
}
}
else
if (objShape.ShapeType == ShapeType.OleObject)
{
if (objShape.OleFormat != null)
{
try
{
if (objShape.OleFormat.SuggestedExtension.Contains(".htm") || objShape.OleFormat.SourceFullName.EndsWith(".htm") ||
objShape.OleFormat.SourceFullName.EndsWith(".html"))
{
// idCount = idCount + 1;
objShape.AlternativeText = "#htm#";//~" + "I" + idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
// if
(!spCount.ContainsKey("htm"))
//
spCount.Add("htm", 1);
//else
//
spCount["htm"] = spCount["htm"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".pdf")
|| objShape.OleFormat.SourceFullName.EndsWith(".pdf"))
{
// idCount = idCount + 1;
objShape.AlternativeText = "#PDF#";//~" + "I" + idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0, objShape.AlternativeText.Replace("#", ""),
1, "Special Objects", "");
//if (!spCount.ContainsKey("PDF"))
//
spCount.Add("PDF", 1);
//else
//
spCount["PDF"] = spCount["PDF"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".xls"))
{
if
(!objShape.AlternativeText.Contains("$EXCEL$"))
{
objShape.AlternativeText = "#EXCEL#";
//if (objShape.OleFormat.IsLink)
//{
// if
(!spCount.ContainsKey("EXCEL"))
//
spCount.Add("EXCEL", 1);
// else
//
spCount["EXCEL"] = spCount["EXCEL"] + 1;
//}
}
if (objShape.OleFormat.IsLink)
{
objShape.AlternativeText = "#Linked
file#";
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0, objShape.AlternativeText.Replace("#", ""),
1, "Special Objects", "");
}
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".ppt"))
{
objShape.AlternativeText = "#PPT
Presentation#";//+ "I" +
idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0, objShape.AlternativeText.Replace("#", ""),
1, "Special Objects", "");
//if (!spCount.ContainsKey("PPT Presentation"))
//
spCount.Add("PPT Presentation", 1);
//else
// spCount["PPT
Presentation"] = spCount["PPT Presentation"] + 1;
}
else if
(objShape.OleFormat.ProgId.ToLower().Contains(".chart."))
{
// idCount = idCount
+ 1;
objShape.AlternativeText = "#Graph#";// + "I" + idCount.ToString();
AddErrorToErrorList(ref
objError, objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Graph"))
//
spCount.Add("Graph", 1);
//else
// spCount["Graph"] = spCount["Graph"]
+ 1;
}
else if
(objShape.OleFormat.ProgId.ToLower().Contains("powerpoint.slide")
|| objShape.OleFormat.ProgId.ToLower().Contains("powerpoint.templatemacro"))
{
objShape.AlternativeText = "#PPT Slide#";// + "I" + idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if
(!spCount.ContainsKey("PPT Slide"))
// spCount.Add("PPT Slide", 1);
//else
// spCount["PPT
Slide"] = spCount["PPT Slide"] + 1;
}
else if
(objShape.OleFormat.ProgId.ToLower().Contains("wordpad"))
{
objShape.AlternativeText = "#Wordpad#";// + "I" + idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
// if
(!spCount.ContainsKey("Wordpad"))
//
spCount.Add("Wordpad", 1);
//else
//
spCount["Wordpad"] = spCount["Wordpad"] + 1;
}
else if
(objShape.OleFormat.SuggestedExtension.Contains(".avi")
|| objShape.OleFormat.SuggestedExtension.Contains(".wmv")
|| objShape.OleFormat.SuggestedExtension.Contains(".vlc")
|| objShape.OleFormat.SuggestedExtension.Contains(".dat"))
{
// idCount = idCount + 1;
objShape.AlternativeText = "#Video
File#";//~" + "I" +
idCount.ToString();
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("AVI"))
//
spCount.Add("AVI", 1);
//else
//
spCount["AVI"] = spCount["AVI"] + 1;
}
else if
(objShape.OleFormat.IsLink)
{
objShape.AlternativeText = "#Linked
file#";
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Linked file"))
//
spCount.Add("Linked file", 1);
//else
//
spCount["Linked file"] = spCount["Linked file"] + 1;
}
else
{
// idCount = idCount + 1;
objShape.AlternativeText = "#Custom
Shape#";// + "I" +
idCount.ToString();
//if
(!spCount.ContainsKey("Custom Shape"))
//
spCount.Add("Custom Shape", 1);
//else
//
spCount["Custom Shape"] = spCount["Custom Shape"] +
1;
}
}
catch
{
if (objShape.OleFormat.ProgId.ToLower().Contains("package"))
{
objShape.AlternativeText = "#Linked
file#";
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0, objShape.AlternativeText.Replace("#", ""),
1, "Special Objects", "");
//if (!spCount.ContainsKey("Linked file"))
//
spCount.Add("Linked file", 1);
//else
// spCount["Linked file"] =
spCount["Linked file"] + 1;
}
else
{
objShape.AlternativeText = "#Custom object#";
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Custom object"))
//
spCount.Add("Custom object", 1);
//else
//
spCount["Custom object"] = spCount["Custom object"]
+ 1;
}
}
}
}
else
if (objShape.ShapeType == ShapeType.Image)
{
if (!objShape.AlternativeText.StartsWith("#")
&& !objShape.AlternativeText.EndsWith("#"))
{
if (objShape.ParentNode != null)
{
if (objShape.ParentNode.NodeType == NodeType.HeaderFooter)
continue;
if (objShape.ParentNode.ParentNode != null)
{
if (objShape.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
continue;
}
}
if (objShape.ImageData.ImageType ==
Aspose.Words.Drawing.ImageType.Wmf)
{
objShape.AlternativeText = "#Clipart#";
AddErrorToErrorList(ref objError,
objShape.AlternativeText.Replace("#",
""), 0,
objShape.AlternativeText.Replace("#",
""), 1, "Special
Objects", "");
}
else
objShape.AlternativeText = "#DrawingImage#";
//"#Shape Image#";
//if (!spCount.ContainsKey("Shape Image"))
//
spCount.Add("Shape Image", 1);
//else
//
spCount["Shape Image"] = spCount["Shape Image"] + 1;
}
}
else
if (objShape.ShapeType == ShapeType.StraightConnector1 || objShape.ShapeType
== ShapeType.Line)
{
string AppendAttributes = string.Empty;
AppendAttributes += "#HR#";
if
(objShape.Width > 250)
{
AppendAttributes +=
"#FullWidth#";
}
if (objShape.Left > 120 && objShape.Right > 120)
{
AppendAttributes += "#center#";
}
else if (objShape.Left > 120)
{
AppendAttributes +=
"#left#";
}
else if (objShape.Right > 120)
{
AppendAttributes +=
"#right#";
}
objShape.AlternativeText = AppendAttributes;//By
Shrikant ....Extract Contents of Lines
}
else
if (objShape.ShapeType == ShapeType.CustomShape)
{
// idCount = idCount + 1;
objShape.AlternativeText = "#DrawingImage#";
//"#Shape Image#";//~" + "I"
+ idCount.ToString();
// AddErrorToErrorList(ref objError, "Shape Image", idCount,
"Shape Image object present in Document", "", "Special
Objects", "I" + idCount.ToString());
// AddErrorToErrorList(ref
objError, objShape.AlternativeText.Replace("#", ""), 0,
objShape.AlternativeText.Replace("#", ""), 1, "Special
Objects", "");
//if (!spCount.ContainsKey("Shape Image"))
// spCount.Add("Shape
Image", 1);
//else
// spCount["Shape
Image"] = spCount["Shape Image"] + 1;
}
else
if (objShape.ChildNodes.Count > 0)
{
ExtractTextBoxContents(objShape); //By
Shrikant ....Extract Contents of textbox
}
else
{
// idCount = idCount + 1;
objShape.AlternativeText
= "#Custom Shape#";//~" + "I" + idCount.ToString();
// AddErrorToErrorList(ref objError, "Custom Shape", idCount,
"Custom shape object present in Document", "",
"Special Objects", "I" + idCount.ToString());
//if
(!spCount.ContainsKey("Custom Shape"))
// spCount.Add("Custom
Shape", 1);
//else
// spCount["Custom
Shape"] = spCount["Custom Shape"] + 1;
}
}
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"ManageInvalidObjects", "0", ex.Message, "");//
if
(logger != null)
logger.Log(ex.Message.ToString(), LogLevel.DEBUG,
Guid.NewGuid());
}
NodeCollection
imgs = doc.GetChildNodes(NodeType.DrawingML,
true);
foreach
(DrawingML objShape in
imgs)
{
if
(objShape.AlternativeText.ToLower().Contains("wmf")
|| objShape.AlternativeText.ToLower().Contains(".eps"))
{
//
idCount = idCount + 1;
if
(objShape.ParentNode != null)
{
if (objShape.ParentNode.NodeType == NodeType.HeaderFooter)
continue;
if (objShape.ParentNode.ParentNode != null)
{
if (objShape.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
continue;
}
}
objShape.AlternativeText = "#Clipart#";//~"
+ "I" + idCount.ToString();
AddErrorToErrorList(ref objError, "Clipart",
0, "Clipart", 1, "Special Objects", "");
//if
(!spCount.ContainsKey("Clipart"))
// spCount.Add("Clipart", 1);
//else
// spCount["Clipart"] =
spCount["Clipart"] + 1;
}
else
if (objShape.Name.ToUpper().StartsWith("CHART"))
{
AddErrorToErrorList(ref objError, "Graph",
0, "Graph", 1, "Special Objects", "");
//if
(!spCount.ContainsKey("Graph"))
// spCount.Add("Graph", 1);
//else
// spCount["Graph"] =
spCount["Graph"] + 1;
}
//else
//{
// if (!spCount.ContainsKey("Shape
Image"))
// spCount.Add("Shape Image",
1);
// else
// spCount["Shape Image"] =
spCount["Shape Image"] + 1;
//}
}
int
nestedCount = ValidateNestedTables(doc);
//if
(spCount.Count > 0)
//{
// foreach (string strkey in spCount.Keys)
// {
// AddErrorToErrorList(ref objError,
strkey, 0, strkey, spCount[strkey], "Special Objects", "");
// }
//}
//if
(spCount.Count > 0)
//{
// foreach (string strkey in spCount.Keys)
// {
// for (int i = 0; i < spCount[strkey];
i++)
// {
// AddErrorToErrorList(ref objError,
strkey, 0, strkey, 1, "Special Objects", "");
// }
// }
//}
if
(nestedCount > 0)
{
AddErrorToErrorList(ref objError, "Nested
Table", 0, "Nested Table",
nestedCount, "Special Objects", "");
}
if
(doc.HasRevisions)
{
AddErrorToErrorList(ref objError, "Track
changes", 0, "Track changes",
nestedCount, "Track changes present",
"");
}
return
doc;
}
private static void
AddErrorToErrorList(ref List<Error> errorList,
string nodeName, int
lineNo, string description, int errorCount, string
attribute, string id)
{
try
{
Error
error = new Error();
error.tagName = nodeName;
error.description =
description;
error.lineNo = lineNo;
error.type =
IRIS.CoreServices.Utility.Resources.ConversionErrorCode.E105;
error.id = id;
error.errorStatus = errorCount;
error.isDeleted = false;
error.attributeName =
attribute;
errorList.Add(error);
}
catch
{
}
}
public static int
ValidateNestedTablesOld(Aspose.Words.Document
doc)
{
int
_NestedTables = 0;
Aspose.Words.NodeCollection tableList =
doc.GetChildNodes(Aspose.Words.NodeType.Table,
true);
foreach
(Aspose.Words.Tables.Table table in tableList)
{
if
(table.Rows.Count > 0)
{
for
(int row = 0; row < table.Rows.Count; row++)
{
for (int col = 0; col <
table.Rows[row].Cells.Count; col++)
{
if (table.Rows[row].Cells[col].HasChildNodes)
{
for (int child = 0;
child < table.Rows[row].Cells[col].ChildNodes.Count; child++)
{
if
(table.Rows[row].Cells[col].ChildNodes[child].NodeType == Aspose.Words.NodeType.Table)
_NestedTables += 1;
}
}
}
}
}
}
return
_NestedTables;
}
public static int
ValidateNestedTables(Aspose.Words.Document
doc)
{
int
_NestedTables = 0;
bool
isNestedTable = false;
Aspose.Words.NodeCollection tableList =
doc.GetChildNodes(Aspose.Words.NodeType.Table,
true);
foreach
(Aspose.Words.Tables.Table table in tableList)
{
isNestedTable = false;
if
(table.Rows.Count > 0)
{
for
(int row = 0; row < table.Rows.Count; row++)
{
for (int col = 0; col <
table.Rows[row].Cells.Count; col++)
{
if (table.Rows[row].Cells[col].HasChildNodes)
{
for (int child = 0;
child < table.Rows[row].Cells[col].ChildNodes.Count; child++)
{
if
(table.Rows[row].Cells[col].ChildNodes[child].NodeType == Aspose.Words.NodeType.Table)
{
isNestedTable = true; break;
}
}
}
if (isNestedTable) break;
}
if (isNestedTable) break;
}
if
(isNestedTable)
{
_NestedTables += 1;
}
}
}
return
_NestedTables;
}
static Document ManageImages(Document
doc, string sType, IRIS.CoreServices.Common.UserContext user, IRIS.CoreServices.Logging.Logger logger)
{
try
{
#region "LogiC By Shrikant to Inline
Images"
NodeCollection
Shapes = doc.GetChildNodes(NodeType.Shape, true);
foreach
(Aspose.Words.Drawing.Shape objShape in Shapes)
{
if
(objShape.AlternativeText == "#TextBoxShape#")
{
if (sType != "default")
{
CompositeNode ChildParent = objShape.ParentNode;
objShape.WrapType =
WrapType.Inline;
objShape.HorizontalAlignment
= HorizontalAlignment.Left;
if (ChildParent.NodeType == NodeType.Paragraph)
{
((Paragraph)ChildParent).ParagraphFormat.Alignment =
ParagraphAlignment.Left;
}
}
}
else
if (objShape.IsInsertRevision && sType
== "default")
{
objShape.AlternativeText = "#InsertedShape#";
}
else
if (objShape.IsDeleteRevision && sType
== "default")
{
objShape.AlternativeText = "#DeletedShape#";
}
else
{
if (!objShape.AlternativeText.StartsWith("#")
&& !objShape.AlternativeText.EndsWith("#")
&& sType == "default")
objShape.AlternativeText = "#DrawingImage#";
//"#Shape Image#";
}
}
NodeCollection
DrawingMLs = doc.GetChildNodes(NodeType.DrawingML,
true);
foreach
(Aspose.Words.Drawing.DrawingML objDrawingML
in DrawingMLs)
{
if
(objDrawingML.AlternativeText == "#TextBoxImage#")
{
if (sType != "default")
{
CompositeNode ChildParent =
objDrawingML.ParentNode;
if (ChildParent.NodeType == NodeType.Paragraph)
{
((Paragraph)ChildParent).ParagraphFormat.Alignment =
ParagraphAlignment.Left;
}
}
}
else
if (objDrawingML.IsInsertRevision &&
sType == "default")
{
objDrawingML.AlternativeText = "#InsertedImage#";
}
//else
if (objDrawingML.Target == "#clipart#")
//{
// objDrawingML.AlternativeText =
"#AnyShape#";
//}
else
if (objDrawingML.IsDeleteRevision &&
sType == "default")
{
objDrawingML.AlternativeText = "#DeletedImage#";
}
else
{
if (!objDrawingML.AlternativeText.StartsWith("#") &&
!objDrawingML.AlternativeText.EndsWith("#")
&& sType == "default")
{
if (objDrawingML.Name.ToUpper().StartsWith("CHART"))
objDrawingML.AlternativeText = "#Graph#";
else
objDrawingML.AlternativeText = "#DrawingImage#";
}
if (!objDrawingML.IsInline)
{
try
{
if (sType != "default")
{
CompositeNode ChildParent =
objDrawingML.ParentNode;
if (ChildParent.ParentNode.NodeType != NodeType.Cell)
{
Paragraph NewPara = new
Paragraph(doc);
NewPara.ParagraphFormat.Alignment = ParagraphAlignment.Center;
NewPara.AppendChild(objDrawingML);
ChildParent.ParentNode.InsertAfter(NewPara, ChildParent);
}
else
{
//if (objDrawingML.ParentNode.NodeType ==
NodeType.Paragraph)
//{
//
((Paragraph)objDrawingML.ParentNode).ParagraphFormat.Alignment =
ParagraphAlignment.Center;
//}
}
}
}
catch
{
}
}
}
}
#endregion
}
catch
(Exception ex)
{
//logger.LogAudit("Normalization",
user.UserId, user.ActiveReportId, user.ActiveCompanyId, user.UserDisplayName,
"ManageImages", "0", ex.Message, "");//
if
(logger != null)
logger.Log(ex.Message.ToString(), LogLevel.DEBUG,
Guid.NewGuid());
}
return
doc;
}
static void CreateFormattingOfComments(ref Document doc, ref Dictionary<int, string>
commentData)
{
try
{
ArrayList
collectedComments = new ArrayList();
//Dictionary<int,
string> commentData = new Dictionary<int, string>();
NodeCollection
comments = doc.GetChildNodes(NodeType.Comment,
true);
//
Look through all comments and gather information about them.
foreach
(Aspose.Words.Comment comment in comments)
{
commentData.Add(comment.Id,
comment.Author + "|" +
comment.DateTime + "|" +
comment.ToString(Aspose.Words.SaveFormat.Text));
}
NodeCollection
commentsStart = doc.GetChildNodes(NodeType.CommentRangeStart,
true);
//
Look through all comments and gather information about them.
foreach
(Aspose.Words.CommentRangeStart comment in commentsStart)
{
CompositeNode
p = comment.ParentNode;
string
commentText = commentData[Convert.ToInt32(comment.Id)];
string[]
commentTextArray = commentText.Split('|');
Run
node = new Run(doc);
commentData[Convert.ToInt32(comment.Id)] = "<e-comment
class=\"ephox-comment-Shrikant\"
data='[{\"author\":\"" + commentTextArray[0] + "\",\"text\":\"" +
commentTextArray[2] + "\",\"time\":\""
+ commentTextArray[1] + "\"}]'>";
node.Text = "$e-comment$" + comment.Id + "";
p.InsertBefore(node,
comment);
p.RemoveChild(comment);
}
NodeCollection
commentsEnds = doc.GetChildNodes(NodeType.CommentRangeEnd,
true);
foreach
(Aspose.Words.CommentRangeEnd comment in commentsEnds)
{
CompositeNode
p = comment.ParentNode;
string
TextboxContent = comment.GetText();
Run
node = new Run(doc);
node.Text = "$/e-comment$";
p.InsertAfter(node,
comment);
p.RemoveChild(comment);
}
}
catch
(Exception ex)
{
}
}
static void ExtractTextBoxContents(Shape
objShape)
{
try
{
#region "LogiC By Shrikant to
Extract contents of Textbox"
CompositeNode
ChildParent = objShape.ParentNode;
if
(objShape.ParentNode.NodeType == NodeType.GroupShape)
{
ChildParent =
objShape.ParentNode.ParentNode;
}
CompositeNode
SuperParent = ChildParent.ParentNode;
Paragraph
lastOne = null;
bool
l = false;
#region "LogiC By Shrikant to
Identify Texbox Images (.Shape)"
NodeCollection
ObjImgShapes = objShape.GetChildNodes(NodeType.Shape,
true);
foreach
(Shape ObjImgShape in
ObjImgShapes)
{
bool
headerContent = false;
if
(objShape.ParentNode != null)
{
if (ObjImgShape.ParentNode.ParentNode != null)
{
if (ObjImgShape.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent =
true;
}
else if
(ObjImgShape.ParentNode.ParentNode.ParentNode != null)
{
if
(ObjImgShape.ParentNode.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent = true;
}
}
}
}
if
(headerContent)
ObjImgShape.AlternativeText
= "#HeaderTextBoxShape#";
else
ObjImgShape.AlternativeText = "#TextBoxShape#";
}
#endregion
#region "LogiC By Shrikant to
Identify Texbox Images (.DrawingML)"
NodeCollection
ObjDrawingMLs = objShape.GetChildNodes(NodeType.DrawingML,
true);
foreach
(Aspose.Words.Drawing.DrawingML objDrawingML
in ObjDrawingMLs)
{
bool
headerContent = false;
if
(objShape.ParentNode != null)
{
if (objDrawingML.ParentNode.ParentNode != null)
{
if (objDrawingML.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent =
true;
}
else if
(objDrawingML.ParentNode.ParentNode.ParentNode != null)
{
if
(objDrawingML.ParentNode.ParentNode.ParentNode.NodeType == NodeType.HeaderFooter)
{
headerContent = true;
}
}
}
}
if
(headerContent)
objDrawingML.AlternativeText = "#HeaderTextBoxImage#";
else
objDrawingML.AlternativeText = "#TextBoxImage#";
}
#endregion
NodeCollection
objParagraphs = objShape.GetChildNodes(NodeType.Paragraph,
true);
while
(objParagraphs.Count > 0)
{
Paragraph
objParagraph = ((Paragraph)(objParagraphs[0]));
if
(lastOne != null)
SuperParent.InsertAfter(objParagraph, lastOne);
else
SuperParent.InsertAfter(objParagraph, ChildParent);
lastOne = objParagraph;
l = true;
}
if
(l)
{
objShape.ParentNode.RemoveChild(objShape);
}
//ChildParent.RemoveChild(objShape);
#endregion
}
catch
(Exception ex)
{
}
}
#endregion
#endregion
In this providing information about WCF and Web API. Thank for nice blog. In case someone want to know about IT training courses in Rohtak.
ReplyDeletePython Training Course | PHP & MySQL Training | HTML & CSS (Web Designing) Training | Digital Marketing Course | C Language Training | Basic Computer | Merient Infotech
Nice article. It's very helpful to my work.
ReplyDeleteMerient Infotech provides best IT training in Rohtak. We specialize in preparing the Professionals in the field of Digital Marketing, Web Development, Web Designing, MS-Office, Basic to Advance Programming Language like PHP, Python, JavaScript, HTML, CSS and jQuery.
Merient Infotech
Digital Marketing
PHP
Python
Web Development
Web Designing