Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.doc .xls to .pdf

Status
Not open for further replies.

gcaramia

Programmer
Oct 30, 2003
185
IT
What i want to do is to transform a .doc or .xls into .pdf
I tried to print to a pdf-printer as distiller or PSprinter + GostScript + FreeDist and it's ok but i should like that the parent application (word and excel) doesn't open.
Any suggestion?
Thanks
 
If you are going to do anything with a .doc or .xls you must use some application or library which understands them.

Using OLE you can open the Microsoft apps invisibly. Something like:

Code:
var 
  XLApp: Variant;
  LWorkbook:variant;
begin
  XLApp:= CreateOleObject('Excel.Application');

  XLApp.Visible := false;

  LWorkbook:=XLApp.Workbooks.Open(
   AFileName,
   0,  {don't update links}
   true);  {read only}

  ...
  ...
end;

The Formula One spreadsheet that ships with Delphi can read .XLS files. It is lighterweight than Excel, so it starts instantly, is easily distributable but does not handle all Excel features.

In similar vein the excellent WPTools ( will read Word files. It has a PDF writer as a cost option, which I also use with great success. You could probably output from Formula One to wpPDF, but I haven't tried that myself.

Have fun
Simon
 
Thank's Simon
I think OLE may be a solution. I don't know OLE yet but i go to study it.
I'm afraid WPTools is expensive for me so if i find how to print using your sample code .....
Giovanni
 
In some manner i solved.
Parent application is open but it's not visible.
I post here my code. May be it's useful to someboby.

uses comobj;

procedure TForm1.Button1Click(Sender: TObject);
var MyExcel: olevariant;
begin
MyExcel:=UnAssigned;
MyExcel:=CreateOleObject('Excel.Application');
Try
MyExcel.Visible:=false;
MyExcel.WorkBooks.open('..\cartel1.xls');
MyExcel.WorkSheets.Printout;
Finally
if not varisempty(MyExcel) then
begin
MyExcel.quit;
MyExcel := unassigned;
end;
end;
end;

end.

 
I forgot.
If default printer is either Acrobat Distiller or any postscript printer + GostScript + FreeDist, .pdf is generated.

Thanks Simon for help


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top