ImageEn for Delphi and C++ Builder ImageEn for Delphi and C++ Builder

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Thumbnails for MS Word documents

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

View 
UserName:
Password:
Format  Bold Italicized Underline  Align Left Centered Align Right  Horizontal Rule  Insert Hyperlink   Browse for an image to attach to your post Browse for a zip to attach to your post Insert Code  Insert Quote Insert List
   
Message 

 

Emoji
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Black Eye [B)]
Frown [:(] Shocked [:0] Angry [:(!] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
mountaincoder Posted - Jan 19 2024 : 16:12:15
Is there a way using the ImageEn tools in a VCL app to create a thumbnail for a Word doc using an image of the first page?

We do this for PDFs using your components but we would love to support Word docs too.

Thanks,
Tony
5   L A T E S T    R E P L I E S    (Newest First)
mountaincoder Posted - Jan 20 2024 : 18:02:00
Wow! Thanks for all the effort. I'll try that last one.
xequte Posted - Jan 20 2024 : 16:33:34
Here is the code to convert a Word document to PDF.

Note:
- UNTESTED
- Word must be installed
- File may be locked after conversion, so you may need to sleep/process messages



const
  wdFormatDocument                    =  0;
  wdFormatDocumentDefault             = 16;
  wdFormatDOSText                     =  4;
  wdFormatDOSTextLineBreaks           =  5;
  wdFormatEncodedText                 =  7;
  wdFormatFilteredHTML                = 10;
  wdFormatFlatXML                     = 19;
  wdFormatFlatXMLMacroEnabled         = 20;
  wdFormatFlatXMLTemplate             = 21;
  wdFormatFlatXMLTemplateMacroEnabled = 22;
  wdFormatHTML                        =  8;
  wdFormatPDF                         = 17;
  wdFormatRTF                         =  6;
  wdFormatTemplate                    =  1;
  wdFormatText                        =  2;
  wdFormatTextLineBreaks              =  3;
  wdFormatUnicodeText                 =  7;
  wdFormatWebArchive                  =  9;
  wdFormatXML                         = 11;
  wdFormatXMLDocument                 = 12;
  wdFormatXMLDocumentMacroEnabled     = 13;
  wdFormatXMLTemplate                 = 14;
  wdFormatXMLTemplateMacroEnabled     = 15;
  wdFormatXPS                         = 18;
  wdFormatOfficeDocumentTemplate      = 23;
  wdFormatMediaWiki                   = 24;

const
  wdDoNotSaveChanges = $00000000;

// Convert a DOC or DOCX document to PDF, DOC or DOCX
function ConvertWordToPDF(const InFilename, OutFilename: string: OutFormat: Integer = wdFormatPDF): Boolean;
var
  wordApp: OleVariant;
begin
  Result := False;
  try
    wordApp := CreateOleObject('Word.Application');
    if VarIsEmpty( wordApp ) then
      exit;

    wordApp.Visible := False;
    wordApp.Documents.Open( InFilename,
                            false,   // ConfirmConversions
                            true );  // ReadOnly

    wordApp.ActiveDocument.SaveAs2( OutFilename, OutFormat );  

    wordApp.Quit(wdDoNotSaveChanges, EmptyParam, EmptyParam);
    wordApp := Unassigned;

    Result := True;
  except
    // Word error
  end;
end;


Nigel
Xequte Software
www.imageen.com
xequte Posted - Jan 20 2024 : 16:27:05
Hi

We import Word files just using some simple automation code.

I had a bit more time today to research it, and as I expected, there does not seem to be a definitive method to do it. There are still ways, though. For instance, this guy has a method that "prints" to XPS and then renders the XPS to a bitmap:

https://chentiangemalc.wordpress.com/2011/05/31/creating-a-thumbnail-of-a-word-document-using-powershell/

That should be portable to Delphi.

It may also be possible to print to other formats, e.g. images, but I could not find any evidence of that:

https://learn.microsoft.com/en-us/office/vba/api/word.document.printout

Finally, an inelegant solution would be to save to PDF and then generate a PDF thumbnail. This could be done using Outlook automation and would probably work OK.



Nigel
Xequte Software
www.imageen.com
mountaincoder Posted - Jan 20 2024 : 09:45:38
Thanks for the follow up. It's what I suspected.

I had only wondered if it was possible because you have a Word import tool for your RTF editor.

Still love your controls. Thanks.
xequte Posted - Jan 19 2024 : 21:31:32
Hi Tony

I don't believe that is even technically possible (other than screen scraping )

Nigel
Xequte Software
www.imageen.com