我该如何将Word文档中的页面转换成特定的图片?
我使用以下代码将其转换为.tiff
格式的图片:
object varMissing = Type.Missing;
object varFalseValue = false;
object varTrueValue = true;
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
word.ActivePrinter = "Microsoft XPS Document Writer";
object fileName = startupPath + "\\" + filename1;
object falseValue = false;
object trueValue = true;
object missing = Type.Missing;
word.Visible = true;
word.Activate();
Document doc = word.Documents.Open(ref fileName, ref missing,
ref falseValue, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref missing);
doc.Activate();
object PrintToFile = true;
object OutputFileName = startupPath + "\\" + filename1.Split('.')[0] + ".tif";
doc.PrintOut(ref varMissing, ref varFalseValue, ref varMissing,
ref OutputFileName, ref varMissing, ref varMissing, ref varMissing,
ref varMissing, ref varMissing, ref varMissing, ref PrintToFile,
ref varMissing, ref varMissing, ref varMissing, ref varMissing,
ref varMissing, ref varMissing, ref varMissing);
doc.Close(ref varMissing, ref varMissing, ref varMissing);
word.Quit(ref varMissing, ref varMissing, ref varMissing);
//Multi to Single
MemoryStream ms;
Image myImage;
FileStream fs = new FileStream(startupPath + "\\" + filename1.Split('.')[0] + ".tif", FileMode.Open);
fs.Seek(0, SeekOrigin.Begin);
//Here I am getting error....
myImage = Image.FromStream(fs, true, false);
Guid myGuid = myImage.FrameDimensionsList[0];
FrameDimension myDimension = new FrameDimension(myGuid);
int myPageCount = myImage.GetFrameCount(myDimension);
for (int i = 0; i < myPageCount; i++)
{
ms = new MemoryStream();
myImage.SelectActiveFrame(myDimension, i);
myImage.Save(string.Format(startupPath + "\\" + filename1.Split('.')[0] + ".tif", i), ImageFormat.Tiff);
}
fs.Close();
但是当我尝试将文件流转换为图像时,会出现错误,例如:
Parameter is not valid.
有没有其他的方法将word文件转换为图片文件?但我不能使用市场上出售的dll,我需要使用Microsoft的核心Interop dll。因此,请问是否有人可以建议我将.doc文件转换为.jpg的链接或方法。