Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Open PDF with Acrobat Reader in iOS


This question is answered. Helpful answers available: 1. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Dec 29, 2016 11:37 AM Last Post By: Maxime Bonin
Maxime Bonin

Posts: 61
Registered: 1/23/17
Open PDF with Acrobat Reader in iOS  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2016 1:28 PM
I'm building an iOS app. It receives a PDF via app tethering. I to want make this PDF open with Acrobat Reader as soon as it is received.

I've tried the posix command
_sytem(PAnsiChar('open ' + AnsiString(sCommand)));
but 'PAnsiChar' and 'AnsiString' doesn't seem to be accepted in a mobile environment ...

Anyone knows how to make this happen ?

Edited by: Maxime Bonin on Dec 23, 2016 2:32 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Open PDF with Acrobat Reader in iOS [Edit]
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 23, 2016 3:12 PM   in response to: Maxime Bonin in response to: Maxime Bonin
Maxime wrote:

I've tried the posix command

_sytem(PAnsiChar('open ' + AnsiString(sCommand)));


but 'PAnsiChar' and 'AnsiString' doesn't seem to
be accepted in a mobile environment ...

Nope, because they have been intentionally disabled (you can re-enable them
with an RTL patch: http://andy.jgknet.de/blog/2015/09/byte-strings-for-delphi-10-seattles-mobile-compilers/).

Anyone knows how to make this happen ?

Use MarshaledAString instead:

_system(MarshaledAString('open ' + sCommand));


Alternatively, use iOS's NSWorkspace.openURL() method instead:

var
  URL : NSURL;
  Workspace : NSWorkspace;
begin
  URL := TNSURL.Wrap(TNSURL.OCClass.URLWithString(StrToNSStr(sCommand)));
  Workspace := TNSWorkspace.Wrap(TNSWorkspace.OCClass.sharedWorkspace);
  Workspace.openURL(URL);
end;


--
Remy Lebeau (TeamB)
Maxime Bonin

Posts: 61
Registered: 1/23/17
Re: Open PDF with Acrobat Reader in iOS [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2016 5:10 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thanks

I succeeded to reactivate the Ansi string and pointers in XE8 !

But I didn't succeed using the '_system' command. Not even with a standard Url like 'http://www.google.com' (doesn't open in Safari) ...

I tried the standard '
_sytem(PAnsiChar('open ' + AnsiString(sCommand)));
' and I've looked online (stackoverflow) where someone suggest to add 'UTF8String'

Here is what I did : via App Tethering's procedure 'ResourceReceived', I receive a Stream containing a PDF file. I get the the iOS' filepath and put it in a member variable :

FLastFileReceivedFilePath := TPath.Combine(TPath.GetTempPath, 'myDoc.pdf');


and :

_system(PAnsiChar(UTF8String('open ' + 'file://' + FLastFileReceivedFilePath)));


the other code with the 'workspace' didn't work either ...

I've succeeded doing what I wanted in Android (opening a PDF in Acrobat Reader) but not in iOS. This excerpt from the book Delphi Cookbook sums up my experience :

''However, Android and iOS users don't have the same user experience.
On Android, you can use whatever app you have i nstalled on the device to show the PDF, so
you can also change the file with annotations, highlights, and by drawing directly on the file.
Note that the file is also readable from other apps. This can be a problem in some situations.
On iOS, conversely, you cannot modify the PDF with annotations and so on. You also don't
have full control on the file and the file remains "private" for your app. These facts must be
carefully analyzed and you have to be aware of the pros and cons about every choice you
make. If you want to provide a uniform set of functionalities, additional work and third-party
components and libraries will be needed.'' Daniel Teti, Delphi Cookbook, 2nd edition, p. 290


Remy Lebeau (TeamB) wrote:
Maxime wrote:

I've tried the posix command

_sytem(PAnsiChar('open ' + AnsiString(sCommand)));


but 'PAnsiChar' and 'AnsiString' doesn't seem to
be accepted in a mobile environment ...

Nope, because they have been intentionally disabled (you can re-enable them
with an RTL patch: http://andy.jgknet.de/blog/2015/09/byte-strings-for-delphi-10-seattles-mobile-compilers/).

Anyone knows how to make this happen ?

Use MarshaledAString instead:

_system(MarshaledAString('open ' + sCommand));


Alternatively, use iOS's NSWorkspace.openURL() method instead:

var
  URL : NSURL;
  Workspace : NSWorkspace;
begin
  URL := TNSURL.Wrap(TNSURL.OCClass.URLWithString(StrToNSStr(sCommand)));
  Workspace := TNSWorkspace.Wrap(TNSWorkspace.OCClass.sharedWorkspace);
  Workspace.openURL(URL);
end;


--
Remy Lebeau (TeamB)

Edited by: Maxime Bonin on Dec 29, 2016 5:14 AM
Eli M

Posts: 1,346
Registered: 11/9/13
Re: Open PDF with Acrobat Reader in iOS [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2016 7:24 AM   in response to: Maxime Bonin in response to: Maxime Bonin
http://www.fmxexpress.com/create-view-and-open-pdfs-in-other-apps-with-delphi-xe8-firemonkey-on-ios/

uses
{$IFDEF IOS}
,iOSapi.Foundation, FMX.Platform.Ios, iOSapi.UIKit, Macapi.Helpers
{$ENDIF}
//
public
FController : UIDocumentInteractionController;
//
procedure TFPDFExport.FormCreate(Sender: TObject);
begin
FController := TUIDocumentInteractionController.Wrap(
TUIDocumentInteractionController.Alloc.init);
end;
//
procedure TFPDFExport.OpenIn(path: string);
{$IFDEF IOS}
var
URL: NSURL;
DPFBarItem: UIBarButtonItem;
success : Boolean;
{$ENDIF}
begin
{$IFDEF IOS}
URL := TNSUrl.Wrap(TNSUrl.OCClass.fileURLWithPath(StrToNSStr(path)));
FController.setURL(URL);
FController.setUTI(StrToNSStr('com.adobe.pdf'));
DPFBarItem := self.DPFToolbar1.BarItems[1].DPFBarItem;
success := FController.presentOptionsMenuFromBarButtonItem(
DPFBarItem , True);
{$ENDIF}
end;


Also:

A) Open it via a Share Sheet
http://docwiki.embarcadero.com/CodeExamples/Berlin/en/FMX.ShareSheet_Sample

B) Open it via an Action Sheet
https://www.tmssoftware.com/site/forum/forum_posts.asp?TID=2800&PID=9745&SID=57a2455c-d574-5f7925aa-c1f22db6-bbeb35b2&title=v15-actionsheet-demo

C) Open it in TWebBrowser
Maxime Bonin

Posts: 61
Registered: 1/23/17
Re: Open PDF with Acrobat Reader in iOS  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 29, 2016 11:37 AM   in response to: Maxime Bonin in response to: Maxime Bonin
frm := TForm.CreateNew(nil);
 
         btn := TButton.Create(frm);
         btn.Parent := frm;
         btn.Align := TAlignLayout.Top;
         btn.Text := 'Close';
 
         btn.OnClick := OnButtonClick;
         WebBrowswer := TWebBrowser.Create(frm);
 
         WebBrowswer.Parent := frm;
         WebBrowswer.Align := TAlignLayout.Client;
 
         WebBrowswer.Navigate('file://' + FLastFileReceivedFilePath);
         frm.Show;
 


Works perfectly (Delphi XE8, XCode 8, iPad 9.3)
Code published in Daniel Teti, Delphi Cookbook. It opens the PDF in a WebBrowser. It doesn't work for my purpose because I want to be able to modify the PDF (fill a form + add signatures) with Acrobat Reader.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02