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 Mar 17, 2015 9:09 pm

I'm using Free Spire.DOC

When I load an image, I get an unhandled exception raised by AppendPicture. The image loads correctly into the Image type, then raises exception on AppendPicture.

My code:

Code: Select all
                DocPicture Pic;
                Para = section.AddParagraph();

                Image image = Image.FromFile(HttpContext.Current.Server.MapPath(@"~\Content\icons\DiplomaBG.jpg"));
                Pic = Para.AppendPicture(image);


My full Exception trace

System.TypeInitializationException was unhandled by user code
HResult=-2146233036
Message=The type initializer for 'sprᨔ' threw an exception.
Source=Spire.Doc
TypeName=sprᨔ
StackTrace:
at sprᨔ..ctor()
at sprᴧ..ctor(Document A_0)
at sprឈ..ctor(DocumentBase A_0)
at sprᡝ..ctor(IDocument A_0)
at sprᨓ..ctor(IDocument A_0)
at Spire.Doc.Fields.DocPicture..ctor(IDocument doc)
at Spire.Doc.Document.CreateParagraphItem(ParagraphItemType itemType)
at Spire.Doc.Documents.Paragraph.ᜀ(ParagraphItemType A_0)
at Spire.Doc.Documents.Paragraph.AppendPicture(Image image)
at _9ResWeb.Controllers.ResumeApiController.getResumeDOC(ResumeViewModel newResume) in c:\Users\dave\Documents\GitHub\9ResWebAlpha\9ResWeb\Controllers\ResumeApiController.cs:line 383
at lambda_method(Closure , Object , Object[] )
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
InnerException: System.MissingMethodException
HResult=-2146233069
Message=Method not found: 'Int32 sprẌ.ᜂ(Double)'.
Source=Spire.Doc
StackTrace:
at spr⇩.ᜈ(Double A_0)
at sprᨔ..cctor()
InnerException:

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Wed Mar 18, 2015 3:21 am

Hello,

Thanks for your inquiry.
In order to reproduce this issue, please upload your sample document and the picture(DiplomaBG.jpg) or you can send it to support@e-iceblue.com.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 18, 2015 3:57 am

I have included the diploma. This one is particularly big. I only tried this when my small png's and bmp's failed to load because I saw other users had problems with png's. degree.bmp and cerification.bmp are files i really wanted to add.

I don't understand how I can upload a sample document since the exception keeps a document from being generated -- I got a problem while generating a DOC, not editing it.

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Wed Mar 18, 2015 6:47 am

Hello,

Sorry that I have a mistake that misunderstand you load a document and edit it, so let you send the sample document for our testing.
Please provide the using pictures when throw an exception for our testing. If the pictures are too big, please send them to support@e-iceblue.com via email.


Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 18, 2015 3:13 pm

I have included 3 of the files I wanted to add to the DOC. iconcert.png and certs.png are the important ones. Your system didn't allow me to upload bmp's.

Please Let me know if any other code or explanations are important.

I can send or embed the entire Create Doc method.

I don't think the specific files are the problem b/c i have literally tried dozens, all different sizes and formats.

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Thu Mar 19, 2015 10:07 am

Hello,

Thanks for sharing information.
Please download Spire.Doc Pack(hot fix) version:5.3.71 from the following link and have a try:
http://www.e-iceblue.com/Download/downl ... t-now.html
If the issue still happens, welcome to get it back to us.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Mar 19, 2015 2:09 pm

Thank you, but this is not the FREE SPIRE, it's the trial version...

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Fri Mar 20, 2015 8:59 am

Hello,

Please provide the entire Create Doc method and your system environment information.

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Mon Mar 23, 2015 5:02 pm

Here is the full web api method

the exception is raised on

Code: Select all
Pic = Para.AppendPicture(image);


I have confirmed that the Image gets properly loaded into the Image by

Code: Select all
Image image = Image.FromFile(HttpContext.Current.Server.MapPath(@"~\Content\icons\iconcert.png"));


