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:
, 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.