0
 let shareActivity = UIActivityViewController(activityItems: [page.dataRepresentation], applicationActivities: nil)
 if UIDevice.current.isIpad() {
     shareActivity.popoverPresentationController?.sourceView = self.homeController.view
     shareActivity.popoverPresentationController?.sourceRect = CGRect(
                    x: self.homeController.view.bounds.size.width / 2,
                    y: self.homeController.view.bounds.size.height,
                    width: 0,
                    height: 0
                )
            }

     shareActivity.completionWithItemsHandler = { _, _, _, _ in
      }


     self.homeController.present(shareActivity, animated: true)

I use pdfkit, no matter from page.dataRepresentation or document.dataRepresentation, I cannot share PDF.

What do I need to do to share directly without saving the file locally, then [path.url]

swifter
  • 1
  • 1
  • Not sure if you can do that - tried everything some time ago and eventually reverted to the share from local file as I could not manage to share directly. – skaak Dec 30 '20 at 04:41
  • Hello, I tried to save it locally, but I use pdfkit to get every page of the pdf file. I found that every page of pdf will be overwritten when using outputStream. All data must be saved at once. A complete PDF, but this will cause too much memory, I want to save page by page – swifter Dec 30 '20 at 08:13
  • Ok - I thought you had trouble sharing data directly without first saving to file and that is what my comment refers to. I don't know pdfkit, but if you have access to outputStream I think you could do it. What do you mean when you say using outputStream? Show that code. – skaak Dec 30 '20 at 09:38
  • Thank you for your reply, I did have trouble sharing the document directly using native Using OutputStream was also unsuccessful. The idea is this let outPutStream = OutputStream(toFileAtPath: tempPath, append: true) Then traverse the data of each page and write one by one outPutStream?.write(data: data) Finally closed outPutStream?.close() I found that the local file PDF only has the last page, but the number of data is the same as the original size, which is a headache – swifter Dec 31 '20 at 02:18
  • I am not sure you can append pages like that to a (binary) pdf. https://stackoverflow.com/questions/50195842/how-to-implement-a-pdf-viewer-that-loads-pages-asynchronously – skaak Dec 31 '20 at 05:27

0 Answers0