Add pages after bookmark navigator

Technical support for Spire.Doc

Moderator: iceblue support

Add pages after bookmark navigator

Postby ahamed » Wed Aug 31, 2011 9:37 am

Hi,
I am stuck with following code. What I am trying to do....

1.I am loading 14pages of qutation template file from
Document document = new Document();
document.LoadFromFile(@"..\Template_structure\Full.doc");

2. some where middle of the page example page number 6. I need to check how many master products they got in the quote builder and add to the word document accordingly.
3. Master products assosiate with sub products .

Ex:
Masterproducts - 1
subproducts -1
subproducts -2
subproducts -3
subproducts -4
page - 6

Masterproducts - 2
subproducts -1
subproducts -2
subproducts -3
subproducts -4
Page 7

may be this will go to pages 6 to 11....etc depends on how many master products they have on the qutaion builder. There are no changes on the other pages on the template.

please find the following code :


Document document = new Document();
document.LoadFromFile(@"\..\Full_template.doc");

BookmarksNavigator nav = new BookmarksNavigator(document);


IPartbuilder ptb = new Partbuilder();
IQuoteBuilder qtb = new QuoteBuilder();

bool checkmasterproduct = qtb.checkanymasterproductexist(quoteid);

if (checkmasterproduct == true)
{
ArrayList arr = new ArrayList();
arr = qtb.getallmasterproductitems(quoteid);
foreach (object I in arr)
{

int productcode = (int)I;
qtb.Getmasterproductname(productcode);

nav.MoveToBookmark("playsimbolimages");


Section section = document.AddSection();
Paragraph paragraph = section.AddParagraph();
paragraph.AppendText(""+ I +"-" + ptb.ProductDescription + "" );
paragraph.ApplyStyle(BuiltinStyle.Heading2);


section.AddParagraph();
paragraph = section.AddParagraph();
paragraph.AppendText(""+ ptb.ProductLongDescription +"");

section = document.AddSection();
section.BreakCode = SectionBreakType.NewPage;

ArrayList arr2 = new ArrayList();
arr2=qtb.GetallProductsformasterproducts(productcode,quoteid);

foreach (object S in arr2)
{
Partbuilder B = (Partbuilder)S;
// ITextRange t4 = nav.InsertText(""+ B.ProductDescription +"<br/>");


}


}
}

document.SaveToFile("Full_Quote-QTE-" + qid + ".doc", FileFormat.Docx,Response,HttpContentType.Attachment);
}
}

Please advice me soon as possible.

Thank you in advance.
ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Re: Add pages after bookmark navigator

Postby harry.support » Thu Sep 01, 2011 7:03 am

Hi,

Thanks for your inquiry.
You could create a new paragraph and append a PageBreak separator to the new paragraph.
Please try:
Code: Select all
nav.MoveToBookmark("playsimbolimages", false, true);
Paragraph newParagraph = new Paragraph(nav.Document);
nav.InsertParagraph(newParagraph);
Body body = newParagraph.OwnerTextBody;
newParagraph.AppendBreak(BreakType.PageBreak);
...
foreach (object S in arr2)
{
    if(newParagraph == null)
    {
        newParagraph = body.AddParagraph();
    }
    Partbuilder B = (Partbuilder)S;
    ITextRange t4 = newParagraph.AppendText(""+ B.ProductDescription);
    newParagraph = null;
}

Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: Add pages after bookmark navigator

Postby ahamed » Thu Sep 01, 2011 4:19 pm

Hi Harry,

Thank you very much for the answer I have managed to do some of the work unfatunatly still I am having some trouble. Please look at the code below

