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.

Wed Feb 21, 2018 6:36 am

Hi Team,

Am using Spire.Doc (6.1 version) in my application. It is working fine in locally. But, its throwing an error "Generic error occurred in GDI++" in azure only. After I analyzed the code and got to know where is the problem. The problem with UpdateTableOfContents() function. When I remove this line, i can generate the word document in azure but Table of Contenst(Index) is not coming in the document,

Below is my code:
private byte[] WriteToDoc()
{
string filePath = "~/Data/xxx.docx";
LoadFromFile(HttpContext.Current.Server.MapPath(filePath));
DocumentSections.Add(new ScopeHeaderSection(this, DocumentTitle, DocumentAuthor));
DocumentSections.Add(new ScopeTableOfContentSection(this));
using (MemoryStream stream = new MemoryStream())
{
SaveToStream(stream, FileFormat.Docx);
Document finalDoc = new Document();
finalDoc.LoadFromStream(stream, FileFormat.Docx);
stream.SetLength(0);
finalDoc.UpdateTableOfContents(); // here , its throws error only in azure.
finalDoc.SaveToStream(stream, FileFormat.Docx);
return stream.ToArray();
}
}

So, Can you help what else i can give to get the Table of Contents without error.

Note: Locally its working fine with UpdateTableOfContents() also.

Please help me out.

Regards,
Vanmathi

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Wed Feb 21, 2018 7:22 am

Hello Vanmathi,

Thanks for your inquiry.
We need your file to reproduce and investigate your issue. Please save the stream in this line, finalDoc.LoadFromStream(stream, FileFormat.Docx);, to a .docx file and send it to support@e-iceblue.com.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Wed Feb 21, 2018 9:03 am

Hi Team,

Thanks for the reply. here am attaching the word file.
Note: We are hosting onto azure through PaaS .

Please advice me whether we need to set anything in azure side. or any alternative method for UpdateTableOfContents()

Thanks in advance.

Regards,
Vanmathi
xxx.7z
xxx.7z

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Wed Feb 21, 2018 9:31 am

Hello Vanmathi,

Thanks for providing.
I will do an investigation with your file and then get back to you.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Wed Feb 21, 2018 9:41 am

Hi Amy,


I have changed my code like this.
using (MemoryStream stream = new MemoryStream())
{
Document finalDoc = new Document();
finalDoc.UpdateTableOfContents();
SaveToStream(stream, FileFormat.Docx);
finalDoc.LoadFromStream(stream, FileFormat.Docx);
stream.SetLength(0);
finalDoc.SaveToStream(stream, FileFormat.Docx);
return stream.ToArray();
}

Here, I did not get any error even UpdateTableOfcontents() is there. But , I can see empty of TOC in downloaded file.
Please help me. its very urgent

Regards,
Vanmathi N.A

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Wed Feb 21, 2018 9:59 am

Hi Amy,

For more information, am sending this code. This is for creating table of contents.
DocumentSections.Add(new ScopeTableOfContentSection(this));

Definition of ScopeTableOfContentSection(this) code: this may be helpful.

public class ScopeTableOfContentSection : ScopeDocumentSection
{
public ScopeTableOfContentSection(IDocument document)
: base(document)
{
Section = document.Sections[0];
}

/// <summary>
/// Builds a Table of Contents Section for the Scope of Work Document
/// </summary>
public override void WriteSection()
{
Paragraph tableOfContents = Section.AddParagraph();
TextRange tocTitleText = tableOfContents.AppendText("Table of Contents");
tocTitleText.CharacterFormat.Bold = true;
tocTitleText.CharacterFormat.FontSize = 14F;
tableOfContents.Format.AfterSpacing = 10F;
tableOfContents.AppendTOC(1, 9);
}

/// <summary>
/// Applies styling to the Table of Contents for the Scope of Work Document
/// </summary>
/// <param name="tableOfContents">The Table of Contents Title Paragraph</param>
/// <param name="text">The Table of Contents TextRange</param>
private void ApplyStyle(Paragraph tableOfContents, TextRange text)
{
text.CharacterFormat.Bold = true;
text.CharacterFormat.FontSize = 14F;
tableOfContents.Format.AfterSpacing = 10F;
}
}

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Wed Feb 21, 2018 10:36 am

Hello Vanmathi,

When using the new code, do you also has the issue in local?
I just did a testing in local using the following code, I can see TOC in the output docx file.
Code: Select all
Document finalDoc = new Document();
            finalDoc.LoadFromFile("..\\..\\test.docx");
            Section section = finalDoc.Sections[0];
            Paragraph tableOfContents = section.AddParagraph();
            TextRange tocTitleText = tableOfContents.AppendText("Table of Contents");
            tocTitleText.CharacterFormat.Bold = true;
            tocTitleText.CharacterFormat.FontSize = 14F;
            tableOfContents.Format.AfterSpacing = 10F;
            tableOfContents.AppendTOC(1, 9);
            finalDoc.UpdateTableOfContents();
            MemoryStream stream = new MemoryStream();
            finalDoc.SaveToStream(stream, FileFormat.Docx);
            finalDoc.LoadFromStream(stream, FileFormat.Docx);
            stream.SetLength(0);
            finalDoc.SaveToStream(stream, FileFormat.Docx);


I have some troubles in building a project in azure now. I will try to solve it. Once I finish the investigation on your issue, I will get back to you.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Wed Feb 21, 2018 10:44 am

Hi Amy,

In local, its working fine. I can see TOC. no issue in local. Problem in Azure environment only.

I found the problem with AppendTOC(1,9)

Can you please check and explain me what is that?
Note: we hosted into azure using PaaS
Regards,
Vanmathi

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Thu Feb 22, 2018 3:42 am

Hello Vanmathi,

Thanks for waiting.
I have finished the testing in azure, the error indeed occurred when running finalDoc.UpdateTableOfContents(). Sorry for the inconvenience caused. The issue has been logged into our bug system. We will notify you when it is fixed.
The method AppendTOC(int lowerLevel, int upperLevel) is to set heading level of TOC. AppendTOC(1, 9) means the level range from heading 1 to heading 9. It is necessary when creating TOC, otherwise, there is no TOC data.

Sincerely,
Amy
E-iceblue support team
User avatar

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

Thu Feb 22, 2018 7:43 am

Hi Amy,

Thanks for the reply.
So, You are saying you were able to replicate the issue on Azure side. May I know what makes the problem? Do we need version update or code change ? Please let me know when can I except a positive reply from you?

TIA,
Regards,
Vanmathi N.A

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Thu Feb 22, 2018 8:16 am

Hello Vanmathi,

At the moment, I cannot provide any update on the issue. As soon as our dev team finish the investigation I'll tell you the related information. Thanks for your understanding.

Best regards,
Amy
E-iceblue support team
User avatar

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

Mon Feb 26, 2018 1:39 am

Hello Vanmathi,

Thank you for waiting.
The error has been fixed now. We will inform you when new version is available .

Best regards,
Amy
E-iceblue support team
User avatar

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

Mon Feb 26, 2018 6:54 am

Hi amy,

Good. Thanks for the update. Please let me know once you release the version.

Note: I have deployed my application in App Service. The same code is working fine in cloud service.
Am I correct?

Regards,
Vanmathi

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Mon Feb 26, 2018 7:28 am

Hello Vanmathi,

Yes, you are correct.

Best regards,
Amy
E-iceblue support team
User avatar

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

Mon Feb 26, 2018 8:47 am

Can you tentatively give me the release date Amy?

Regards,
Vanmathi

vanmathi
 
Posts: 17
Joined: Tue Dec 17, 2013 4:40 am

Return to Spire.Doc