Page 1 of 1

pascal export to pdf problem

PostPosted: Tue Jul 31, 2018 9:40 am
by zammas
Hi,

I use freepascal to export an *.odt file to *.pdf.
With this code I can export file:

Code: Select all   Expand viewCollapse view
function SaveOdtFileToPdf3(ASourceFileURL: string; ATargetFileURL: string):string;
var
  Server       : Variant;
  Desktop      : Variant;
  LoadParams   : Variant;
  Document     : Variant;
  Param        : Variant;
  Param1        : Variant;
  Param2        : Variant;
 
  FilterParams : Variant;
  _ret : String;

  function CreateProperty(const AName: AnsiString; AValue: Variant): Variant;
  begin
    Result := Server.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
    Result.Name := AName;
    Result.Value := AValue;
  end;

begin
  _ret := '';
  try
    try
      if Assigned(InitProc) then
        TProcedure(InitProc);

      Server := CreateOleObject('com.sun.star.ServiceManager');
      Desktop := Server.CreateInstance('com.sun.star.frame.Desktop');

      LoadParams := VarArrayCreate([0, 0], varVariant);
      Param := Server.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
      Param.Name := 'Hidden';
      Param.Value := True;
      LoadParams[0] := Param;


      Document := Desktop.LoadComponentFromURL(WideString(ASourceFileURL), '_blank', 0, LoadParams);

      FilterParams := VarArrayCreate([0, 1], varVariant);


      Param1 := Server.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
      Param1.Name := 'FilterName';
      Param1.Value := 'writer_pdf_Export';     //writer_pdf_Export writer_web_pdf_Export
      FilterParams[0] := Param1;


      Param2 := Server.Bridge_GetStruct('com.sun.star.beans.PropertyValue');
      Param2.Name := 'CompressionMode';
      Param2.Value := 1;
      FilterParams[1] := Param2;

      Document.storeToURL(WideString(ATargetFileURL), FilterParams);
      Document.Close(False);


    except
      on E : Exception do
      begin
       _ret:=E.Message;
      end;
    end;
  finally
    Result:= _ret;
  end;

end;


My questions are:
1. There is a callback of the export process to know the export status?
2. I noticed that if writer is open, the procedure goes into error ... Is it possible to avoid the thing?

Re: pascal export to pdf problem

PostPosted: Tue Jul 31, 2018 3:14 pm
by Lupp
I have very little experience with document automation and none with this specific topic. I only can point you to
https://www.freepascal.org/~michael/art ... office.pdf by Michaƫl Van Canneyt who surely is an expert.
The article is about working with Delphi, but concerning your questions that shouldn't make much difference.
Of course, you may know the text already. Do you also take part in the Lazarus forum http://forum.lazarus.freepascal.org/ ?