Alex P.
Alex P.

Reputation: 1158

ActiveX component for converting Word and Excel documents to PDF

We need to add a feature to our in-house Borland Delphi 7 application to convert MS Office documents (.doc, .docx, .xls, .xlsx) to PDF.

Is there an ActiveX component or another solution (commercial or free) which we can use or integrate with our application to achieve this?

Would need that to also work for versions of Office older than 2007 since on 2007 conversion is available through an add-on and on 2010 it available by default.

We're also interested if that can be achieved without a third party component.

Upvotes: 2

Views: 5070

Answers (2)

Johan
Johan

Reputation: 76537

Is there an ActiveX component or another solution (commercial or free) which we can use or integrate with our application to achieve this?

The best way is to use Office itself to convert.
Office 2007 is the first version that can save a document as PDF.
So if you have a version installed (not you, but someone else) pre-2007, you have to install a PDF-printer (like PDF-creator or whatnot).

You can then instruct Word using OLE-automation (only works on Office 2007 and up)

procedure ConvertToPDF(Filename: string);
const
  pdf = '.pdf';
var
  NewFilename: string;
  Extension: string;
  WinWord, Document: OleVariant;
  e: OleVariant;
begin
  e:= EmptyParam;
  Extension:= ExtractFileExt(Filename);
  NewFilename:= StringReplace(Filename, Extension, pdf, [rfReplaceAll, rfIgnoreCase]);
  WinWord := CreateOleObject('Word.Application');        
  Document := WinWord.Documents.Open(Filename);
  Document.SaveAs(NewFilename, wdFormatPDF, e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e,e);
  .... 

Upvotes: 4

mjn
mjn

Reputation: 36634

One option is to use OpenOffice, which can open MS Office documents and save them as PDF.

This can be automated and even used over the network (central converter service) over the headless mode of OpenOffice, which accepts control commands over a socket connection.

There are implementations available in various programming languages which use this service API for conversions.

Upvotes: 4

Related Questions