I'm reading a Google Doc with landscape orientation using the Google Drive API v3, and trying to replace a few words in the doc with something else.
For example, if the document contains "Text_to_replace" I search for that string and replace that by "Hello World!"
But every time I update the Google document's content using the Google Drive API, the document's orientation always changes to portrait. Even when the document's orientation was originally set to landscape.
I'm not adding code to this post since I'm able to replicate this issue using any http client (like https://www.hurl.it/)
Here's how to replicate the issue:
I) Setting up the document
In order to replicate the issue, you need a document with orientation = landscape.
II) What the code is doing
1) We first log in through the API using Service Account (https://developers.google.com/identity/protocols/OAuth2ServiceAccount)
2) We get the FileResource instance of the document (https://developers.google.com/drive/v3/reference/files/get)
3) We get the HTML export of the file (GET HTML request to https://docs.google.com/feeds/download/documents/export/Export?id=(document id)&exportFormat=html)
4) We replace some words in the document's HTML (for example, we replace the text "Text_to_replace" by "Hello World!")
5) We make an update through the API.
https://www.googleapis.com/upload/drive/v3/files/(document id)?uploadType=media
User-Agent apex-google-api
Authorization Bearer (service account authentication token)
Content-Type text/html
This is when the document loses the landscape orientation (it's changed to portrait)
I've tried to only do the update, skipping steps 2 to 4, and I still see the issue (orientation goes to portrait).
Maybe the problem is that I'm sending the entire HTML back to the document when updating? Is there a way to update the document's content without losing the orientation?
Thanks in advanced