We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Need help on Documentbuilder

Hi,
I have a function which needs to be called recursively depending on the number of pages a document has. see the function below

for (int pagecount = 1; pagecount < DynamictDoc.PageCount; pagecount++)
{
    SetSideBarNew(ref DynamictDoc, ref documentBuilder, contentData.FolderId 
}

The use of this function is the it is dynamically setting leftside bar in word document on every page. But issue here is this function is overwriting all the previous calls. For eg.
If the document contains 3 pages, only the 3rd page is showing the left sidebar note the first 2 pages,Similarily if the document contains 4 pages,only the 4th page is showing the leftside bar.,
not the first 3 pages.
Can you tell me whats the issue here…

Hi Sunny,

Thanks for your interest in Aspose.Word. Could you please share more information regarding your requirements and sample input/output documents? So we will look into these and suggest you accordingly.

I’m also moving the thread to the related Aspose forum…

Best Regards,

I am using a documentbuilder object see the sample below.I need to left indent a content marked in the yellow section . Can you tell me how can i achieve this…I am using lot of merrge fields and all the merge fields are using the same documentbuilder object. I just need to indent the content marked as yellow.

string practices = GetPracticeHtml(folderList);
documentBuilder.MoveToMergeField("BioPractices");
documentBuilder.InsertHtml(string.Format("{0}", practices));

private string GetPracticeHtml(List FolderContentList)
{
    StringBuilder strPartice = new StringBuilder();
    int i = 0;
    if (FolderContentList != null && FolderContentList.Count > 0)
    {
        strPartice.Append("Practice Area");
        foreach (FolderContent foldContent in FolderContentList)
        {
            EktronHelper.SortList(foldContent.ContentList, "ContentTitle", SortDirection.Ascending);
            foreach (Wilmerhale.Common.Content content in foldContent.ContentList)
            {
                i += 1;
                // strPartice.Append("" + content.ContentTitle + "");

                strPartice.Append("**");
                strPartice.Append(content.ContentTitle);
                strPartice.Append("**");
                strPartice.Append(" ");
                // strPartice.Append(" ");
                // strPartice.Append("");


                strPractice.Append(content.ContentTitle); //I need toleftindent this content,
                strPractice.Append("");
                strPractice.Append(" ");

                if (folderContent.FolderList != null)
                {
                    FolderContent fcon = folderContent.FolderList.Find(delegate (FolderContent fContent) { return fContent.FolderID == content.ChildFolderID; });

                    if (fcon != null)
                        GetContentHtml(fcon, ref strPractice, x + 1);

                }
            }
            return "";
        }

    }

v

I am using a documentbuilder object see the sample below.I need to left indent a content marked in the yellow section in the black background . Can you tell me how can i achieve this…I am using lot of merrge fields and all the merge fields are using the same documentbuilder object. I just need to indent the content marked as yellow.

string practices = GetPracticeHtml(folderList);
documentBuilder.MoveToMergeField("BioPractices");
documentBuilder.InsertHtml(string.Format("{0}", practices));

private string GetPracticeHtml(List FolderContentList)
{
    StringBuilder strPartice = new StringBuilder();
    int i = 0;
    if (FolderContentList != null && FolderContentList.Count > 0)
    {
        strPartice.Append("Practice Area");
        foreach (FolderContent foldContent in FolderContentList)
        {
            EktronHelper.SortList(foldContent.ContentList, "ContentTitle", SortDirection.Ascending);
            foreach (Wilmerhale.Common.Content content in foldContent.ContentList)
            {
                i += 1;
                // strPartice.Append("" + content.ContentTitle + "");

                strPartice.Append("**");
                strPartice.Append(content.ContentTitle);
                strPartice.Append("**");
                strPartice.Append("");
                // strPartice.Append("");
                // strPartice.Append("");


                strPractice.Append(content.ContentTitle); //I need toleftindent this content,
                strPractice.Append("");
                strPractice.Append("");

                if (folderContent.FolderList != null)
                {
                    FolderContent fcon = folderContent.FolderList.Find(delegate (FolderContent fContent) { return fContent.FolderID == content.ChildFolderID; });

                    if (fcon != null)
                        GetContentHtml(fcon, ref strPractice, x + 1);

                }
            }
            return "";
        }
    }
}

can it be indented i havenot heard the answer

Hi,

Thanks for your inquiry and sorry for the delayed response. Please use the following HTML code to be able to left indent the text in a Word document:

Need to left indent this content

Best Regards,

I need to left align
tag in aspose document. how can we achieve this.Is there any way to achieve this.See the sample below.In the sample, you will see that there are square bullets in
tag. in the yellow section,how can we apply left align or apply margin left in ul tag in aspose.I need it urgently.See below the sample code which i am using to generate square bullets.I need to append styling in it to align it to left

oldediBody = oldediBody.Replace(" ", "");

The 2007 Compensation & Entrepreneurship Report in Information Technology and the 2007 Compensation & Entrepreneurship Report in Life Sciences have been released. The reports—co-sponsored by Ernst & Young LLP Strategic Growth Markets Practice, J. Robert Scott Executive Search and WilmerHale—collect data on the top executive positions in privately held, primarily venture-backed companies and presents a correlation between executive compensation and a number of other variables including financing stage, company size in terms of revenue and headcount, founder/non-founder status, industry segment, product stage and geography.
These studies are valuable tools in helping businesses and executives understand today’s ever-changing compensation trends for senior executives within private technology companies in the software, communications, hardware/ semiconductors/electronics, IT services/consulting/system integration, and content/ information providers market segments, as well as privately-held therapeutic, diagnostic, medical device, instrumentation and platform companies.
Key findings for the IT sector in this year’s survey include:

  • Executive Compensation: Average base salaries rose by 4.6% across the executive positions surveyed from 2006 to 2007, and executives earned approximately two-thirds of their target bonus in 2006.
  • Equity Holdings: Average equity holdings for CEOs were 5.7% of total fully diluted equity. The combined average equity holdings for the CEO, CFO, CTO, head of engineering, head of sales and head of marketing was 11.82%, up from 10.86% in 2006.
  • Recruiting and Retention: As companies evolve from the early stage, with one or fewer rounds of funding, to becoming more mature companies with four or more rounds of funding, the number of Founders remaining in the CEO position declines dramatically from two-thirds to one-third.
  • Severance Packages: Approximately two-thirds of non-founding CEOs have some form of a severance package. Of those with severance packages, the average severance period is seven months, up from six months in last year’s survey. Approximately 25-30% of the remaining team has a severance package.
  • Board Compensation: Very few private companies offer cash grants to board members. Typically, board members are granted between 0.25-0.5% of fully diluted equity to join the board. Very few outside board members of private companies receive cash compensation.

Hi,

Thanks for your inquiry. Specifying ‘text-align: right’ in style of
tag is not supported yet. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-6997. Your request has been linked to this issue and you will be notified as soon as it is supported. Sorry for the inconvenience.

Moreover, you can use the following HTML markup code to right align your lists in Word document.

  • bullet 1
  • bullet 2
  • bullet 3

Best Regards,

But the issue is that the list is slightly indented towards right…I need to align the list with Title which begins with “Key findings” .see below sample.How can we apply styling for that.

  • bullet 1
  • It doesnot work it just aligns the text left not the list. **Key findings for the IT sector in this year’s survey include:**
    • Executive Compensation: Average base salaries rose by 4.6% across the executive positions surveyed from 2006 to 2007, and executives earned approximately two-thirds of their target bonus in 2006.
    • Equity Holdings: Average equity holdings for CEOs were 5.7% of total fully diluted equity. The combined average equity holdings for the CEO, CFO, CTO, head of engineering, head of sales and head of marketing was 11.82%, up from 10.86% in 2006.
    • Recruiting and Retention: As companies evolve from the early stage, with one or fewer rounds of funding, to becoming more mature companies with four or more rounds of funding, the number of Founders remaining in the CEO position declines dramatically from two-thirds to one-third.
    • Severance Packages: Approximately two-thirds of non-founding CEOs have some form of a severance package. Of those with severance packages, the average severance period is seven months, up from six months in last year’s survey. Approximately 25-30% of the remaining team has a severance package.
    • Board Compensation: Very few private companies offer cash grants to board members. Typically, board members are granted between 0.25-0.5% of fully diluted equity to join the board. Very few outside board members of private companies receive cash compensation.

    Hi,

    Thanks for your inquiry. There are commands “Increase Indent” and “Decrease Indent” in MS Word. I am afraid, there is no analog of these commands in Aspose.Words. So, you should use ListLevel.NumberPosition, ListLevel.TabPosition and ListLevel.TextPosition.

    Best Regards,

    *awais.hafeez:
    Hi,

    Thanks for your inquiry. There are commands “Increase Indent” and “Decrease Indent” in MS Word. I am afraid, there is no analog of these commands in Aspose.Words. So, you should use ListLevel.NumberPosition, ListLevel.TabPosition and ListLevel.TextPosition.
    can you provide me some sample how can use this to indent li in my document
    Best Regards,*

    Is there any way that we can find out when the single document contains 2 or more pages…using aspose for words I am using document builder object.I have a function that need to be called recursively depending on the number pages single document can contain…For eg if a single document contains 3 pages it needs to be called 3 times, 2 pages 2 times …in c#

    Hi,

    Thanks for your inquiry. Sure, here is the sample code:

    Document doc = new Document();
    // Create a list based on one of the Microsoft Word list templates.
    Aspose.Words.Lists.List list = doc.Lists.Add(ListTemplate.NumberDefault);
    // Completely customize one list level.
    ListLevel level1 = list.ListLevels[0];
    level1.Font.Color = Color.Red;
    level1.Font.Size = 24;
    level1.NumberStyle = NumberStyle.OrdinalText;
    level1.StartAt = 21;
    level1.NumberFormat = "\x0000";
    level1.NumberPosition = -36;
    level1.TextPosition = 144;
    level1.TabPosition = 144;
    // Completely customize yet another list level.
    ListLevel level2 = list.ListLevels[1];
    level2.Alignment = ListLevelAlignment.Right;
    level2.NumberStyle = NumberStyle.Bullet;
    level2.Font.Name = "Wingdings";
    level2.Font.Color = Color.Blue;
    level2.Font.Size = 24;
    level2.NumberFormat = "\xf0af"; // A bullet that looks like some sort of a star.
    level2.TrailingCharacter = ListTrailingCharacter.Space;
    level2.NumberPosition = 144;
    // Now add some text that uses the list that we created. 
    // It does not matter when to customize the list - before or after adding the paragraphs.
    DocumentBuilder builder = new DocumentBuilder(doc);
    builder.ListFormat.List = list;
    builder.Writeln("The quick brown fox...");
    builder.Writeln("The quick brown fox...");
    builder.ListFormat.ListIndent();
    builder.Writeln("jumped over the lazy dog.");
    builder.Writeln("jumped over the lazy dog.");
    builder.ListFormat.ListOutdent();
    builder.Writeln("The quick brown fox...");
    builder.ListFormat.RemoveNumbers();
    builder.Document.Save(@"C:\Temp\Lists.CreateCustomList Out.doc");
    

    Secondly, you can get the number of pages in the document by using Document.PageCount property.

    Best Regards,

    Hi, We are currently running into some issues while generating word document from aspose. We need the document to have left side bar to be of different color. But only the first page of single document is containing different color and all other subsequent pages are of different color. See the code we are using below.See the red lines where we are calling the function and the function definition.Document is generating the right color. But if a single document containns 2 or more pages. only the first page is showing the color. Other pages are coming without any leftsidebar as well as no color. We need to solve this issue urgently. Can we have a call to discuss this in detail. The client is wilmerhale.They have bought the aspose license.Any help on this would be really appreciated.

    protected void PracticeDocGeneration(List pracContent, List contids) // JGS modified to accept two params
    {
        // Document Title
        string DocumentTitle = "Practice_" + System.Guid.NewGuid().ToString().Substring(0, 4) + "_" + (Request.Form["TitleField"] == "" ? "Title" : Request.Form["TitleField"]) + ".docx";
        // Get Asset template location.
        string assetpath = GetTemplateLocation("Practice");
    
        // Declaring main document ASPOSE object.
        Document MainDoc = new Document();
    
        Service objService = new Service();
        PgSquareBanner.Sqaurebanner objSquareBanner = new PgSquareBanner.Sqaurebanner();
        Office objOffice = new Office();
        AlternateContent objaltcontent = new AlternateContent();
        CurrentDevelopment objCurrentDevlopment = new CurrentDevelopment();
        string Title = string.Empty;
        string Img = string.Empty;
        string BodyDescription = string.Empty;
        int itemCount = 0;
    
        if (pracContent.Count > 0) // JGS modified to check content data list not empty
        {
            foreach (ContentData contentData in pracContent) // JGS modified to loop content data
            {
                // ContentData contentData = contentManager.GetItem(uid); // JGS removed unnecessary code
    
                if (contentData != null)
                {
                    long PracticeSmartformId = contentData.XmlConfiguration.Id;
                    XDocument personal = XDocument.Parse(contentData.Html.ToString());
                    if (personal != null)
                    {
                        switch (PracticeSmartformId)
                        {
                            // Practice Or Industries(48924) - Service Smartform
                            case 7:
                                objService = GetObject(contentData.Html, false);
                                ContentData cd = new ContentData();
                                ContentManager cm = new ContentManager();
                                cd = cm.GetItem(contentData.Id, true);
                                string foldername = cd.FolderName;
                                if (!string.IsNullOrEmpty(foldername))
                                {
                                    Title = foldername + " " + "-" + " ";
                                }
    
                                Title += objService.TxtName;
    
                                if (objService.ServiceImage != null)
                                {
                                    if (objService.ServiceImage.img != null)
                                    {
                                        Img = objService.ServiceImage.img.src;
                                    }
                                }
                                if (objService.Description.Any != null)
                                {
                                    BodyDescription = EktronHelper.GetRichTextOuterXML(objService.Description);
                                    if (BodyDescription.Contains(""))
                                    {
                                        BodyDescription = BodyDescription.Replace("", "");
                                    }
                                }
    
                                break;
                            // Firm Information Or About - 8536 - CommonBannerwithHeading Smartform
                            case 28:
                                objSquareBanner = GetObject<PgSquareBanner.Sqaurebanner>(contentData.Html, false);
    
                                Title = objSquareBanner.Heading;
    
                                if (objSquareBanner.Image != null)
                                {
                                    if (objSquareBanner.Image.img != null)
                                    {
                                        Img = objSquareBanner.Image.img.src;
                                    }
                                }
    
                                if (objSquareBanner.Description.Any != null)
                                {
                                    BodyDescription = GetRichTextOuterXML(objSquareBanner.Description);
                                    if (BodyDescription.Contains(""))
                                    {
                                        BodyDescription = BodyDescription.Replace("", "");
                                    }
                                }
                                break;
                            // Office - Office Smartform
                            case 10:
                                objOffice = GetObject(contentData.Html, false);
    
                                Title = objOffice.Name;
                                if (objOffice.OfficePhoto != null)
                                {
                                    if (objOffice.OfficePhoto.img != null)
                                    {
                                        Img = objOffice.OfficePhoto.img.src;
                                    }
                                }
    
                                if (objOffice.Description.Any != null)
                                {
                                    BodyDescription = EktronHelper.GetRichTextOuterXML(objOffice.Description);
                                    if (BodyDescription.Contains(""))
                                    {
                                        BodyDescription = BodyDescription.Replace("", "");
                                    }
                                }
                                break;
                            case 24:
                                objCurrentDevlopment = GetObject(contentData.Html, false);
    
                                if (objCurrentDevlopment.TxtName.Any != null)
                                {
                                    Title = EktronHelper.GetRichTextOuterXML(objCurrentDevlopment.TxtName);
                                }
    
                                if (objCurrentDevlopment.ServiceImage != null)
                                {
                                    if (objCurrentDevlopment.ServiceImage.img != null)
                                    {
                                        Img = objCurrentDevlopment.ServiceImage.img.src;
                                    }
                                }
                                if (objCurrentDevlopment.Description.Any != null)
                                {
                                    BodyDescription = EktronHelper.GetRichTextOuterXML(objCurrentDevlopment.Description);
                                    if (BodyDescription.Contains(""))
                                    {
                                        BodyDescription = BodyDescription.Replace("", "");
                                    }
                                }
                                break;
                            case 37:
                                objaltcontent = GetObject(contentData.Html, false);
    
                                if (!string.IsNullOrEmpty(objaltcontent.Title))
                                {
                                    Title = objaltcontent.Title;
                                }
    
                                if (objaltcontent.Description.Any != null)
                                {
                                    BodyDescription = EktronHelper.GetRichTextOuterXML(objaltcontent.Description);
                                    if (BodyDescription.Contains(""))
                                    {
                                        BodyDescription = BodyDescription.Replace("", "");
                                    }
    
                                }
                                Img = null;
                                break;
    
                        }
    
                        try
                        {
                            Document DynamictDoc = new Document(assetpath);
    
                            // Creating two biography documents and merging into one final document.
                            // Open the template document with merge fields.
                            DocumentBuilder documentBuilder = new DocumentBuilder(DynamictDoc);
    
                            #region Service Image
    
                            string Practiceimg = string.Empty;
                            string strtitle = Request.Form["TitleField"].ToString();
                            if (!string.IsNullOrEmpty(strtitle) && strtitle.ToLower() != "Title".ToLower())
                            {
                                // documentBuilder.MoveToMergeField(Request.Form["TitleField"].ToString());
                                documentBuilder.MoveToMergeField("PracticeTitleHeading");
                                documentBuilder.InsertHtml(string.Format("{0}", strtitle));
                            }
    
                            // Added by Edynamics-Gaurav
                            if (!string.IsNullOrEmpty(Img))
                            {
                                if (Img.Contains("?"))
                                {
                                    Practiceimg = Server.MapPath(Img.Split(’?’)[0]);
                                }
                                else
                                {
                                    Practiceimg = Server.MapPath(Img);
                                }
                                if (Practiceimg != null)
                                {
    
                                    string imageExtension = Path.GetExtension(Practiceimg);
                                    Bitmap bmp = new Bitmap(Practiceimg);
                                    bmp = MakeGrayscale(bmp);
                                    // Bitmap b = new Bitmap(HttpContext.Current.Server.MapPath("~" + Practiceimg));
                                    string imageName = Guid.NewGuid().ToString() + imageExtension;
                                    bmp.Save(HttpContext.Current.Server.MapPath("~/PGImages/" + imageName));
                                    Practiceimg = Server.MapPath("~/PGImages/" + imageName);
                                }
    
                            }
                            else
                            {
                                Practiceimg = Server.MapPath(Img);
                            }
    
                            if (!string.IsNullOrEmpty(Practiceimg))
                            {
                                // check if image exist before inserting
                                if (File.Exists(Practiceimg))
                                {
                                    documentBuilder.InsertImage(Practiceimg, 85, 85);
                                    System.IO.File.Delete(Practiceimg);
                                }
    
                            }
    
                            #endregion
                            if (long.Parse(hdnTemplateID.Value) == PRAC_TEMPLATE_ID_US_HEADER || long.Parse(hdnTemplateID.Value) == PRAC_TEMPLATE_ID_US_A4_HEADER)
                            {
                                SetSideBar(ref DynamictDoc, ref documentBuilder, contentData.FolderId);
                            }
    
                            documentBuilder.MoveToMergeField("SerName");
                            if (!string.IsNullOrEmpty(Practiceimg))
                            {
                                documentBuilder.InsertHtml(string.Format("{0}", Title));
                            }
                            else
                            {
                                documentBuilder.InsertHtml(string.Format("{0}", Title));
                            }
    
                            if (!string.IsNullOrEmpty(Title))
                            {
                                string footertext = string.Empty;
                                footertext = Title;
                                int strlength = Title.Length;
                                if (strlength > 60)
                                {
                                    footertext = EktronHelper.Chop(Title, 60);
                                    footertext += "…";
                                }
                                else
                                {
                                    footertext = Title;
                                }
                                documentBuilder.MoveToMergeField("footerTitle");
                                documentBuilder.InsertHtml(string.Format("{0}", footertext.ToUpper()));
                            }
    
                            documentBuilder.MoveToMergeField("SerDescription");
    
                            StringBuilder str = new StringBuilder();
                            XmlDocument doc = new XmlDocument();
                            XmlElement rootNode = doc.CreateElement("root");
                            doc.AppendChild(rootNode);
                            XmlElement root = doc.DocumentElement;
                            if (root != null)
                            {
                                root.InnerXml = BodyDescription;
                                XmlNodeList pNodes = root.SelectNodes("//p");
                                if (pNodes != null && pNodes.Count > 0)
                                {
                                    foreach (XmlNode pNode in pNodes)
                                    {
    
                                        if (!string.IsNullOrEmpty(pNode.InnerText.Trim()))
                                        {
    
                                            str.Append(pNode.OuterXml);
                                        }
                                    }
                                }
                                else
                                {
                                    str.Append(BodyDescription);
                                }
    
                            }
    
                            documentBuilder.InsertHtml(str.ToString());
    
                            // Don’t need merge fields in the document anymore.
                            DynamictDoc.MailMerge.DeleteFields();
    
                            itemCount++;
    
                            if (itemCount < pracContent.Count)
                            {
                                documentBuilder.InsertBreak(BreakType.PageBreak);
                            }
                            if (string.IsNullOrEmpty(MainDoc.ToTxt().Trim()))
                            {
                                MainDoc = DynamictDoc;
                            }
                            else
                            {
                                // Merge two biography contents into one document
                                foreach (Section srcSection in DynamictDoc)
                                {
                                    // Importing a node creates a copy of the original node
                                    Node dstSection = MainDoc.ImportNode(srcSection, true, ImportFormatMode.KeepSourceFormatting);
                                    // Now the new section node can be appended to the destination document.
                                    MainDoc.AppendChild(dstSection);
                                }
                            }
    
                        }
                        catch (Exception ex)
                        {
    
                        }
    
                    }
                }
            }
    
            #region Saving DMS document and updating Proposal content
    
            // Saving the document using bytes stream.
            MemoryStream stream = new MemoryStream();
            MainDoc.Save(stream, SaveFormat.Docx);
    
            // Getting data in to bytes
            long fileLength = stream.Length;
            byte[] fileData = new byte[fileLength];
            fileData = stream.ToArray();
    
            // Adding DMS document and updating dms link in proposal content.
            AddDMSAsset(fileData, DocumentTitle, 221);
    
            #endregion
    
        }
    }
    

    here is the function definition

    private void SetSideBar(ref Document DynamictDoc, ref DocumentBuilder documentBuilder, long FolderId)
    {
    
        // GENERAL - RGB(152, 1, 46) - RED COLOR 
        System.Drawing.Color color = System.Drawing.Color.FromArgb(152, 1, 46);
        string ImageFile = String.Empty;
        System.Drawing.Image img;
    
        double HeaderDistance = documentBuilder.PageSetup.HeaderDistance;
    
        double PageWidth = documentBuilder.PageSetup.PageWidth;
        double RightMargin = documentBuilder.PageSetup.RightMargin;
        double RightBorder = documentBuilder.PageSetup.Borders.Right.LineWidth;
    
        double PageHeight = documentBuilder.PageSetup.PageHeight;
        double TopMargin = documentBuilder.PageSetup.TopMargin;
        double BottomMargin = documentBuilder.PageSetup.BottomMargin;
    
        double TopBorder = documentBuilder.PageSetup.Borders.Top.DistanceFromText;
    
        double Top = -(TopMargin + HeaderDistance + TopBorder + 20);
        double Height = PageHeight + TopMargin + BottomMargin;
    
        double Width = 40;
    
        if (FolderId == 181)
        {
            // Intellectual Property - RGB(229,130,0) - ORANGE
            color = System.Drawing.Color.FromArgb(229, 130, 0);
            ImageFile = Server.MapPath("…/…/images/WHProposalGenerator/IntellectualProperty.png");
        }
        if (FolderId == 182 || FolderId == 640)
        {
            // Litigation/Controversy - RGB(85,37,77) - PURPLE
            color = System.Drawing.Color.FromArgb(85, 37, 77);
            ImageFile = Server.MapPath("…/…/images/WHProposalGenerator/LitigationControversy.png");
        }
        // else if (FolderId == 183 || (FolderId >= 313 && FolderId <= 322))
        else if (FolderId == 183)
        {
            // Regulatory and government affairs - RGB(90,127,146) - LIGHT BLUE 
            color = System.Drawing.Color.FromArgb(90, 127, 146);
            ImageFile = Server.MapPath("…/…/images/WHProposalGenerator/RegulatoryAndGovernmentAffairs.png");
    
        }
        // else if (FolderId == 185 || (FolderId >= 294 && FolderId <= 301))
        else if (FolderId == 185)
        {
            // Transactional - RGB(170,179,0) - GREEN
            color = System.Drawing.Color.FromArgb(170, 179, 0);
            ImageFile = Server.MapPath("…/…/images/WHProposalGenerator/Transactional.png");
    
        }
        else if (FolderId == 184)
        {
            // Securities - RGB(0,87,114) - DARK BLUE
            color = System.Drawing.Color.FromArgb(0, 87, 114);
            ImageFile = Server.MapPath("…/…/images/WHProposalGenerator/Securities.png");
        }
    
        // Create textbox shape and insert it into the document.
        Aspose.Words.Drawing.Shape shape = new Aspose.Words.Drawing.Shape(DynamictDoc, Aspose.Words.Drawing.ShapeType.Rectangle);
    
        double Left = PageWidth - RightMargin - shape.Width + 9;
    
        shape.Height = Height;
        shape.Width = Width;
        shape.FillColor = color;
        shape.Top = Top;
        shape.Left = PageWidth - RightMargin - shape.Width + 9; ;
        shape.BehindText = true;
        shape.Name = "WHColorSideBar";
        shape.DistanceTop = 0;
        shape.StrokeWeight = 0;
    
        documentBuilder.InsertNode(shape);
    
        if (ImageFile != String.Empty)
        {
            img = new Bitmap(ImageFile);
            // Create textbox shape and insert it into the document.
            Aspose.Words.Drawing.Shape shapeImg = new Aspose.Words.Drawing.Shape(DynamictDoc, Aspose.Words.Drawing.ShapeType.Image);
            shapeImg.Height = img.Height;
            shapeImg.Width = img.Width;// 
            shapeImg.FillColor = color;
            shapeImg.Top = -40;
            shapeImg.Left = PageWidth - RightMargin - shape.Width + img.Width + 10;
            shapeImg.BehindText = false;
            shapeImg.ImageData.SetImage(ImageFile);
            shapeImg.DistanceTop = 0;
    
            documentBuilder.InsertNode(shapeImg);
        }
    
    }
    

    I have a function which needs to be called recursively depending on the number of pages a document has.see the function below

    for (int pagecount = 1; pagecount < DynamictDoc.PageCount; pagecount++)
    {
         SetSideBarNew(ref DynamictDoc, ref documentBuilder, contentData.FolderId 
    }
    

    The use of this function is the it is dynamically setting leftside bar in word document on every page. But issue here is this function is overwriting all the previous calls. For eg.
    If the document contains 3 pages, only the 3rd page is showing the left sidebar note the first 2 pages, Similarily if the document contains 4 pages,only the 4th page is showing the leftside bar., not the first 3 pages.
    Can you tell me whats the issue here…

    Hi,

    Thanks for your inquiry. Could you please create your target Word document using MS WORD as to how your final output should be generated like and attach it here for our reference. Also, please attach your input Word document too. I will investigate your scenario further and provide you more information.

    Best Regards,

    Hi,
    See the sample word document that is being attached. If you see the document, you will see that every page is showing the correct sidebar which is dynamically generated from code.
    But if single document contains more than 1 page, just the first page is howing the right color leftsiderbar. This is a criticaly issue for us. I need to know can aspose also give support on call.
    Client is Wilmerhale.

    Hi,

    Thanks for your inquiry. What I understand, you have two kinds of side bars i.e. one to be used in first page and the other is for the remaining pages in a Section. I think, the best place for your sidebar images is in the HeaderFirst and HeaderPrimary type headers in a particular Section. For this configuration to work correctly, please set PageSetup.DifferentFirstPageHeaderFooter property to true.

    Best Regards,

    where do we have to set these values

    Hi,

    I have attached sample Word document and the output document i.e. produced by using the following code snippet here for your reference. In the out.docx, you can see that the sidebar image has different color as compared to the colors sidebars on other pages have:

    Document doc = new Document(@"C:\Temp\Sample.docx");
    Section sect = doc.FirstSection;
    sect.PageSetup.DifferentFirstPageHeaderFooter = true;
    Shape firstShape = GetShape(doc, Color.Navy);
    Shape otherShape = GetShape(doc, Color.Red);
    Paragraph firstShapePara = new Paragraph(doc);
    firstShapePara.AppendChild(firstShape);
    InsertShapeIntoHeader(firstShapePara, sect, HeaderFooterType.HeaderFirst);
    Paragraph otherShapePara = new Paragraph(doc);
    otherShapePara.AppendChild(otherShape);
    InsertShapeIntoHeader(otherShapePara, sect, HeaderFooterType.HeaderPrimary);
    doc.Save(@"C:\Temp\out.docx");
    
    private static Shape GetShape(Document doc, Color col)
    {
        Shape shape = new Shape(doc, ShapeType.Rectangle);
        shape.Width = 72;
        shape.Height = doc.FirstSection.PageSetup.PageHeight;
        shape.Fill.Color = col;
        shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
        shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
        shape.WrapType = WrapType.None;
        shape.VerticalAlignment = VerticalAlignment.Center;
        shape.HorizontalAlignment = HorizontalAlignment.Right;
        return shape;
    }
    private static void InsertShapeIntoHeader(Paragraph shapePara, Section sect, HeaderFooterType headerType)
    {
        HeaderFooter header = sect.HeadersFooters[headerType];
        if (header == null)
        {
            header = new HeaderFooter(sect.Document, headerType);
            sect.HeadersFooters.Add(header);
        }
        header.AppendChild(shapePara.Clone(true));
    }
    

    I hope, this helps.

    Best Regards,