开发者

convert the contents of word file to JPEG in c#

开发者 https://www.devze.com 2023-01-18 07:58 出处:网络
I want to convert the contents of word file [single page] into JPEG file in C#. Follwing is the code I have tried. But the Clipboard.GetImage() returns a null.

I want to convert the contents of word file [single page] into JPEG file in C#.

Follwing is the code I have tried. But the Clipboard.GetImage() returns a null.

Please help me out.

Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
        object fileName = @"C:\Documents and Settings\ErabLK\Desktop\toTest.docx";
        object val = System.Reflection.Missing.Val开发者_如何学编程ue;
        object falseVal = false;
        Document wordDoc = wordApp.Documents.Open(ref fileName, ref val, ref falseVal, ref val, ref val,
                             ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val,
                             ref val, ref val);


        wordDoc.ActiveWindow.Selection.WholeStory();
        wordDoc.ActiveWindow.Selection.Copy();
        Image img = System.Windows.Forms.Clipboard.GetImage();


GetImage() will only work if there is something on the Clipboard that is an image already.

http://msdn.microsoft.com/en-us/library/system.windows.forms.clipboard.getimage(VS.80).aspx

One solution I can think of is to create a Bitmap and use the System.Drawing.Text functions to render the pages text to the Bitmap and save it as a JPEG. You can probably extract the font properties from the word document and use that for the drawing to render it with a similar look.


        Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
        Microsoft.Office.Interop.Word.Document wordDoc = new Microsoft.Office.Interop.Word.Document();

        object falseVal = false;

        object fileName =@"C:\u.doc";
        object val= System.Reflection.Missing.Value;

        Microsoft.Office.Interop.Word.Document wordDoc1 = wordApp.Documents.Open(ref fileName, ref val, ref falseVal, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val, ref val);

        wordDoc.ActiveWindow.Selection.WholeStory();
        wordDoc.ActiveWindow.Selection.
        Image img = System.Windows.Forms.Clipboard.GetImage();
0

精彩评论

暂无评论...
验证码 换一张
取 消