if (checkmasterproduct == true)
{
ArrayList arr = new ArrayList();
arr = qtb.getallmasterproductitems(quoteid);
foreach (object I in arr)
{

int productcode = (int)I;
string prodname = qtb.Getmasterproductname(productcode);
string imgname = ptb.GetProductCodeByID(productcode);

ptb.GetAllProductsItems(productcode);

nav.MoveToBookmark("Certification", false, true);



////////////////////////////////Code///////////////////////////

Paragraph newparagraph = new Paragraph(nav.Document);
nav.InsertParagraph(newparagraph);

ITextRange heading = newparagraph.AppendText("" + prodname + "");
heading.CharacterFormat.FontName = "Verdana";
heading.CharacterFormat.FontSize = 11;
heading.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);
Body body = newparagraph.OwnerTextBody;

newparagraph.AppendPicture(Image.FromFile(@"h:\Websites\Smp_C\Templates\" + ptb.ProductCode + ".jpg"));
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange text = newparagraph.AppendText("" + ptb.ProductLongDescription + "");
text.CharacterFormat.FontName = "verdana";
text.CharacterFormat.FontSize = 10;
text.CharacterFormat.Bold = false;
newparagraph.ApplyStyle(BuiltinStyle.BlockText);
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading2 = newparagraph.AppendText("Play Value");
heading2.CharacterFormat.FontName = "Verdana";
heading2.CharacterFormat.FontSize = 11;
heading2.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendPicture(Image.FromFile(@"h:\Websites\Smp_C\Templates\PlaySymbol.jpg"));
newparagraph.AppendPicture(Image.FromFile(@"h:\Websites\Smp_C\Templates\PlaySymbol.jpg"));
newparagraph.AppendPicture(Image.FromFile(@"h:\Websites\Smp_C\Templates\PlaySymbol.jpg"));
newparagraph.AppendPicture(Image.FromFile(@"h:\Websites\Smp_C\Templates\PlaySymbol.jpg"));
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading3 = newparagraph.AppendText("Cost");
heading3.CharacterFormat.FontName = "Verdana";
heading3.CharacterFormat.FontSize = 11;
heading3.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);

/////////////////////////////Code End//////////////////////////



ArrayList arr2 = new ArrayList();
arr2 = qtb.GetallProductsformasterproducts(productcode, quoteid);

foreach (object S in arr2)
{
Partbuilder B = (Partbuilder)S;

ITextRange text10 = newparagraph.AppendText("" + B.ProductDescription + "- £"+ B.ListPrice + ".00");
text10.CharacterFormat.FontName = "verdana";
text10.CharacterFormat.FontSize = 10;
text10.CharacterFormat.Bold = false;
newparagraph.AppendBreak(BreakType.LineBreak);

}


newparagraph.AppendBreak(BreakType.LineBreak);
ITextRange heading4 = newparagraph.AppendText("Total");
heading4.CharacterFormat.FontName = "Verdana";
heading4.CharacterFormat.FontSize = 11;
heading4.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading5 = newparagraph.AppendText("Carriage Charge");
heading5.CharacterFormat.FontName = "Verdana";
heading5.CharacterFormat.FontSize = 11;
heading5.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading6 = newparagraph.AppendText("Security Fence");
heading6.CharacterFormat.FontName = "Verdana";
heading6.CharacterFormat.FontSize = 11;
heading6.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading7 = newparagraph.AppendText("Welfare Facilities");
heading7.CharacterFormat.FontName = "Verdana";
heading7.CharacterFormat.FontSize = 11;
heading7.CharacterFormat.Bold = true;

newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);

ITextRange heading8 = newparagraph.AppendText("Quotation Total");
heading8.CharacterFormat.FontName = "Verdana";
heading8.CharacterFormat.FontSize = 11;
heading8.CharacterFormat.Bold = true;

newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.PageBreak);
newparagraph = null;
}

Question 1. I woulk like to add a table after Partbuilder B = (Partbuilder)S; and I need to add B.ProductDescription first column, B.ListPrice to the second colum.
Question 2. Is it possible to add more paragraphs like
Paragraph newparagraph2 = new Paragraph(nav.Document);
nav.InsertParagraph(newparagraph2);

