0

There is an image in Google Sheet (coming from Google Form) that I would like to insert in Google Doc in Image Format. Currently, I'm getting Url only from the below mention script. How can I get the image. This is the script-

function afterFormSubmit(e) {
  const info = e.namedValues;
  createPDF (info);

}

function createPDF(info){
   
  const pdfFolder = DriveApp.getFolderById("1I7ChP1xRbl7GwnvAcXV_9JIHegvsU2PO");
  const tempFolder = DriveApp.getFolderById("1srcXlFgmh01e4Psw_dxM4bNgarY6tfli");
  const templateDoc = DriveApp.getFileById("1xype5jUa6H8VJ4JSaV-KfccSjK5w6e-hmoI1k6MXSOc");

  const newTempFile = templateDoc.makeCopy(tempFolder);
  const openDoc =  DocumentApp.openById(newTempFile.getId());
  const body = openDoc.getBody();
  body.replaceText("{Location Code}",info['Location Code'][0]);
  body.replaceText(" {Timestamp}",info['Timestamp'][0]);
  body.replaceText( " {Upload Image}",info['Upload Image'][0]);
  
  openDoc.saveAndClose();

  const blobPDF = newTempFile.getAs(MimeType.PDF);
  const pdfFile = pdfFolder.createFile(blobPDF).setName(info['Location Code'][0]+"-"+new Date());
  tempFolder.removeFile(newTempFile);
  /** @type {any} */

}

Google Doc Format

Currently getting data like this

Google sheet input sheet via Google Form

3
  • Please show what you tried regarding inserting an image to a Google Doc and a brief description of your search efforts as is suggested in How to Ask. – Rubén Apr 7 at 16:55
  • @Rubén I am trying to insert an image(images are coming from Google Form-I have their link in google sheet-pic attached above) into a Google doc. I have {Upload image} text in the position where I want to insert the image(pic attached above. Currently, I'm using this(full script attached above)- body.replaceText( " {Upload Image}",info['Upload Image'][0]); - As I'm new to this scripting I don't know what changes I need to do to get image from Url to Google doc – Anvita Singh Apr 8 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.