I'm supposed to test PSPDFKit in a way that lets the user open a locally saved pdf file.
For this i require the files url(e.g. path, i guess). How can i let the user pick a local document?
Can anybody help me out?
I'm using storyboard and swift.
You can present a PDF document in PSPDFKit using the PDFViewController like so:
// Create the `Document`.
let fileURL = Bundle.main.url(forResource: "Document", withExtension: "pdf")!
let document = Document(url: fileURL)
// Create the PDF view controller.
let pdfController = PDFViewController(document: document)
// Present the PDF view controller within a `UINavigationController` to enable the toolbar.
present(UINavigationController(rootViewController: pdfController), animated: true)
For more details, take a look at the following guide here.
Also, to present a document that your end-user has selected, consider using a document picker or a file browser. Please refer to DocumentPickerSidebarExample.swift from Catalog and SwiftUI Document Browser for runnable example projects.
In the future, please reach out to our support portal at pspdfkit.com/support/request/ - we're happy to provide support there for our commercial SDK.
We are trying to use SFSafariViewController to browse a Word document from our iOS Mobile app using Swift as it gives ReaderView and Font Increase/Decrease within the App. Everything works as expected on the Simulator with 12.2 ios version, however when we published the changes to TestFlight and started using the app on a real phone ios 13.0 version the SFSafariViewController shows the FileName and says "Open in 'Dropbox' 'More... '"
https://i.stack.imgur.com/R595d.jpg
we want to disable/remove that option to choose different apps to open the word/pdf docs and display the content directly within the app. Would greatly appreciate if someone can help remove this option and directly display the documents like below.
https://i.stack.imgur.com/EhFec.png
Below is the code. Can someone please help how to resolve this issue?
func openGuidelineSafari(passedURL: String) {
let allowedCharacterSet = CharacterSet(charactersIn: " ").inverted
let escapedString = passedURL.addingPercentEncoding(withAllowedCharacters: allowedCharacterSet)
let url = URL (string: (escapedString!))
let config = SFSafariViewController.Configuration()
config.entersReaderIfAvailable = true
let vc = SFSafariViewController(url:url!, configuration: config)
vc.delegate = self
present(vc, animated: true)
}
I'm sharing a PDF using the built in Share activity action sheet using the following code:
if let pdf = pdfData {
let vc = UIActivityViewController(activityItems: [pdf], applicationActivities: [])
if (vc.responds(to: #selector(getter: popoverPresentationController))) {
vc.popoverPresentationController?.sourceView = btnShare;
}
self.present(vc, animated: true)
} else {
showTextAlertWithImage...
...
}
When the sharing popover is displayed, tapping on Airdrop and sharing to a nearby computer the PDF everything works as expected.
But if I choose Mail from the sharing list the PDF is blank. Does anyone please know why?
It's the same PDF that's being shared in both situations. If it matters, the mail account is an Outlook account.
Sharing the PDF through the Gmail app also produces the correct PDF, however the attachment does not include the '.pdf' file extension.
Check how to add Content Type to your activity item you are sharing.
When i open an attachment from iPhone or iPad mail application, there is a popup that can transfert the file to a third party application.
This iOS popup is called UIActivityViewController.
I wand to add my own iOS application (written in swift) in this popup and i do not know how to do...
Thanks
I believe you are asking about two separate things.
UIActivityViewController:
Here's my code in my app.
let vc = UIActivityViewController(activityItems: [shareImage], applicationActivities: [])
vc.excludedActivityTypes = [
UIActivityType.airDrop,
UIActivityType.assignToContact,
UIActivityType.addToReadingList,
//UIActivityType.copyToPasteboard,
//UIActivityType.mail,
//UIActivityType.message,
//UIActivityType.openInIBooks,
//UIActivityType.postToFacebook,
//UIActivityType.postToFlickr,
UIActivityType.postToTencentWeibo,
//UIActivityType.postToTwitter,
UIActivityType.postToVimeo,
UIActivityType.postToWeibo,
UIActivityType.print,
//UIActivityType.saveToCameraRoll
]
present(vc,
animated: true,
completion: nil)
vc.popoverPresentationController?.sourceView = self.view
vc.completionWithItemsHandler = {(activity, success, items, error) in
}
Pay attention to the excludedActiviyTypes code. My app is an image effect app, so I commented out the things I wish to have in the popup - Weibo, print, assignToContact, ReadingList, Vimeo, and TencentWeibo. Here's the thing - I kept the full list of activities for quick reference. (I've never found it on ADC and end up getting it by using code complete.)
UIActivityType is an extended struct, so if you want to go the route of using it this way I think you'll have to (1) subclass UIActivityViewController, (2) write your own extension to UIActivityType, and (3) provide any/all code needed to use a service that isn't listed above.
A Document Provider is what I think you are looking for. Either that, or Universal - sometimes called Deep - Linking. (The links are to Apple documentation for using each.)
I've obviously used UIActivityiewController, but haven't (yet) had any need to these other two.
If you have questions about setting up a UIActivityViewController, post them in the comments. If someone else has a way to "extend" it in any way other than I described, let me know and I'll remove this answer.
I am using the following code to share text using iOS sharing extension (UIActivityViewController).
let vc = UIActivityViewController(activityItems: ["File URL"], applicationActivities: [])
presentViewController(vc, animated: true, completion: nil)
It shows a popup to share using text sharing applications like following:
But, I want the sharing app portion in my view into a page control like below:
How can I do this? If there is any alternative way to achieve this requirement, kindly suggest.