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 22, 2016 9:38 am

Indeed I had not this line but when I added it, it didn't change the problem.

In the pdf, the beginning of the second document of the loop is sticked to the end of the previous one whereas in the Word it starts on the next page.

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

Tue Feb 23, 2016 2:55 am

Hi,

The output pdf file I got on my side started on the next page, this is my output pdf: http://www.e-iceblue.com/downloads/temp/6802output.zip.
I used the following code and Spire.Doc Pack(hot fix) Version:5.6.27 for .NET4.0 dlls.
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

Tue Feb 23, 2016 8:32 am

I reviewed my code and I do the exact same thing with the 5.6.27 version.
On the contrary I use the .NET3.5 dlls...

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

Tue Feb 23, 2016 8:52 am

Hi,

Thanks for your response.
.NET3.5 dlls also was fine in pdf on my side. Please try to run my testing project on your side to check if it is ok in pdf.
http://www.e-iceblue.com/downloads/temp ... 2.13.1.zip

Best Regards,
Amy
E-iceblue support team
User avatar

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

Thu Feb 25, 2016 8:31 am

Hi,

How did my project work?
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

Tue Mar 01, 2016 8:13 am

Sorry, I didn't have time to look at it.
I will try during this week.

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

Tue Mar 01, 2016 2:28 pm

I succeeded to reproduce what I told you with your project by adding the code below (do it before importing the doc in the finalDoc) :
Code: Select all
// No Break
doc.LastSection.BreakCode = SectionBreakType.NoBreak;

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

Wed Mar 02, 2016 5:55 am

Hi,

Thanks for your reply.
It did have the issue adding this line doc.LastSection.BreakCode = SectionBreakType.NoBreak, sorry for the inconvenience.
I have forwarded it to our dev team. We will inform you when it is resolved.

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