How to compress photo

I am using appscript to turn on the trigger from google sheet to convert to PDF and email to user straightway. and there’s image I include in the page.
As in the google sheet, this is the page looks like:

and after the script running:


var changedFlag = false;

var TEMPLATESHEET=‘Boom-Report’;

function emailSpreadsheetAsPDF() {

// Utilities.sleep(3000); //to pause for 3 seconds . Make sure photo completely upload to google sheet



// This is the link to my spreadsheet with the Form responses and the Invoice Template sheets

// Add the link to your spreadsheet here

// or you can just replace the text in the link between “d/” and “/edit”

// In my case is the text: 17I8-QDce0Nug7amrZeYTB3IYbGCGxvUj-XMt8uUUyvI

const ss = SpreadsheetApp.openByUrl(“”);

// We are going to get the email address from the cell “B7” from the “Invoice” sheet

// Change the reference of the cell or the name of the sheet if it is different

const value = ss.getSheetByName(“Source Email-Boom”).getRange(“X3”).getValue();

const email = value.toString();

// Subject of the email message

const subject = ss.getSheetByName(“Source Email-Boom”).getRange(“B3”).getValue();

// Email Text. You can add HTML code here - see

const body = “Boom Lifts Inspection Report - Sent via Auto Generate PDI Report from Glideapps”;

// Again, the URL to your spreadsheet but now with “/export” at the end

// Change it to the link of your spreadsheet, but leave the “/export”

const url = '’;

const exportOptions =

'exportFormat=pdf&format=pdf' + // export as pdf

'&size=A4' + // paper size letter / You can use A4 or legal

'&portrait=true' + // orientation portal, use false for landscape

'&fitw=true' + // fit to page width false, to get the actual size

'&sheetnames=false&printtitle=false' + // hide optional headers and footers

'&pagenumbers=false&gridlines=false' + // hide page numbers and gridlines

'&fzr=false' + // do not repeat row headers (frozen rows) on each page

'&gid=671631174'; // the sheet's Id. Change it to your sheet ID.

// You can find the sheet ID in the link bar. 

// Select the sheet that you want to print and check the link,

// the gid number of the sheet is on the end of your link.

var params = {method:“GET”,headers:{“authorization”:"Bearer "+ ScriptApp.getOAuthToken()}};

// Generate the PDF file

var response = UrlFetchApp.fetch(url+exportOptions, params).getBlob();

// Send the PDF file as an attachement

GmailApp.sendEmail(email, subject, body, {

  htmlBody: body,

  attachments: [{

        fileName: ss.getSheetByName("Source Email-Boom").getRange("B3").getValue().toString() +".pdf",

        content: response.getBytes(),

        mimeType: "application/pdf"



// Save the PDF to Drive. (in the folder) The name of the PDF is going to be the name of the Company (cell B5)

const nameFile = ss.getSheetByName(“Source Email-Boom”).getRange(“B3”).getValue().toString() +".pdf"

const folderID = “1ZKWq9jWmeEQlxncuTPHssCFXC3Fidmxn”;



function on_sheet_change(event) {

var sheetname = event.source.getActiveSheet().getName();

var sheet = event.source.getActiveSheet();

if (sheetname == ‘Boom-Report’) {

emailSpreadsheetAsPDF() ;

} else return;


This is the PDF looks like:

Turn up only half .

And i believe, this is because the image so large. So, how to compress ?

1 Like

Appreciated if you guys can help me

I’m not really sure but maybe you could try to run the utilities.sleep(3000)

Right now it is commented out. Take away the //

1 Like

but sleep is to delay. all i need is to compress the photo right .
Like what for to delay ?

@Eric_Penn was suggesting that perhaps the PDF is being generated before the images have fully loaded into the template. Your screenshot supports this, as only one image is partially shown. So I suspect he is probably right.

Why don’t you give his suggestion a try?
You never know, it might work…

Yes, i have tried this . Its not work. Same things happen. It turns up half of the image.
That’s why I put the // .

I’d still suspect the same problem. Maybe the delay isn’t long enough.
I can see that you are using an onChange trigger, which means the script will fire as soon as the first change is made in the sheet. Try a longer delay. Try adding a sleep for a full minute.

Ok i try Utilities.sleep(60000) now , will come back here

Still got this
@Darren_Murphy @Eric_Penn

I noticed that, even if I download manually through google sheet, same thing happen.

My appscript experience is limited. You could try adding
SpreadsheetApp.flush(); before the utilities.sleep

Noted, i am trying . will come back.

I’ve tried , PDF Ffiles looks the same, only half appear. Not even half .
But i noticed after adding SpreadsheetApp.flush(); the file size larger.
Now was 19MB, before adding was like 11MB.

Is there any ways to compress photo from the time that user adding up the photo on Glide itself.
As you know, Whatsapp apps also auto compress the image size. Well, now my user only upload for like 10-15 forms which need photos but the usage of Image & Files near 1 GB.


any ways to auto compress photo ???

@biha there is no compressing of the uploaded image to glide possible, I’m afraid.

But if you are ok to store the image outside glide then you could use cloudinary and still use the image picker in glide to get hold of the users image.

I have done a similar thing as shown in this post

Thanks @Krivo , let me read the threads .

@Krivo , I’m back

  1. I’ve change the Folder Name and Cloud Name

  1. What the location is for ? Naming the photo am i right ?

  1. When I click button “Add Image and Location”, still cannot see the image like you do.

@biha you do not need any location info. It was for another use case that somebody had.

Please check that you gave the correct address of the images in glide.

This is how you find the correct address of the images uploaded to glide

I’m sorry, but where to place the address of the images in Glide?

Here, correct?