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.

Sun Feb 15, 2015 8:34 am

I want Convert Word to Pdf but , this error occur ?
The type initializer for 'spr᧹' threw an exception.
this is my Code !

Code: Select all
   public static byte[] ConvertDocToPdf(byte[] bytesDoc)
        {
            if (bytesDoc != null)
            {
                const string strFileName = "Job-Description";
                string strPath = HostingEnvironment.MapPath("~/assets/Preview_Job_Description");
                if (strPath != null && !Directory.Exists(strPath))
                    Directory.CreateDirectory(strPath);
                strPath += "/" + strFileName+".docx";
                System.IO.File.WriteAllBytes(strPath, bytesDoc);
                Spire.Doc.Document document = new Spire.Doc.Document();
                document.LoadFromFile(strPath);
            //Convert Word to PDF
            document.SaveToFile("~/assets/Preview_Job_Description/toPDF.PDF", FileFormat.PDF);
                byte[] pdfBytes =System.IO.File.ReadAllBytes(HostingEnvironment.MapPath("~/assets/Preview_Job_Description/toPDF.PDF"));
                return pdfBytes;
            }
            else
            {
                bytesDoc = new byte[0];
                const string strFileName = "Job-Description";
                string strPath = HostingEnvironment.MapPath("~/assets/Preview_Job_Description");
                if (strPath != null && !Directory.Exists(strPath))
                    Directory.CreateDirectory(strPath);
                strPath += "/" + strFileName;
                System.IO.File.WriteAllBytes(strPath + ".doc", bytesDoc);
                return bytesDoc;
            }
        }

pshtiwan.hassan
 
Posts: 1
Joined: Sun Feb 15, 2015 8:31 am

Mon Feb 16, 2015 2:18 am

Hello,

Thanks for your inquiry.
Please provide your sample document for our testing here, or you can send it to us(support@e-iceblue.com) via email.
Thanks.

Best Regards,
Betsy
User avatar

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

Thu Mar 12, 2015 2:33 pm

I had a similar error which with resolved by placing the Spire.pdf.dll file in the same location as Spire.doc.dll

Hampo
 
Posts: 28
Joined: Thu Jan 22, 2015 2:29 pm

Fri Mar 13, 2015 1:47 am

Hello,

pshtiwan.hassan,please try the solution provided by Hampo, if the issue still exists, please provide us the docuemnt for our testing.

Best Regards,
Betsy
E-iceblue support team
User avatar

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

Return to Spire.Doc