Question 3. When I out put the template the text created by code is right align I need to manually press the backspace key to align left.

Please help me with the issue.Thank you for the time.
ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Re: Add pages after bookmark navigator

Postby harry.support » Mon Sep 05, 2011 8:21 am

For #1, please check http://www.e-iceblue.com/Knowledgebase/ ... B.NET.html
#2, yes.
#3, when you insert a new paragraph into a paragraph, the original paragraph will be splitted, and you will get 3 paragraphs. So you may need to reset the style of the 3rd paragraph. please check http://www.e-iceblue.com/Knowledgebase/ ... B.NET.html
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: Add pages after bookmark navigator

Postby ahamed » Tue Sep 06, 2011 5:10 pm

Hi Harry,
Thanks for the reply I really appriciate your help. I have one more question

In my case I need to add a table immeidatly after- Partbuilder B = (Partbuilder)S;

please see the code below its works fine but adding the table end of the document. When I insert
Section section = document.AddSection();
its go to the bottom of the page could you please let me know is there any other way that i can insert a table in newparagraph with out adding a section.



Paragraph newparagraph = new Paragraph(nav.Document);
nav.InsertParagraph(newparagraph);

foreach (object item in items)
{
Partbuilder p = (Partbuilder)item;
ITextRange heading = newparagraph.AppendText("" + p.ProductDescription + "-(" + p.ProductCode + ") Age Range:" + p.AgeRange + "");
heading.CharacterFormat.FontName = "Verdana";
heading.CharacterFormat.FontSize = 11;
heading.CharacterFormat.Bold = true;
newparagraph.AppendBreak(BreakType.LineBreak);
newparagraph.AppendBreak(BreakType.LineBreak);
}

ArrayList arr2 = new ArrayList();
arr2 = qtb.GetallProductsformasterproducts(productcode, quoteid);

foreach (object S in arr2)
{
Partbuilder B = (Partbuilder)S;

ITextRange text10 = newparagraph.AppendText("" + B.ProductDescription + "- £" + B.ListPrice + ".00");
text10.CharacterFormat.FontName = "verdana";
text10.CharacterFormat.FontSize = 10;
text10.CharacterFormat.Bold = false;

//Paragraph newparagraph2 = new Paragraph(nav.Document);
//nav.InsertParagraph(newparagraph2);

//Table contents goes here
Section section = document.AddSection();
String[] header = { "", "" };
String[][] data =
{
new String[]{"" + B.ProductDescription + "", "£"+ B.ListPrice + ".00"}
};
Spire.Doc.Table table = section.AddTable();
table.ResetCells(data.Length + 1, header.Length);

for (int r = 0; r < data.Length; r++)
{
TableRow datarow = table.Rows[r + 1];
datarow.Height = 15;
datarow.HeightType = TableRowHeightType.Exactly;
datarow.RowFormat.BackColor = Color.Empty;

for (int c = 0; c < data[r].Length; c++)
{
datarow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
datarow.Cells[c].AddParagraph().AppendText(data[r][c]);

}
}
}

Thanks again for your support.
ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Re: Add pages after bookmark navigator

Postby harry.support » Wed Sep 07, 2011 8:26 am

Hi,

You don't need to create a new section a create your table within the new section. Please try:
Code: Select all
using System;
using System.Drawing;
using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Interface;

namespace InsertTable
{
    class Program
    {
        static void Main(string[] args)
        {
            Document doc = new Document(@"..\..\Summary_of_Science.doc");
            BookmarksNavigator nav = new BookmarksNavigator(doc);
            nav.MoveToBookmark("Position2", false, true);
            Table table = CreateTable(nav.Document);
            nav.InsertTable(table);

            doc.SaveToFile("test.doc");
            System.Diagnostics.Process.Start("test.doc");
        }

