cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

convert downloaded pdf file to human readable string

convert downloaded pdf file to human readable string

bbongrip
Helpful | Level 6

Im downloading a pdf file from dropbox that I've previously saved to dropbox, created progamatically using HTML Markup. (which is working fine).  But I then want to convert the pdf file to a human readable String so that I can gather specific info from that string.  heres what i've been trying but its not giving me a human readable string.

 

/** Download pdf file from dropbox **/
        
        // Verify user is logged into Dropbox
        if let dropboxClient = DropboxClientsManager.authorizedClient {
            
            // Download File from Dropbox
            let filename = ((cell?.textLabel?.text)! + ".pdf").lowercased()
            print(filename)
            
            dropboxClient.files.download(path: "/\(filename)").response { response, error in
                
                if let response = response {
                    let responseMetadata = response.0
                    print("dropbox responseMetadata: \(responseMetadata)")
                    let fileContents = response.1 as NSData
                    print("dropbox fileContents: \(fileContents.description)")
                    
                    let encodedFile = String(data: fileContents as Data, encoding: String.Encoding.ascii)
                    
                    print("ACTUAL FILE: \(encodedFile?)")
                    
                } else if let error = error {
                    print("dropbox error: \(error)")
                }
            }
        }

I believe Im having trouble using the proper String.encoding, but i've tried most of them and nothing seems to work.  Any help is much appreciated. Thanks

 

2 Replies 2

Greg-DB
Dropbox Staff
It sounds like the Dropbox portion of this is working properly, so I'm afraid I can't offer much insight.

That is, the PDF data is getting downloaded, and how your app handles that data is up to you. PDF data isn't necessarily human-readable though, so this may not just be a matter of encoding string properly. I recommend reading about the PDF format to see how you can extract the information you're looking for.

bbongrip
Helpful | Level 6
ok. Thanks again Greg
Need more support?
Who's talking

Top contributors to this post

  • User avatar
    bbongrip Helpful | Level 6
  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?