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 Aug 10, 2021 2:45 pm

Hi

My scenario is that specific document headers and footers must be applied to documents stored in SharePoint.
Header and footers are defined in a template document. The process is as follow:

    - loading the template document which contains the header and footer to be applied to processed documents
    - loading the documents from SharePoint which should have the header and footer applied
    - applying the loaded header and footer to the documents
    - storing the modified documents back to SharePoint.

this works great by using the Spire.Doc Nuget - it's stable and easy to read code.
But the processed documents are getting larger and larger as I begin to repeat the mentioned process a couple of times.
I realized that if I open a processed document in Microsoft Word and use the "Inspect document" tool inside Word in order to remove the Custom XML Data parts, the document gets its initial file size back. But then, If I replace the already existing header and footer again by repeating the above process again, the document gets larger again and afterwards contains Custom XML Data again, which I can remove again to get the initial file size back.

Is this a known issue in combination with SharePoint as the storage location? I am afraid that this has something to do with the Office integration of SharePoint. Maybe I'm doing something totally wrong?

My code is below:

Code: Select all
public class WordDocument: IDocument
    {
        private Document doc;
        public WordDocument(Stream srcDocument)
        {
            this.doc = new Document();
            doc.LoadFromStream(srcDocument, FileFormat.Auto);
        }

        public void ReplaceHeader(Stream headerTemplateStream, IDictionary<string, string> replacementsList)
        {
            var headerTemplateDoc = LoadDocument(headerTemplateStream, replacementsList);
            var templateHeader = headerTemplateDoc.Sections[0].HeadersFooters.Header;
            var docHeader = doc.Sections[0].HeadersFooters.Header;
            ReplaceHeaderFooter(templateHeader, docHeader);
        }

        public void ReplaceFooter(Stream footerTemplateStream, IDictionary<string, string> replacementsList)
        {
            var footerTemplateDoc = LoadDocument(footerTemplateStream, replacementsList);
            var templateFooter = footerTemplateDoc.Sections[0].HeadersFooters.Footer;
            var docFooter = doc.Sections[0].HeadersFooters.Footer;
            ReplaceHeaderFooter(templateFooter, docFooter);
        }

        private static void ReplaceHeaderFooter(HeaderFooter template, HeaderFooter doc)
        {
            doc.EnsureMinimum();
            doc.Paragraphs.Clear();

            foreach (DocumentObject o in template.ChildObjects)
            {
                doc.ChildObjects.Add(o.Clone());
            }
        }

        private static Document LoadDocument(Stream docStream, IDictionary<string, string> replacementsList)
        {
            var doc = new Document();
            doc.LoadFromStream(docStream, FileFormat.Auto);
            foreach (var replacement in replacementsList)
            {
                doc.Replace(replacement.Key, replacement.Value, true, false);
            }
            return doc;
        }

        public byte[] ToByteArray(string targetFileName)
        {
            var fileExtension = targetFileName.Substring(targetFileName.LastIndexOf(".") + 1).ToLower();
            var fileFormat = fileExtension == "pdf" ? FileFormat.PDF : doc.DetectedFormatType;
            byte[] filebytes = null;
            using (var stream = new MemoryStream())
            {
                doc.SaveToStream(stream, fileFormat);
                filebytes = stream.ToArray();
            }
            return filebytes;
        }

        public void Dispose()
        {
            this.doc.Dispose();
        }

lukasjung
 
Posts: 6
Joined: Tue Aug 10, 2021 2:23 pm

Wed Aug 11, 2021 12:06 pm

Hello,

Thanks for your inquiry.

I did some tests and did notice that it will add Custom XML Data to the output file after each replacement. I have posted it to our Dev team for further investigation. If there is any update, we will let you know.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Mon Aug 23, 2021 11:13 am

Any update on this issue?
A fix or a work around is critical for us - it decides whether we can use Spire.Doc or not. And as a result, whether we will buy the license or not...
Thanks,
Lukas

lukasjung
 
Posts: 6
Joined: Tue Aug 10, 2021 2:23 pm

Tue Aug 24, 2021 2:09 am

Hello Lukas,

Thanks for your follow up.
I just checked the status of your issue and found it has been resolved. Our Test team is now testing the hotfix. Once it passes the test, we will prepare a fixed version for you. Thanks for your patience.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Tue Aug 31, 2021 1:39 pm

Wow, glad to read that it has been resolved! Looking forward to getting a fixed version!
Excellent service until here, thank you very much!

lukasjung
 
Posts: 6
Joined: Tue Aug 10, 2021 2:23 pm

Fri Sep 03, 2021 2:06 pm

Hi Brian

Did you already get a sign from your testing / dev team when the updated version will be available? And how will it be available? Hope you will push a new version of the Nuget package...

Thanks and have a great weekend.
Lukas

lukasjung
 
Posts: 6
Joined: Tue Aug 10, 2021 2:23 pm

Mon Sep 06, 2021 1:15 am

Hello Lukas,

Thanks for your follow up.

I just got news from our Test team that the fix has some impacts on other cases, it failed to pass the test. Now our Dev team are working on these impacts. We are very sorry for the inconvenience caused.
Anyway, I will keep you informed if it is resolved.

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Wed Sep 22, 2021 5:49 am

Sorry, me again. Do you have any updates on when the fix might be available?
Lukas

lukasjung
 
Posts: 6
Joined: Tue Aug 10, 2021 2:23 pm

Wed Sep 22, 2021 7:42 am

Hello Lukas,

Thanks for your follow up.
Our Dev team has fixed your issue. And considering your urgent situation, we first compiled a temporary version for you. Please download it for testing. Looking forward to your test results.
https://www.e-iceblue.com/downloads/Tem ... _9.9.5.zip

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Sat Oct 09, 2021 10:01 am

Hello,

Greetings from E-icblue!
Glad to inform you that we just released Spire.Doc Pack(hot fix) Version:9.10.0 which fixed your issue, please download it from the following links to test on your side. Looking forward to your test result.
Website link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget link: https://www.nuget.org/packages/Spire.Doc/9.10.0

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Thu Oct 14, 2021 9:14 am

Hello,

Greetings from E-iceblue!
Does the hotfix Spire.Doc Pack(hot fix) Version:9.10.0 solve your issue? Could you please give us some feedback at your convenience?

Sincerely,
Brian
E-iceblue support team
User avatar

Brian.Li
 
Posts: 1271
Joined: Mon Oct 19, 2020 3:04 am

Return to Spire.Doc