I’m trying to figure out if it’s possible to download a Google Docs file through the Drive API, make some changes to it (like adding highlights to certain text parts), and then upload it back while keeping the original formatting intact so it still works in Google Docs.
I already looked into using Google Apps Script but I need this to work offline. I also checked the export options in the Drive API but there doesn’t seem to be a way to import modified files back.
From what I can see, there are some roadblocks:
The file metadata from Drive API doesn’t include a direct download link
When working offline, the cached files are in binary format that can’t be easily identified
Does anyone know if the current Drive API supports this kind of workflow? Or am I stuck with the limitations?
Indeed, you’ve encountered a significant limitation of the Drive API. Google Docs employs a unique formatting structure that the API does not support for direct edits. While you can export documents, re-uploading them as editable Docs while retaining original formatting is not feasible. The available options like DOCX and PDFs work well, but they’re limited in terms of Google Docs capabilities. Ultimately, you might consider exporting to DOCX, editing it, and then creating a new Google Doc. However, this may result in some loss of specific formatting and features that are exclusive to Google Docs.
This is one of those frustrating cases where Google’s architecture just doesn’t play nice with what you’re trying to do. The problem is Google Docs uses its own proprietary format that’s totally different from standard stuff like DOCX or ODT. When you export via API, you’re getting a translation - not the actual document structure. I’ve spent tons of time with the Drive API and there’s just no clean way to roundtrip a Google Doc without losing stuff. Your best bet is the Docs API for programmatic edits, but that needs internet access so it won’t work offline. You could also export to DOCX and accept that formatting will get messed up when you import back - plus you’ll lose comments and collaborative features completely.
this is pretty much a dead end with current api limits. google docs format is locked down - you can’t hack around it offline. I’d try a different approach: use pandoc to convert between formats if you really need offline editing. just expect formatting issues when you sync back to docs.