Is there a way to set the Google Doc page layout to landscape using App Script.
I have a script that copies the Google Spreadsheet table to Google Doc but its too wide to display properly. If I could change the layout to landscape it will display properly.
It also seems as though the page width is the same number regardless of whether the page is oriented portrait or landscape.
Another problem is if I body.setPageWidth(792).setPageHeight(612) for letter, it changes the page width and height but does not change to landscape.
I believe your goal is as follows.
Unfortunately, it seems that in the current stage, the Document service (DocumentApp) cannot achieve this. But, fortunately, when Google Docs API is used, this can be achieved. In this case, how about the following sample script?
Before you use this script, please enable Google Docs API at Advanced Google services.
function myFunction() {
const docId = DocumentApp.create("sampleFilename").getId(); // or please manually set the document ID.
Docs.Documents.batchUpdate({ requests: [{ updateDocumentStyle: { documentStyle: { flipPageOrientation: true }, fields: "flipPageOrientation" } }] }, docId);
}
flipPageOrientation: true
.flipPageOrientation: false
.