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

 

ImageEn Forum
Profile    Join    Active Topics    Forum FAQ    Search this forumSearch
Forum membership is Free!  Click Join to sign-up
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 ImageEn Library for Delphi, C++ and .Net
 ImageEn and IEvolution Support Forum
 Thumbnails for MS Word documents
 New Topic  Reply to Topic
Author Previous Topic Topic Next Topic  

mountaincoder

USA
12 Posts

Posted - Jan 19 2024 :  16:12:15  Show Profile  Reply
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

xequte

38046 Posts

Posted - Jan 19 2024 :  21:31:32  Show Profile  Reply
Hi Tony

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

Nigel
Xequte Software
www.imageen.com
Go to Top of Page

mountaincoder

USA
12 Posts

Posted - Jan 20 2024 :  09:45:38  Show Profile  Reply
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.
Go to Top of Page

xequte

38046 Posts

Posted - Jan 20 2024 :  16:27:05  Show Profile  Reply
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
Go to Top of Page

xequte

38046 Posts

Posted - Jan 20 2024 :  16:33:34  Show Profile  Reply
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
Go to Top of Page

mountaincoder

USA
12 Posts

Posted - Jan 20 2024 :  18:02:00  Show Profile  Reply
Wow! Thanks for all the effort. I'll try that last one.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
Jump To: