Saving and sharing a pdf

I’m experimenting with creating and saving a pdf in IOS with the following but I can’t find it on my device when it is Saved. I was assuming Documents is the “File” folder but not there?? I’m not getting errors and the Debugger shows there is data in d

Var d As New PDFDocument
Var g As Graphics = d.Graphics

Var f As FolderItem = SpecialFolder.Documents.Child("Demo.pdf")

g.Font = Font.BoldSystemFont(24)
Const tHL As String = "Demo"

g.DrawText(tHL,10,40)
g.DrawLine(10,45,g.TextWidth(tHL)+10,45)

Const tBD As String = "This is a DEMO:"

g.Font = Font.SystemFont(12)
g.DrawText(tBD, 10, 70,400)

Const kFirstLinkText As String = "• Click to go to Location"
g.DrawingColor = Color.Blue
Var tHeight As Double = g.TextHeight

for x as Integer = 0 to locations.LastIndex
  g.DrawText(kFirstLinkText,10,120+x*20)
  var a as String = "https://www.google.com/maps/search/?api=1&query="+ locations(x).Latitude.ToString + "," + locations(x).Longitude.ToString '36.26577,-92.54324
  // Let's add the first Link, setting the area to surround the text of the "kFirstLinkText"
  d.AddLinkArea(a,10,110+x*20,g.TextWidth(kFirstLinkText), tHeight)
next x

Try
  d.Save(f)
  //mypdfgame = f.OpenAsCGPDFDocumentMBS
  
Catch e As IOException
  System.DebugLog(e.Message)
End Try

Annoyingly, on iOS,
The ‘Documents’ folder that your app sees and uses is not the global ‘Documents’ that you might expect.
Every iOS app gets its own Documents folder.

To date, I haven’t worked out how to access the ‘big’ one, but there must be a way, as other apps do it.
‘Your’ documents folder is accessible by the user if they plug the device into a Mac and look at it as if it were an external drive, using Finder.

Raw Xojo apps do not support iCloud, Airdrop or similar.
By telling Apple that your app supports file sharing, you get the ability to copy to and from using Finder. I’ll post the instructions below.

You can also offer up a sharing panel for the PDF file. That allows the user to email the PDF to themselves, (plus whatever else Apple allow on that option, such as Markup)

I suspect that Jeremie’s iOS Kit contains something that will help, as it is a tremendous body of work
*(which should long ago have been part of Xojo’s iOS implementation, IMO. )

1 Like

Copying files to and from your app’s Documents folder:
(In this example, an app called MobiStitch)

Sharing documents. (Mac)

  1. Open a Finder window.
  2. Connect your iPad to your computer with a USB cable.
  3. Select your device in the Finder. Learn what to do if your computer doesn’t recognise your device.
  4. Click the Files tab to see a list of apps that can share files.
  5. Click the triangle next to MobiStitch to see saved files.
  6. mobifilecopy
1 Like

If I can’t see the file on the device to use airdrop would the only way to share a file your app has created is to email it as an attachment?

It’s how I do it.

Apparently…

The UIActivityViewController class bundled in the iOS SDK makes it easy for you to embed AirDrop into your apps…All you need to do is tell the class the objects you want to share and the controller handles the rest

UIActivityViewController is mentioned in the iOSKit.

What appears to be Swift(?) code:

let objectsToShare = [fileURL]
let activityController = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
present(activityController, animated: true, completion: nil)

Again, if it’s this ‘simple’, it really should be a standard part of Xojo’s iOS implementation by now, shouldn’t it?

I’ll have a play with this later on myself.

I see jeremie had fun with this in the past:

1 Like

I created a GitHub project for iCloud earlier this year:

2 Likes