I'd like to insert image in the Google document by using Google Apps Script, and to spread it (the image) to the width of the page - margins or to insert it in the table cell and spread it to the width of the cell.
The code goes like this:
var image = DriveApp.getFileById(fileId).getBlob();
var insertPlace = body.findText(searchText).getElement();
insertPlace.asText().setText("");
var insertedImage = insertPlace.getParent().asParagraph().insertInlineImage(0, image);
var h = insertedImage.getHeight();
var w = insertedImage.getWidth();
insertedImage.setWidth(width).setHeight(width * h / w);
And where is the problem?
width!
How to find width of the table cell or body?
I have tried with
var width = insertPlace.getParent().asParagraph().asTableCell().getWidth();
but got null although cell is in the single column of the table, and table takes all the width of the page-margins.
Anyone got the idea about how to get width of the cell?
Also, how to get page width, margins etc...
UPDATE
I have discovered that the issue must be with the Google code about this. Actually, they have made differently handling with tables in slides compared to document:
https://developers.google.com/apps-script/reference/slides/table-cell https://developers.google.com/apps-script/reference/document/table-cell
In slides version there is, for example, getParentColumn(), which is not available for the document... any many similar discrepancies.
What are doing these guys at Google?!?!?