-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCode.gs
More file actions
52 lines (44 loc) · 1.48 KB
/
Code.gs
File metadata and controls
52 lines (44 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function onOpen() {
DocumentApp.getUi().createMenu("Page Sizer by Adam Natad")
.addItem('Start', 'openSizeDialog')
.addItem('Guide', 'showGuideDialog')
.addToUi();
}
function onInstall(e) {
onOpen(e);
}
function openSizeDialog() {
const html = HtmlService.createHtmlOutputFromFile('PageSizeDialog')
.setWidth(450)
.setHeight(600);
DocumentApp.getUi().showModalDialog(html, "Page Sizer by Adam Natad");
}
function showSuccessDialog() {
const html = HtmlService.createHtmlOutputFromFile('SuccessDialog')
.setWidth(300)
.setHeight(170);
DocumentApp.getUi().showModalDialog(html, 'Page Applied');
}
function showGuideDialog() {
const html = HtmlService.createHtmlOutputFromFile('GuideDialog')
.setWidth(600)
.setHeight(530);
DocumentApp.getUi().showModalDialog(html, 'Guide for Page Sizer by Adam Natad');
}
function setCustomPageSizeAndMargins(data) {
const doc = DocumentApp.getActiveDocument();
const body = doc.getBody();
const factor = data.unit === 'cm' ? 28.3465 : 72;
const widthPts = data.width * factor;
const heightPts = data.height * factor;
const marginTop = data.marginTop * factor;
const marginBottom = data.marginBottom * factor;
const marginLeft = data.marginLeft * factor;
const marginRight = data.marginRight * factor;
body.setPageWidth(widthPts);
body.setPageHeight(heightPts);
body.setMarginTop(marginTop);
body.setMarginBottom(marginBottom);
body.setMarginLeft(marginLeft);
body.setMarginRight(marginRight);
}