Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Mon Feb 01, 2016 10:17 am

Hi,

I tested the 5.6.16 version of spire.doc.
There are some optimization on the generation but I still have problems with the rendered content.

This is more or less what I do:
Code: Select all
Document finalDoc = new Document();
for (int i = 0; i < 10; i++)
            {
              Document doc = new Document();
              doc.LoadFromFile("template_spire.docx");     

              '''' Sorry it's in VB
              For Each s As Section In doc.Sections
                    t = New Table(doc)
                    r = t.AddRow()
                    c = r.AddCell()
                   
                    t.TableFormat.LayoutType = LayoutType.Fixed
                    t.PreferredWidth = New PreferredWidth(WidthType.Percentage, 100)
           
                    While s.Body.ChildObjects.Count > 0
                        Dim obj As DocumentObject = s.Body.ChildObjects(0)                                   

                        c.ChildObjects.Add(obj)
                    End While
                   
                    For Each p As Paragraph In c.Paragraphs
                        p.Format.KeepFollow = True
                    Next

                    s.Tables.Add(t)
                Next             
                '''' End of VB section

              finalDoc.ImportContent(doc, false);
            }
finalDoc.SaveToFile(outputPDF,FileFormat.PDF);
finalDoc.Dispose();


The final documents are different and not exactly as it is in the template.
The template and the generated documents are available here: https://www.wetransfer.com/downloads/166e1cdcc82a81fec282a98623b95b8b20160201101244/d7a085bd50987cfc7aa9603b0f169fc120160201101244/a86666

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Tue Feb 02, 2016 5:45 am

Hi,

Thanks for your posting.
I have reproduced the differences(output word document has one difference,output pdf document has five differences) in result files. The differences have been forwarded to our dev team. We will tell you when they are fixed.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Wed Feb 03, 2016 8:44 am

Hi,

I got an update on the difference of output word document. Your template content includes page-breaks, but table does not support page-break, so page beak before "Text" content showed as below lost and "Text" content is covered with previous element.
issue1.png

I share a solution by adding new table to resolve "Text" content missing issue.
Code: Select all
  Document finalDoc = new Document();
            for (int i = 0; i < 10; i++)
            {
                Document doc = new Document();
                doc.LoadFromFile("..\\..\\Input\\6802\\template_spire.docx");
                foreach (Section s in doc.Sections)
                {
                    Table t = new Table(doc);
                    TableRow r = t.AddRow();
                    TableCell c = r.AddCell();

                    t.TableFormat.LayoutType = LayoutType.Fixed;
                    t.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
                    int breakCount = 0;
                    while (s.Body.ChildObjects.Count - breakCount > 0)
                    {
                        DocumentObject obj = s.Body.ChildObjects[0];
                        if (obj is Paragraph)
                        {
                            Paragraph paraChild = obj as Paragraph;
                            Paragraph para = obj.Clone() as Paragraph;
                            paraChild.ChildObjects.Clear();

                            int breakIndex = -1;
                            foreach (DocumentObject child in para.ChildObjects)
                            {
                                if (child is Break && (child as Break).BreakType == BreakType.PageBreak)
                                {
                                    breakIndex = para.ChildObjects.IndexOf(child);
                                    if (paraChild.ChildObjects.Count > 0)
                                        c.ChildObjects.Add(obj);

                                    Paragraph breakPara = para.Clone() as Paragraph;
                                    breakPara.ChildObjects.Clear();
                                    breakPara.ChildObjects.Add(child.Clone());

                                    foreach (Paragraph p in c.Paragraphs)
                                    {
                                        p.Format.KeepFollow = true;
                                    }

                                    s.Tables.Add(t.Clone());
                                    breakCount++;
                                    c.ChildObjects.Clear();

                                    s.Body.ChildObjects.Add(breakPara);
                                    breakCount++;
                                    paraChild.ChildObjects.Clear();
                                    s.Body.ChildObjects.RemoveAt(0);
                                }
                                else
                                    paraChild.ChildObjects.Add(child.Clone());
                            }
                            if (breakIndex < 0)
                                c.ChildObjects.Add(obj);
                        }
                        else
                            c.ChildObjects.Add(obj);
                    }

                    foreach (Paragraph p in c.Paragraphs)
                    {
                        p.Format.KeepFollow = true;
                    }

                    s.Tables.Add(t);
                }
                finalDoc.ImportContent(doc, false);
            }
            string outputWord = "result6802.docx";
            string outputPDF = "result6802.pdf";
            finalDoc.SaveToFile(outputWord, FileFormat.Docx2013);
            finalDoc.SaveToFile(outputPDF, FileFormat.PDF);
     


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Feb 15, 2016 4:22 pm

