0

How to remove the text box in google slides using App script?

After this I am saving it to pdf. I have to remove the text box for next flow.

var s = SlidesApp.getActivePresentation()
  var slide = s.getSlides()[0];

//Student Name
  slide
    .insertTextBox('Sai',100,100,100,10,10)
    .getText()
    .getTextStyle()
    .setFontSize(StudentName.fontSize);

1 Answer 1

2

I believe your goal as follows.

  • From How to remove the text box in google slides using App script?, I understood you want to remove the text box in Google Slides using Google Apps Script.

In your script, the text box is inserted. In this case, the text box is not removed. In order to remove the text box, I would like to propose the following sample script.

Modified script:

function myFunction() {
  var s = SlidesApp.getActivePresentation()
  var slide = s.getSlides()[0];
  slide.getShapes().forEach(shape => {
    if (shape.getShapeType() == SlidesApp.ShapeType.TEXT_BOX) {
      shape.remove();
    }
  });
}
  • In this script, all text boxes are removed in 1st slide in Google Slides.

  • If you want to remove all text boxes in all slides in Google Slides, you can use the following script.

      function myFunction() {
        var s = SlidesApp.getActivePresentation()
        var slides = s.getSlides();
        slides.forEach(slide => {
          slide.getShapes().forEach(shape => {
            if (shape.getShapeType() == SlidesApp.ShapeType.TEXT_BOX) {
              shape.remove();
            }
          });
        });
      }
    

Note:

  • From After this I am saving it to pdf. I have to remove the text box for next flow., in your situation, although I'm not sure about your whole script, before the Google Slides are exported as the PDF format, in order to reflect the latest Google Slides, it might be required to put SlidesApp.getActivePresentation().saveAndClose(). Ref Please be careful this.

References:

Sign up to request clarification or add additional context in comments.

1 Comment

Thank You very much. It is working for my requirement. Yes, I am using "s.saveAndClose();" and var blob = DriveApp.getFileById("1zkIsdiSaVaK6W_R4du6VuyvK2leC3lBTg8fSzNCN6Zc").getBlob(); DriveApp.createFile(blob); Now, I am using your code to remove text box. But it is not working after saveAndClose(). I am checking that now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.