开发者

How to create thumbnail of Word doc when it doesn’t have one saved?

开发者 https://www.devze.com 2023-04-09 04:28 出处:网络
I want to create a COM dll that will take any Word file and generate an image file of the first page of the document. I have already done this using the IExtractImage functionality of the Windows SDK,

I want to create a COM dll that will take any Word file and generate an image file of the first page of the document. I have already done this using the IExtractImage functionality of the Windows SDK, but this only works if there is a thumbnail saved with the file. (Since the Word user has to make an extra effort to save the thumbnail by going down into the Advanced options of the Prepare | Properties dialog, most Word docs don’t have a preview available.)

(Unfortunately I am stuck with using COM because I am integrating this solution with an existing ASP web app that does not interact well with .NET.)

One approach I am considering is using a PDF-generating SDK to generate a PDF of the file, or ideally a PDF of just the first page of the file, and then generate the preview image from the PDF. (I don’t have access to Adobe’s proprietary PDF SDK, but if it could be shown to work well for this solution, I would look into purchasing a li开发者_运维问答cense.)

Ideally I would like to be able to generate a preview of many other (non-image) file types besides just a Word doc.

I notice that Google now provides a preview of many kinds of files, and I am wondering what approach they have used.

Any thoughts, clues, suggestions, and/or insults are welcome.

Thanks.


The thumbnail from the old OLE-Automation property pages is a very small (not even anti-aliased) black & white Metafile that does not look any good these days. Within classic VB6 or VBA, you can trigger saving the thumbnail with a few lines of code (If I remember correctly). However, Winword, Excel etc. are automated by loading the Gui application invisibly and this does not always work in a (web) server context. Consider to thumbnail the documents while uploading / virus scanning but not from inside a DLL that gets loaded into the web server.

The google approach builds most-likely upon some open-source components that do not work under classic ASP either.


ASP? You could use 2JPEG. It support 275 formats (including Word, Excel, Publisher & Powerpoint files.) The vendor recommends calling 2JPEG as a scheduled background task so you don't impact performance.

Here's a couple of examples:

Command line syntax. You can start in from a batch file or from the Windows Task Scheduler:

2jpeg.exe -src "C:\In\*.*" -dst "C:\Out"

Launch command line from Visual C++ application:

ShellExecute(NULL, "open", "2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"", NULL, SW_HIDE)

From Visual Basic:

Shell ("""2jpeg.exe"" -src ""C:\In\*.*"" -dst ""C:\out""")

Delphi syntax:

ShellExecute(0, 'open', PChar('2jpeg.exe'), PChar('-src "C:\In\*.*" -dst "C:\Out"'), nil, 0);

PERL script on Windows server:

exec '2jpeg.exe -src C:\In\*.* -dst C:\out';

VB Script code example:

Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run """2jpeg.exe"" -src ""C:\In\*.*"" -dst ""C:\Out""", 1, True
Set objShell = Nothing

JavaScript code example:

var objShell = new ActiveXObject("Shell.Application");
objShell.ShellExecute("2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"", "", "open", "1");

PHP code example:

<?php
echo exec('2jpeg.exe -src "C:\In\*.*" -dst "C:\Out" -oper Resize size:"800 600" -jpeg quality:50');
?>

Launch 2JPEG from C# application:

System.Diagnostics.Process.Start("2jpeg.exe", "-src \"C:\\In\\*.*\" -dst \"C:\\Out\"");
0

精彩评论

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

关注公众号