pascal export to pdf problem

Java, C++, C#, Delphi, ??? - Using the UNO bridges

pascal export to pdf problem

Postby zammas » Tue Jul 31, 2018 9:40 am

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?
Libre Office Version: 6.0.5.2 (x64) on Windows 10 Pro
User avatar
zammas
 
Posts: 1
Joined: Tue Feb 20, 2018 10:05 am

Re: pascal export to pdf problem

Postby Lupp » Tue Jul 31, 2018 3:14 pm

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/ ?
On Windows 10: LibreOffice 6.1 and older versions, PortableOpenOffice 4.1.5 and older, StarOffice 5.2
---
Lupp from München
User avatar
Lupp
Volunteer
 
Posts: 1914
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest

cron