cancel
Showing results for 
Search instead for 
Did you mean: 
Announcements
Update: Find information on Dropbox support during COVID-19 here
Close
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

convert downloaded pdf file to human readable string

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
Highlighted

Re: convert downloaded pdf file to human readable string

Dropboxer
Dropboxer
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.
Highlighted

Re: convert downloaded pdf file to human readable string

Helpful | Level 6
ok. Thanks again Greg

Work Smarter with Dropbox

The way we work is changing. Share and discover new ways to work smarter with Dropbox in our community.

Sound good? Let's get started.
Who's talking

Top contributors to this post

What do Dropbox user levels mean?
Need more support?