Jump to content

Recommended Posts

Posted

 

I am using the following code.
But the user has to download the file and then share it.

procedure TUnimForm1.shareButtonClick(Sender: TObject);
var
  dm: TrepDataModule;
begin
  dm := TrepDataModule.Create(nil);
  try
    UniSession.AddJS('var myWindow = window.open(''' + dm.GenRep(InvNum)+ ''', ''foo'','''');' 
      + ' if (myWindow == null)' +
      '   alert (''Please change your popup settings'');' + ' else  {' +
      '  myWindow.moveTo(0, 0);' +
      '  myWindow.resizeTo(screen.width, screen.height);' + '}'
      );
  finally
    dm.Free;
  end;

end;

 

Posted

Hello 

The Share Via window opened with the following code.

And I was able to send the file using Telegram messenger.

procedure TMainForm.UniButton1Click(Sender: TObject);
var
  JSCode: string;
begin
  JSCode :=
    'if (navigator.share) {' +
    '  navigator.share({' +
    '    title: "Share PDF",' +
    '    files: [new File(["' + UnimPDFFrame1.PdfURL + '"], "file.pdf", { type: "application/pdf" })],' +
    '  })' +
    '  .then(() => console.log("Successful share"))' +
    '  .catch((error) => console.log("Error sharing", error));' +
    '} else {' +
    '  alert("Web Share API is not supported in your browser.");' +
    '}';
  UniSession.AddJS(JSCode);
end;

But after sharing, when opening the PDF file, the following message is displayed.

invalid format

While UnimPDFFrame displays it.

procedure TUnimForm1.UnimFormBeforeShow(Sender: TObject);
var
  dm: TrepDataModule;
begin
  dm := TrepDataModule.Create(nil);
  try
    UnimPDFFrame1.PdfURL := dm.GenRep(InvNum)
  finally
    dm.Free;
  end;
end;

Is there anything else I need to do before sharing?

 

Regards.

×
×
  • Create New...