Code: Select all
        [Route("api/getResumeDOC")]
        [AcceptVerbs("POST", "GET")]
        public HttpResponseMessage getResumeDOC([FromBody]ResumeViewModel newResume)
        {

            var ms = new MemoryStream();
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);


            int unicode = 13;
            char character = (char)unicode;
            string NL = character.ToString();
           
            TextRange txtRange;

            Table table;
            TableRow CurrentRow;


            // Doc Setup
            //#region DocSetup

            Document doc = new Document();

            Section section; // = doc.AddSection();

            section = doc.AddSection();
            section.BreakCode = SectionBreakType.NewPage;
            section.PageSetup.PageSize = PageSize.A4;
            section.PageSetup.Margins.Top = 72f;
            section.PageSetup.Margins.Bottom = 72f;
            section.PageSetup.Margins.Left = 89.85f;
            section.PageSetup.Margins.Right = 89.85f; 

            Paragraph Para; // = section.AddParagraph();

            // ------------- Header -----------------
            #region Header
            ParagraphStyle style = new ParagraphStyle(doc);
            style.Name = "9resHeader";
            style.CharacterFormat.FontName = "Arial";
            style.CharacterFormat.Bold = true;
            style.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);
            doc.Styles.Add(style);




            Para = section.AddParagraph();
            Para.ApplyStyle("9resHeader");
            Para.Format.HorizontalAlignment = HorizontalAlignment.Center;
            txtRange = Para.AppendText(String.Format("{0} {1} {2}", newResume.contactInfo.firstName, newResume.contactInfo.middleName, newResume.contactInfo.lastName));
            txtRange.CharacterFormat.FontSize = 20;


            table = section.AddTable(true);
            table.ResetCells(3, 2);
            table.ApplyHorizontalMerge(0, 0, 1);


            table.TableFormat.Borders.LineWidth = 0F;

            CurrentRow = table.Rows[0];
            CurrentRow.RowFormat.Borders.Vertical.LineWidth = 0F;
            CurrentRow.RowFormat.Borders.Horizontal.LineWidth = 0F;
            CurrentRow.RowFormat.Borders.Top.Color = Color.LightGray;
            CurrentRow.RowFormat.Borders.Top.LineWidth = 1F;
            Para = CurrentRow.Cells[0].AddParagraph();


            Para.Format.HorizontalAlignment = HorizontalAlignment.Center;
            txtRange = Para.AppendText(String.Format("{0} {1} {2} {3}", newResume.contactInfo.addrStreet, newResume.contactInfo.addrTown, newResume.contactInfo.addrState, newResume.contactInfo.addrZip));
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.FontSize = 11;
            txtRange.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);


            CurrentRow = table.Rows[1];
            CurrentRow.RowFormat.Borders.Horizontal.Color = Color.LightGray;
            CurrentRow.RowFormat.Borders.Color = Color.LightGray;
            CurrentRow.RowFormat.Borders.Vertical.LineWidth = 0F;
            CurrentRow.RowFormat.Borders.Horizontal.LineWidth = 0F;
            CurrentRow.RowFormat.Borders.Top.Color = Color.LightGray;
            //FRow.IsHeader = true;
            //FRow.Cells[0].GridSpan.
            Para = CurrentRow.Cells[0].AddParagraph();
            Para.Format.HorizontalAlignment = HorizontalAlignment.Left;

            txtRange = Para.AppendText(String.Format("{0} ", newResume.contactInfo.number1));
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.FontSize = 10;
            txtRange.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);

            txtRange = Para.AppendText(String.Format("{0} ", newResume.contactInfo.number2));
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.FontSize = 10;
            //txtRange.CharacterFormat.Bold = true;
            txtRange.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);
            //txtRange.ApplyCharacterFormat()


            Para = CurrentRow.Cells[1].AddParagraph();
            Para.Format.HorizontalAlignment = HorizontalAlignment.Right;
            txtRange = Para.AppendText(String.Format("{0} ", newResume.contactInfo.number1));
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);
            txtRange.CharacterFormat.FontSize = 10;
            txtRange = Para.AppendText(String.Format("{0} ", newResume.contactInfo.number2));
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.FontSize = 10;
            txtRange.CharacterFormat.TextColor = Color.FromArgb(40, 94, 166);
            #endregion


            // Objectives
            #region Objectives
            // Table for Objectives
            Para = section.AddParagraph();
            table = section.AddTable(true);
            table.PreferredWidth = new PreferredWidth(WidthType.Percentage, 100); // {Type = WidthType.Twip}
            table.TableFormat.Paddings.Left = 15;
            table.TableFormat.Paddings.Right = 15;
            table.TableFormat.Paddings.Top = 20;
            table.TableFormat.Paddings.Bottom = 20;
            table.TableFormat.Borders.Color = Color.FromArgb(125, 125, 125);
            //table.TableFormat.BackColor = Color.FromArgb(0, 200, 200);


            CurrentRow = table.AddRow(false, 1);
            CurrentRow.RowFormat.Borders.Vertical.LineWidth = 0F;
            //CurrentRow.RowFormat.Paddings.Top = 1000;
            //CurrentRow.RowFormat.Paddings.Bottom = 1000;
            //CurrentRow.RowFormat.Paddings.Right = 10;
            //CurrentRow.RowFormat.Paddings.Left = 10;
            //CurrentRow.Cells[0].CellFormat.Paddings.All = 10;
            CurrentRow.Cells[0].SetCellWidth(80, CellWidthType.Percentage);
            CurrentRow.Cells[0].CellFormat.BackColor = Color.FromArgb(245, 245, 245);


            foreach (var objective in newResume.objectives)
            {
                Para = CurrentRow.Cells[0].AddParagraph();
                txtRange = Para.AppendText(String.Format("{0}", objective.description));
                txtRange.CharacterFormat.FontName = "Times New Roman";
                txtRange.CharacterFormat.FontSize = 11;
            }


            Para = section.AddParagraph();
            txtRange = Para.AppendText(String.Format("{0}", NL));

            #endregion


            // SkillSets
            #region SkillSets
            foreach (var skillSet in newResume.skills)
            {

                //Para = section.AddParagraph();
                //txtRange = Para.AppendText(String.Format("{0}{1} ", NL, NL));

                txtRange = Para.AppendText(String.Format("{0}{1}: ", NL, skillSet.Title));

                txtRange.CharacterFormat.FontName = "Times New Roman";
                txtRange.CharacterFormat.FontSize = 12;
                txtRange.CharacterFormat.Bold = true;
                txtRange.CharacterFormat.TextColor = Color.FromArgb(125, 125, 125);

                foreach (var skill in skillSet.Skills)
                {
                    txtRange = Para.AppendText(String.Format("{0} ",skill.Title));
                    txtRange.CharacterFormat.FontName = "Times New Roman";
                    txtRange.CharacterFormat.FontSize = 10;
                    txtRange.CharacterFormat.Bold = true;
                    txtRange.CharacterFormat.TextColor = Color.Black;

                }


            }

            //ListStyle listStyle = new ListStyle(doc, ListType.Numbered);
            //listStyle.Name = "levelstyle";
            //listStyle.Levels[0].PatternType = ListPatternType.Arabic;
            //listStyle.Levels[1].NumberPrefix = "\x0000.";
            //listStyle.Levels[1].PatternType = ListPatternType.Arabic;
            //listStyle.Levels[2].NumberPrefix = "\x0000.\x0001.";
            //listStyle.Levels[2].PatternType = ListPatternType.Arabic;
            //doc.ListStyles.Add(listStyle);

            #endregion



            // Career Experience
            #region Jobs
            table = section.AddTable(false);
            table.TableFormat.Paddings.Top = 10;

            TableRow TR; //NL

            CurrentRow = table.AddRow(1);
            Para = CurrentRow.Cells[0].AddParagraph();
            txtRange = Para.AppendText(NL);
            txtRange = Para.AppendText("Experience:");
            txtRange.CharacterFormat.FontSize = 13;
            txtRange.CharacterFormat.Bold = true;
            txtRange.CharacterFormat.FontName = "Arial";
            txtRange.CharacterFormat.TextColor = Color.FromArgb(125, 125, 125);

            foreach (var job in newResume.jobs)
            {
                CurrentRow = table.AddRow(false, 3);

                Para = CurrentRow.Cells[0].AddParagraph();
                CurrentRow.Cells[0].SetCellWidth(40, CellWidthType.Percentage);
                txtRange = Para.AppendText(String.Format("{0}", job.firmLong));
                Para.ApplyStyle("9resHeader");
                txtRange.CharacterFormat.FontSize = 10;


                txtRange = Para.AppendText(String.Format("{2}({0}, {1})", job.city, job.state, NL));
                txtRange.CharacterFormat.TextColor = Color.Black;
                txtRange.CharacterFormat.Bold = false;
                txtRange.CharacterFormat.FontSize = 8;



                Para = CurrentRow.Cells[1].AddParagraph();
                CurrentRow.Cells[1].SetCellWidth(40, CellWidthType.Percentage);
                Para.ApplyStyle("9resHeader");
                txtRange = Para.AppendText(String.Format("{0}", job.titleLong));
                txtRange.CharacterFormat.FontSize = 10;


                //CurrentRow.Cells[2].CellFormat.FitText = true;
                Para = CurrentRow.Cells[2].AddParagraph();
                CurrentRow.Cells[2].SetCellWidth(20, CellWidthType.Percentage);
                Para.ApplyStyle("9resHeader");
                txtRange = Para.AppendText(String.Format("{0}/{1}-{2}/{3}", job.startMonth, job.startYear, job.endMonth, job.endYear));
                txtRange.CharacterFormat.FontSize = 9;
                //txtRange.CharacterFormat.


                CurrentRow = table.AddRow(false, 3);
                table.ApplyHorizontalMerge(CurrentRow.GetRowIndex(), 0, 2);


                foreach (var jobDetail in job.details)
                {
                    Para = CurrentRow.Cells[0].AddParagraph();
                    Para.ListFormat.ApplyBulletStyle();
                    Para.ListFormat.CurrentListLevel.NumberPosition = -10;
                    Para.ListFormat.CurrentListLevel.TextPosition = 20;

                    txtRange = Para.AppendText(jobDetail.description);
                    txtRange.CharacterFormat.FontSize = 9;
                    txtRange.CharacterFormat.Bold = true;

                    //Para.AppendText(String.Format("{0}{1}", jobDetail.description, NL));
                }


            }

            #endregion

            // Education
            #region Education
            Para = section.AddParagraph();
            txtRange = Para.AppendText(String.Format("{0} {1}Education: {2}", NL, NL, NL, NL, NL));
            txtRange.CharacterFormat.FontSize = 13;
            txtRange.CharacterFormat.Bold = true;
            txtRange.CharacterFormat.FontName = "Times New Roman";
            txtRange.CharacterFormat.TextColor = Color.FromArgb(125, 125, 125);


            foreach (var highschool in newResume.education.highschools)
            {
                Para = section.AddParagraph();
                txtRange = Para.AppendText(String.Format("{0} ", highschool.name));
                txtRange.CharacterFormat.FontName = "Arial";
                txtRange.CharacterFormat.FontSize = 11;
                txtRange.CharacterFormat.Bold = true;

                txtRange = Para.AppendText(String.Format("{0} {1} {2} {3}", highschool.city, highschool.state, highschool.gradMonth, highschool.gradYear));
                txtRange.CharacterFormat.Bold = false;
                txtRange.CharacterFormat.FontSize = 10;
            }


            foreach (var college in newResume.education.colleges)
            {
                Para = section.AddParagraph();
                txtRange = Para.AppendText(String.Format("{0} ", college.name));
                txtRange.CharacterFormat.FontName = "Arial";
                txtRange.CharacterFormat.FontSize = 11;
                txtRange.CharacterFormat.Bold = true;

                txtRange = Para.AppendText(String.Format("{0} {1} ", college.city, college.state));
                txtRange.CharacterFormat.Bold = false;
                txtRange.CharacterFormat.FontSize = 10;
                txtRange = Para.AppendText(String.Format("{0},{1} ", college.degreeType, college.degreeProgram));
                txtRange.CharacterFormat.Bold = true;
                txtRange.CharacterFormat.FontSize = 10;
                txtRange = Para.AppendText(String.Format("{0}-{1}", college.gradMonth, college.gradYear));
                txtRange.CharacterFormat.Bold = false;
                txtRange.CharacterFormat.FontSize = 10;
            }

            DocPicture Pic;

            foreach (var certificate in newResume.education.certificates)
            {
                Para = section.AddParagraph();

                Image image = Image.FromFile(HttpContext.Current.Server.MapPath(@"~\Content\icons\iconcert.png"));
                Pic = Para.AppendPicture(image);

                txtRange = Para.AppendText(String.Format("{0} ", certificate.type));
                txtRange.CharacterFormat.FontName = "Arial";
                txtRange.CharacterFormat.FontSize = 11;
                txtRange.CharacterFormat.Bold = true;

                txtRange = Para.AppendText(String.Format("{0} {1}-{2} ", certificate.Provider, certificate.compMonth, certificate.compYear));
                txtRange.CharacterFormat.Bold = false;
                txtRange.CharacterFormat.FontSize = 10;
            }
            #endregion

            doc.SaveToStream(ms, Spire.Doc.FileFormat.Docx);


            response.Content = new ByteArrayContent(ms.ToArray());
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/msword");
            response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment")
            {
                FileName = "Resume.docx"
            };


            return response;
        }
    }

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Tue Mar 24, 2015 9:51 am

