2
votes

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.

2
Both .docx and .pdf formats are fully documented by Microsoft and Adobe respectfully. The .doc standard is also documented of course the document I looked at a few years ago was hundreds of pages. So you are better of going with a component that is already written.Security Hound
No third party component? Fine. Use OLE automation to control Microsoft Word, a version that can open Word documents, and save to PDF, like Office 2010. You must have Office 2010 installed in order to control it via OLE automation.Warren P
You've asked for an ActiveX control, which most likely is provided by a third party, but then specified that non third party is preferred? Oh, wait - and mentioned "commercial or free", which both also imply third party. I think I'm confused here...Ken White
Ken you're right. We are looking at more solutions here to see what our options are. The question indeed needs some editing to make it clear.Alex Pandrea

2 Answers

4
votes

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.

4
votes

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);
  ....