In my case, when I generate I have the separation lines become green whereas in the model the line is yellow...

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Tue Feb 16, 2016 2:37 am

Hi,

The output word document and pdf document on my end don't encounter your issue and the separation lines keep original yellow, attached output word document.
Could you please give us an example for checking the issue? Thank you.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Tue Feb 16, 2016 9:39 am

The output pdf has the yellow lines, but not in the output Word.
And when I open your Word file, lines are green as it is in mine.
I opened it with Word 2013...
Last edited by s.fardilha on Wed Feb 17, 2016 8:19 am, edited 1 time in total.

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Wed Feb 17, 2016 2:41 am

Hi,

Sorry for the issue. Our dev team has fixed it. We will inform you when new version is released.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Thu Feb 18, 2016 3:57 am

Hi,

lines color issue has been resolved. Welcome to download and test Spire.Doc Pack(hot fix) Version:5.6.27.
Full code:
Code: Select all
 Document finalDoc = new Document();
            for (int i = 0; i < 10; i++)
            {
                Document doc = new Document();
                doc.LoadFromFile("..\\..\\template_spire.docx");
                foreach (Section s in doc.Sections)
                {
                    Table t = new Table(doc);
                    TableRow r = t.AddRow();
                    TableCell c = r.AddCell();

                    t.TableFormat.LayoutType = LayoutType.Fixed;
                    t.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
                    int breakCount = 0;
                    while (s.Body.ChildObjects.Count - breakCount > 0)
                    {
                        DocumentObject obj = s.Body.ChildObjects[0];
                        if (obj is Paragraph)
                        {
                            Paragraph paraChild = obj as Paragraph;
                            Paragraph para = obj.Clone() as Paragraph;
                            paraChild.ChildObjects.Clear();

                            int breakIndex = -1;
                            foreach (DocumentObject child in para.ChildObjects)
                            {
                                if (child is Break && (child as Break).BreakType == BreakType.PageBreak)
                                {
                                    breakIndex = para.ChildObjects.IndexOf(child);
                                    if (paraChild.ChildObjects.Count > 0)
                                        c.ChildObjects.Add(obj);

                                    Paragraph breakPara = para.Clone() as Paragraph;
                                    breakPara.ChildObjects.Clear();
                                    breakPara.ChildObjects.Add(child.Clone());

                                    foreach (Paragraph p in c.Paragraphs)

                                    { p.Format.KeepFollow = true; }
                                    s.Tables.Add(t.Clone());
                                    breakCount++;
                                    c.ChildObjects.Clear();

                                    s.Body.ChildObjects.Add(breakPara);
                                    breakCount++;
                                    paraChild.ChildObjects.Clear();
                                    s.Body.ChildObjects.RemoveAt(0);
                                }
                                else
                                    paraChild.ChildObjects.Add(child.Clone());
                            }
                            if (breakIndex < 0)
                                c.ChildObjects.Add(obj);
                        }
                        else
                            c.ChildObjects.Add(obj);
                    }

                    foreach (Paragraph p in c.Paragraphs)

                    {
                        p.Format.KeepFollow = true;
                    }
                    s.Tables.Add(t);
                    s.AddParagraph();
                }
                finalDoc.ImportContent(doc, false);

            }
            finalDoc.SaveToFile("output.docx", FileFormat.Docx2013);
            finalDoc.SaveToFile("output.pdf", FileFormat.PDF);
            finalDoc.Dispose();


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Feb 19, 2016 7:05 am

Hi,

