I'm creating a Google Doc to HTML converter, I want to use the Doc Api and not export it as HTML using the Drive Api :
$service = new Google_Service_Docs($client);
$request = $service->documents->get($docId);
$elements = $request->getBody()->getContent();
$elements is an array of Google_Service_Docs_StructuralElement
Looping through paragraph > elements, if there is an inline object, the inlineObjectElement property is set with a Google_Service_Docs_InlineObjectElement
Question is : how to get the content of an Google_Service_Docs_InlineObjectElement to save it as a file ? All we have in this object is an inlineObjectId...
This update gives you the option to choose to create a new Google Doc, Google Sheets, or Google Slides or attach an existing document to your project. Once your document is attached, you can draft, edit, and comment on your content right inside your project by choosing “Edit Inline.”
Yes it can be set up that way as long as you do not choose the option to "Disable" downloads.
I was able to find a solution for this on this blog post.
Basically, all inline elements are located at:
$inlineObjects = $request->getInlineObjects();
Btw. I recommend renaming "$request" to "$document"
Now, with the inlineObjectId you can get the particular object you want - and there, you get a contentUri which contains the binary content.
Here, a screenshot of $inlineObjects
contents, which is an assoc array. The key is the inlineObjectId:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With