        private static Table CreateTable(IDocument doc)
        {
            String[] header = { "Name", "Capital", "Continent", "Area", "Population" };
            String[][] data =
                {
                    new String[]{"Argentina", "Buenos Aires", "South America", "2777815", "32300003"},
                    new String[]{"Bolivia", "La Paz", "South America", "1098575", "7300000"},
                    new String[]{"Brazil", "Brasilia", "South America", "8511196", "150400000"},
                    new String[]{"Canada", "Ottawa", "North America", "9976147", "26500000"},
                    new String[]{"Chile", "Santiago", "South America", "756943", "13200000"},
                    new String[]{"Colombia", "Bagota", "South America", "1138907", "33000000"},
                    new String[]{"Cuba", "Havana", "North America", "114524", "10600000"},
                    new String[]{"Ecuador", "Quito", "South America", "455502", "10600000"},
                    new String[]{"El Salvador", "San Salvador", "North America", "20865", "5300000"},
                    new String[]{"Guyana", "Georgetown", "South America", "214969", "800000"},
                    new String[]{"Jamaica", "Kingston", "North America", "11424", "2500000"},
                    new String[]{"Mexico", "Mexico City", "North America", "1967180", "88600000"},
                    new String[]{"Nicaragua", "Managua", "North America", "139000", "3900000"},
                    new String[]{"Paraguay", "Asuncion", "South America", "406576", "4660000"},
                    new String[]{"Peru", "Lima", "South America", "1285215", "21600000"},
                    new String[]{"United States of America", "Washington", "North America", "9363130", "249200000"},
                    new String[]{"Uruguay", "Montevideo", "South America", "176140", "3002000"},
                    new String[]{"Venezuela", "Caracas", "South America", "912047", "19700000"}
                };
            Spire.Doc.Table table = new Table(doc);
            table.ResetCells(data.Length + 1, header.Length);

            // ***************** First Row *************************
            TableRow row = table.Rows[0];
            row.IsHeader = true;
            row.Height = 20;    //unit: point, 1point = 0.3528 mm
            row.HeightType = TableRowHeightType.Exactly;
            row.RowFormat.BackColor = Color.Gray;
            for (int i = 0; i < header.Length; i++)
            {
                row.Cells[i].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                Paragraph p = row.Cells[i].AddParagraph();
                p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
                TextRange txtRange = p.AppendText(header[i]);
                txtRange.CharacterFormat.Bold = true;
            }

            for (int r = 0; r < data.Length; r++)
            {
                TableRow dataRow = table.Rows[r + 1];
                dataRow.Height = 20;
                dataRow.HeightType = TableRowHeightType.Exactly;
                dataRow.RowFormat.BackColor = Color.Empty;
                for (int c = 0; c < data[r].Length; c++)
                {
                    dataRow.Cells[c].CellFormat.VerticalAlignment = VerticalAlignment.Middle;
                    dataRow.Cells[c].AddParagraph().AppendText(data[r][c]);
                }
            }

            return table;
        }
    }
}

Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm

Re: Add pages after bookmark navigator

Postby ahamed » Wed Sep 07, 2011 2:00 pm

Thanks for the reply it was really helpfull, how do I right align the text in a cell

String[][] data =
{
new String[]{"" + B.ProductDescription + "", "£"+ B.ListPrice + ".00"}
};


I need to show B.Listprice on right align in the table.

Thank you.
ahamed
 
Posts: 15
Joined: Mon Aug 15, 2011 1:09 pm

Re: Add pages after bookmark navigator

Postby harry.support » Thu Sep 08, 2011 1:51 am

Hi,

You just need to set the align of the paragraph of the cell to right, for example:
Code: Select all
Paragraph p = cell.AddParagraph();
p.Format.HorizontalAlignment = Spire.Doc.Documents.HorizontalAlignment.Center;
Harry
Technical Support / Developer,
e-iceblue Support Team
User avatar
harry.support
 
Posts: 180
Joined: Mon Nov 08, 2010 3:11 pm


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests