Google sheet to PDF save drive and mail or WhatsApp

i need to creak pdf from google sheet and then save as pdf to drive(In particular folder). then same pdf to send by additional block to email or WhatsApp.
Please suggest.
like fallowing can create pdf but same to get retrieve to next button and send to mail or whstapp as attachment


App Inventor Tutorials and Examples: Send Mail | Pura Vida Apps

I want to understand how same which i saved now get connected to next button as pdf file link from google drive and when i click then it will send the data as above..

To save going back and forth to Google Drive, why not just have a google apps script that will create the pdf and store it to google drive at the same time ?

Motive is to share the live data on same day as report. it's easier to operator to mostly handy to see on whstapp to be particular. Please suggest. I had checked details on [App inventor Google sheets] (https://groups.google.com/g/mitappinventortest/c/lLUGkYwn7SM/m/OpGPOlfAAgAJ) but then how to convert same to button as pdf file link don't know. please suggest.

You could start here:

https://developers.google.com/apps-script/samples/automations/generate-pdfs

@TIMAI2 this is really perfect solution. just to know if possible,
can be use same 'Generate & send PDFs from Google Sheets' from button with app script from app. ?

Yes it can.

Thanks, i have to use same script or will need to modify.

It will depend on your requirements. You will probably need to modify if you are going to send parameters from the app.

Ok let me try once

image

to create separate App script for each button and integrate it with button in app. this is beyond my knowledge.
@TIMAI2 if u please support for demo

image

three scripts interacting with each other so

Please, in detail, list your workflow from start to finish, then we can hopefully find the correct solution for you.

@TIMAI2 thanks for support.
• First, we scan and get result person wise and station wise by bar code in sheet 1
• Then as per sheet 3 and 4 with filter of date selection PDF report to be get generated and store on google sheet with name of report and date combine as pdf copy name
• Then this pdf to be auto sent by morning 9 AM as mail and WhatsApp number to see to senior daily basis. On WhatsApp either PDF or google drive link to share so that he to open and check.
• Why date is as filter as if required to send any previous date then to get by filter if possible.
• Sheet 2 and 3 are also am using vlookup like from sheet 1 to get from date filter
• This will get every 24 hours report of any day filter from 9 AM to 9 AM



Can't help with the Whatsapp stuff.

Below will handle the email stuff automatically, no need to interact with the web app from the AI2 app.

Script (to generate a pdf file from desired sheet and then email that pdf file)

var ssID, sID;
var fdrid = 'YOUR FOLDER ID HERE';
var email = 'EMAIL ADDRESS TO SEND TO HERE';

function doGet() {
  var ss = SpreadsheetApp.getActive();
  ssID = ss.getId();
  var sh = ss.getSheetByName('Sheet1');
  sID = sh.getSheetId();

  createPDF();
   return ContentService.createTextOutput('PDF sent');
}

function createPDF() {

  const print_options = [
    ['gid',                  sID         ], // Sheet ID (omit for all sheets as pages)
    ['format',               'pdf'       ], // File type
    ['size',                 7           ], // Paper size
    ['portrait',             true        ], // Page Orientation
    ['fitw',                 true        ], // Scale > Fit to width
    ['top_margin',           0.75        ], // Margin in inches (all four are required)
    ['right_margin',         0.70        ], //
    ['bottom_margin',        0.75        ], //
    ['left_margin',          0.70        ], //
    ['gridlines',            false       ], // Show gridlines
    ['printnotes',           false       ], // Show notes
    ['horizontal_alignment', 'CENTER'    ], // Horizontal alignment
    ['vertical_alignment',   'TOP'       ], // Vertical alignment
    ['pagenum',              'UNDEFINED' ], // Page numbers
    ['printtitle',           false       ], // Workbook title
    ['sheetnames',           false       ], // Sheet name
    ['attachment',           true        ], // Uncertain, true works
    ['fzr',                  false       ], // Uncertain, false works
  ];


  let url_params = '?';
  for (p in print_options) {
    url_params = (
      `${url_params}` +
      `${print_options[p][0]}=${print_options[p][1]}` +
      `${(p == (print_options.length - 1)) ? '' : '&'}`
    );
  }
  let url = (
    `https://docs.google.com/spreadsheets/d/${ssID}/export${url_params}`
  );

  console.log(url);

 
  let options = {
    method: 'GET', 
    headers: { 
      'Authorization': `Bearer ${ScriptApp.getOAuthToken()}` 
    }
  };
  let blob = UrlFetchApp.fetch(url, options).getBlob();
  let filename = 'Business Report';
  console.log(filename);
  

  var pdfId = DriveApp.getFolderById(fdrid).createFile(blob.setName(`${filename}.pdf`)).getId();
  console.log('create_file');

  var doc = DriveApp.getFileById(pdfId);

  MailApp.sendEmail(email,
                  "Business Report",
                  "message",
                  {name:"Minion",attachments:[doc]});
}

Trigger (to send email each morning by 0900)

1 Like

great... thanks a lot.. let me try