Google Drive API不会转换为PDF

时间:2017-05-25 16:41:30

标签: swift google-drive-api pdf-generation

我正在尝试使用files.export将Google Doc文件转换为pdf。我按照指南here进行了操作,但文件只会下载为Word文档。我需要做些什么来解决这个问题?我的代码如下:

func downloadFromDrive(fileID: String) {
    print("About to execute Drive export query for file with id: \(fileID)")
    let query = GTLRDriveQuery_FilesExport.queryForMedia(withFileId: fileID, mimeType: "application/pdf")
    driveservice.executeQuery(query,
                              delegate: self,
                              didFinish: #selector(processDownloadedPDF(ticket:finishedWithObject:error:))
    )
}

func processDownloadedPDF(ticket: GTLRServiceTicket,
                          finishedWithObject file: GTLRDataObject,
                          error : NSError?) {
    if let error = error {
        print("Drive Download Error: \(error)")
        self.navigationController?.navigationBar.stop()
        let alert = UIAlertController(title: "Google Drive Download Error", message:
            "Oops - Something went wrong! Error \(error.code): \(error.localizedDescription)", preferredStyle: .actionSheet)
        alert.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in
        }))
        self.present(alert, animated: true, completion: nil)
        return
    }

    self.navigationController?.navigationBar.stop()
    print("Drive Download Worked")
    //Process downloaded file
    return
}

0 个答案:

没有答案