Attach a PDF File to Email - Swift

Attach a PDF file to email - Swift

You are passing wrong mimeType to addAttachmentData(). Use application/pdf instead of pdf.

Attached PDF to email in Swift, but the PDF is not decoded

OK, I figured it out. Dropbox URLs, at least for PDFs if not everything, include a dl=0 tag to indicate downloading permission. In order to send a PDF through an app, you have to change the dl=0 to dl=1. Then everything works as it should.

So there would be no change to the code above. The change is in my Parse browser where I list my files.

Eli

Attach the pdf file into mail automatically after saving

The Swift 3.0 code below is worked great!

let pdfFilePath = "path to file.pdf"
let url = NSURL.fileURL(withPath: pdfFilePath)
let activityVC = UIActivityViewController(activityItems: ["My Pdf File",url], applicationActivities: nil)
self.present(activityVC, animated: true, completion: nil)

swift pdf file not attaching to an email

Because your file is put into the user's temporary folder, I do not think it will be accessible from the a NSBundle method. That said, if you are writing the NSData to disk in the temporary folder and then directly emailing it, you may want to consider just passing that variable (pdfData) to the mail controller like:

mail.addAttachmentData(pdfData, mimeType: "application/pdf", fileName: "file.pdf")


Related Topics



Leave a reply



Submit