Hello,

Thanks for sharing information.
We are investigating, once there are any processes, we will let you know.

Best Regards,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 25, 2015 9:20 am

Hello,

Sorry for delay.
I suggest that's because spire.pdf.dll was not added or it is not placed in the same location as Spire.doc.dll. Please verify it.

Thanks,
Betsy
E-icblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Wed Mar 25, 2015 3:12 pm

Ok, I see that Spire.Pdf.dll is included with Spire.Doc

But since I use both Spire.Doc and Spire.Pdf, I'm worried that this reference will replace the other and cause conflicts.

In fact, if you're right, when I added Spire.Pdf, it probably replaced the reference. How can I use both?


--------------------------------

Follow up

I cannot include both assemblies in same project (Spire.Pdf.dll from Spire.Pdf and Spire.Doc)

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Wed Mar 25, 2015 8:50 pm

Further Followup:

I created a new project for Doc Creation. I referenced Sprire.Pdf.dll, Spire.Doc.dll, and Spire.License.dll.

They are all located in same packages directory created by nuget packages\FreeSpire.Doc.5.2.12\lib\net40

I still get the strange exception:

Code: Select all
System.TypeInitializationException was unhandled by user code
  HResult=-2146233036
  Message=The type initializer for 'sprᨔ' threw an exception.
  Source=Spire.Doc
  TypeName=sprᨔ
  StackTrace:
       at sprᨔ..ctor()
       at sprᴧ..ctor(Document A_0)
       at sprឈ..ctor(DocumentBase A_0)
       at sprᡝ..ctor(IDocument A_0)
       at sprᨓ..ctor(IDocument A_0)
       at Spire.Doc.Fields.DocPicture..ctor(IDocument doc)
       at Spire.Doc.Document.CreateParagraphItem(ParagraphItemType itemType)
       at Spire.Doc.Documents.Paragraph.ᜀ(ParagraphItemType A_0)
       at Spire.Doc.Documents.Paragraph.AppendPicture(Image image)
       at _9Res.DocGenerator.WordDocBuilder.WordDocBuilder.BuildWordDoc(ResumeDTO resumeData) in c:\Users\dave\Documents\GitHub\9ResWebAlpha\9Res.DocGenerator\WordDocBuilder\WordDocBuilder.cs:line 339
       at _9ResWeb.Controllers.ResumeApiController.getResumeDOC(ResumeViewModel newResume) in c:\Users\dave\Documents\GitHub\9ResWebAlpha\9ResWeb\Controllers\ResumeApiController.cs:line 526
       at lambda_method(Closure , Object , Object[] )
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)
       at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)
  InnerException: System.MissingMethodException
       HResult=-2146233069
       Message=Method not found: 'Int32 sprẌ.ᜂ(Double)'.
       Source=Spire.Doc
       StackTrace:
            at spr⇩.ᜈ(Double A_0)
            at sprᨔ..cctor()
       InnerException:

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Thu Mar 26, 2015 7:22 am

Hello,

If you want to use two products(Spire.Doc and Spire.Pdf) in the same project, you need to use the Spire.Office.
In addition, there is a test project, please download it from the following link, run it on your computer and see how it goes:
http://www.e-iceblue.com/downloads/temp/4622.rar

Thanks,
Betsy
E-iceblue support team
User avatar

Betsy
 
Posts: 802
Joined: Mon Jan 19, 2015 6:14 am

Thu Mar 26, 2015 3:44 pm

Betsy,

If you read my last post, I told you that when I created a dedicated project the problem error/exception still happened.

dalper02
 
Posts: 10
Joined: Tue Mar 17, 2015 7:18 pm

Return to Spire.Doc