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 Oct 08, 2013 9:16 am

Hello, I'm looking for some solution to convert .doc to .bmp, and I'm trying with Spire.Doc for .Net.
My codes:
Code: Select all
        public static System.Drawing.Image ResetResolution(Metafile mf, float resolution)
        {
            int width = (int)(mf.Width * resolution / mf.HorizontalResolution);
            int height = (int)(mf.Height * resolution / mf.VerticalResolution);
            Bitmap bmp = new Bitmap(width, height);
            bmp.SetResolution(resolution, resolution);
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.DrawImage(mf, 0, 0);
            }

            return bmp;
        }
        void doc2bmp(string input, float dpi)// dpi is 300.0
        {
            Spire.Doc.Document doc = null;
            try
            {
                //Create word document
                doc = new Spire.Doc.Document();
                doc.LoadFromFile(input);
 
                //Save doc file.
                System.Drawing.Image[] images = doc.SaveToImages(ImageType.Metafile);
 
                for(int i = 0; i < images.Length; ++i)
                {
                    Metafile metaFile = images[i] as Metafile;
                    System.Drawing.Image image = ResetResolution(metaFile, dpi);

                    string output = System.IO.Path.Combine(folder, String.Format("out.spire{0}.bmp", i));
                    image.Save(output, System.Drawing.Imaging.ImageFormat.Bmp);
                    image.Dispose();
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            finally
            {
                if (doc != null)
                {
                    doc.Close();
                }
            }
        }

My test file:
test.zip

, which is one 50-page .doc, with pictures, text, and table on each page

and my problems:
1.pages are not same as which in .doc with MS Word, and thus total page count become 40 after convertion
2.nearly half page missed of the last page
3.in different PC, the convertion .bmp size are different
in my PC, it's 58.8MB,3302*4675
in my colleague's PC, it's 92.1MB,4131*5845

Maybe there is something wrong with my code? Please help to figure out and thanks.

swizard
 
Posts: 1
Joined: Mon Sep 23, 2013 2:16 am

Wed Oct 09, 2013 7:10 am

Hello,

Thanks for your inquiry.
We reproduced your problems. Sorry for the inconvenience caused by these problems.
Microsoft didn't public any official document to show how to display Word documents and how to convert each page to image. Nobody knows the conversion algorithm in MS-Word. So our algorithm is difference from MS-Word's. And we have been trying to make the content of converted images as same as the Word document' s extracly, but it is very difficult. Sorry that our Spire.Doc component doesn't convert Word document to images very exactly at present , but we are keeping in adjusting our algorighm and will get exactly the converted images from the word document in the future. Thanks for your understanding and support.

Welcome to write to us again in case you have further problems.

Best regards,
Amy
E-iceblue support team
User avatar

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

Fri Jun 20, 2014 9:29 am

Hello,

Thanks for your waiting.
The issues have been resolved. Welcome download and test Spire.Doc Pack(hot fix) Version:5.1.23.
Downloading link:http://www.e-iceblue.com/Download/download-word-for-net-now.html

Feel free to contact us if you have any problems.

Best wishes,
Amy
User avatar

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

Return to Spire.Doc