Did new version resolve your issue?
Thanks for your feedback.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Fri Feb 19, 2016 10:12 am

Hi,

This new version is much better.
I still have one little remaining problem in the generated pdf.

As before, I make a final document which is an assembly of several documents but before importing every "doc" in "finalDoc" I do :
Code: Select all
doc.lastSection.BreakCode = SectionBreakType.NoBreak

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Mon Feb 22, 2016 3:48 am

Hi,

Is the little remaining problem that second ''doc" doesn't start new page but followed the first "doc", as shown below?
outputIssue.png


If so, please try enclosed code on my last post informed you new version.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Feb 22, 2016 8:12 am

No, I mean it does what is in your picture only ig I save in pdf.

With your code, it is good when I save in word.

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Mon Feb 22, 2016 8:25 am

Hi,

Sorry that I still don't know your issue. I compared your output word document and pdf document, and only found the difference I mentioned in my last post. To help us know your issue well, please describe it in detail. Thank you.

Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Mon Feb 22, 2016 8:45 am

Yes that's it.

I used your code and the saved word is ok. But in the pdf there is the difference you mentionned which is not correct.

s.fardilha
 
Posts: 35
Joined: Tue Aug 11, 2015 9:20 am

Mon Feb 22, 2016 8:57 am

Hi,

I tried my code again and it was ok in pdf. Please check if your code has this line "s.AddParagraph();" , again attached full code.
Code: Select all
Document finalDoc = new Document();
            for (int i = 0; i < 10; i++)
            {
                Document doc = new Document();
                doc.LoadFromFile("..\\..\\template_spire.docx");
                foreach (Section s in doc.Sections)
                {
                    Table t = new Table(doc);
                    TableRow r = t.AddRow();
                    TableCell c = r.AddCell();

                    t.TableFormat.LayoutType = LayoutType.Fixed;
                    t.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100);
                    int breakCount = 0;
                    while (s.Body.ChildObjects.Count - breakCount > 0)
                    {
                        DocumentObject obj = s.Body.ChildObjects[0];
                        if (obj is Paragraph)
                        {
                            Paragraph paraChild = obj as Paragraph;
                            Paragraph para = obj.Clone() as Paragraph;
                            paraChild.ChildObjects.Clear();

                            int breakIndex = -1;
                            foreach (DocumentObject child in para.ChildObjects)
                            {
                                if (child is Break && (child as Break).BreakType == BreakType.PageBreak)
                                {
                                    breakIndex = para.ChildObjects.IndexOf(child);
                                    if (paraChild.ChildObjects.Count > 0)
                                        c.ChildObjects.Add(obj);

                                    Paragraph breakPara = para.Clone() as Paragraph;
                                    breakPara.ChildObjects.Clear();
                                    breakPara.ChildObjects.Add(child.Clone());

                                    foreach (Paragraph p in c.Paragraphs)

                                    { p.Format.KeepFollow = true; }
                                    s.Tables.Add(t.Clone());
                                    breakCount++;
                                    c.ChildObjects.Clear();

                                    s.Body.ChildObjects.Add(breakPara);
                                    breakCount++;
                                    paraChild.ChildObjects.Clear();
                                    s.Body.ChildObjects.RemoveAt(0);
                                }
                                else
                                    paraChild.ChildObjects.Add(child.Clone());
                            }
                            if (breakIndex < 0)
                                c.ChildObjects.Add(obj);
                        }
                        else
                            c.ChildObjects.Add(obj);
                    }

                    foreach (Paragraph p in c.Paragraphs)

                    {
                        p.Format.KeepFollow = true;
                    }
                    s.Tables.Add(t);
                    s.AddParagraph();
                }
                finalDoc.ImportContent(doc, false);

            }
            finalDoc.SaveToFile("output.docx", FileFormat.Docx2013);
            finalDoc.SaveToFile("output.pdf", FileFormat.PDF);
            finalDoc.Dispose();


Best Regards,
Amy
E-iceblue support team
User avatar

amy.zhao
 
Posts: 2766
Joined: Wed Jun 27, 2012 8:50 am

Return to Spire.Doc