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.

Tue Dec 13, 2016 4:16 am

Found an issue with merging two docx files and then converting to pdf:

When first file contains page header - this header also appears on pages in further merged documents. But it should not.

Sample files attached. If some workaround possible before hotfix - let me know please.
Last edited by osa_ua on Wed Dec 14, 2016 3:08 am, edited 1 time in total.

osa_ua
 
Posts: 8
Joined: Mon Nov 21, 2016 2:32 am

Tue Dec 13, 2016 6:51 am

Dear Oleg,

Thanks for your inquiry.
In this case, you need to set the header in new section is not same as previous section, here is sample code for your reference.
Code: Select all
            Document OriginalDoc1 = new Document();
            OriginalDoc1.LoadFromFile(@"F:\testing\doc form\original document\test_page_headers2.docx");
            Document TargetDoc = new Document();
            TargetDoc.LoadFromFile(@"F:\testing\doc form\original document\test_page_headers.docx");
            foreach (Section sec in OriginalDoc1.Sections)
            {
                TargetDoc.Sections.Add(sec.Clone());
            }
            //set the new section header.
            TargetDoc.Sections[1].HeadersFooters.LinkToPrevious = false;
            TargetDoc.SaveToFile("9338.docx", FileFormat.Docx);
            TargetDoc.SaveToFile("9338.pdf",FileFormat.PDF);

I found the result .docx file is correct, but the result PDF document is incorrect. And I have posted this PDF issue to our Dev team, we will inform you as soon as there is any progress.
Sorry for inconvenience caused.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Dec 14, 2016 3:03 am

Tried this workaround. Confirming that it fixes merge only if save as docx. If save as PDF - issue still exists. Will be waiting for hotfix. Thanks.

osa_ua
 
Posts: 8
Joined: Mon Nov 21, 2016 2:32 am

Wed Dec 21, 2016 6:21 am

Dear Oleg,

Thanks for your waiting.
Now the issue has been fixed in Spire.Doc Pack(hot fix) Version:5.8.33. Welcome to test it.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Thu Dec 22, 2016 3:45 am

Betsy,

I've tried 5.8.33, however merged pdf still have page header ("This is ODD page header") on page from second document. See attachment.

Thanks, Oleg

osa_ua
 
Posts: 8
Joined: Mon Nov 21, 2016 2:32 am

Thu Dec 22, 2016 3:54 am

Dear Oleg,

Thanks for your feedback.
But I have tested the files with the code I provided before and didn't notice the issue, please check the attachment.
Please make sure you were using Spire.Doc V5.8.33(Spire.doc.dll V5.8.33). Is the code you were using same as my code ?

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Wed Dec 28, 2016 8:00 am

Betsy,

I am using the following code (VB.NET):

Code: Select all
        Dim sdoc As New Spire.Doc.Document
        sdoc.LoadFromFile("test_page_headers.docx")

        Dim sdoc2 As New Spire.Doc.Document
        sdoc2.LoadFromFile("test_page_headers2.docx")

        For Each sec As Spire.Doc.Section In sdoc2.Sections
            Dim section = sec.Clone()
            section.HeadersFooters.LinkToPrevious = False
            sdoc.Sections.Add(section)
        Next sec

        sdoc.SaveToFile("result.pdf", Spire.Doc.FileFormat.PDF)


and still got "This is ODD page header" header on 3rd page. See attachment with result file.
Using NuGet version of Spire.Doc 5.8.33

Thanks, Oleg

osa_ua
 
Posts: 8
Joined: Mon Nov 21, 2016 2:32 am

Wed Dec 28, 2016 8:19 am

Betsy,

looks like I found workaround.
If I change my code and move line
Code: Select all
section.HeadersFooters.LinkToPrevious = False
from the loop and apply it only for first section - it works.
But if I merge, say, 10 documents - this works only for second merged document.

Therefore when merging multiple documents into single pdf
workaround is to apply
Code: Select all
section.HeadersFooters.LinkToPrevious = False
ONLY to the first section of each merged document.

Final code for multiple documents will be something like this:

Code: Select all
        Dim sdoc As New Spire.Doc.Document
        sdoc.LoadFromFile("test_page_headers.docx")

        For Each file As String In files
            Dim sdoc2 As New Spire.Doc.Document
            sdoc2.LoadFromFile(file)

            Dim is_first_section = True
            For Each sec As Spire.Doc.Section In sdoc2.Sections
                Dim section = sec.Clone()
                sdoc.Sections.Add(section)

                'also important note - the following code MUST be after sdoc.Sections.Add as for some reason if it's before - issue still be reproduced
                If is_first_section Then
                    section.HeadersFooters.LinkToPrevious = False 'fix headers/footers
                    is_first_section = False
                End If
            Next sec
        Next

        sdoc.SaveToFile("result.pdf", Spire.Doc.FileFormat.PDF)


Thanks, Oleg

osa_ua
 
Posts: 8
Joined: Mon Nov 21, 2016 2:32 am

Wed Dec 28, 2016 8:31 am

Dear Oleg,

Gald to hear that you found workaround.
If there is any question, welcome to get it back to us.

Sincerely,
Betsy
E-iceblue support team
User avatar

Betsy.jiang
 
Posts: 3099
Joined: Tue Sep 06, 2016 8:30 am

Return to Spire.Doc