I have an application in Apps Script which populates a template document with some data, exports it as a pdf, and emails it to some email address. The new Document Tabs feature in google docs for Workspace accounts has led to a page with the text 'Tab 1' being prepended to the pdf. The function below uses the Drive API to export the doc as a pdf. Two weeks ago this was actually my solution to this very issue, but for some reason it no longer omits the 'Tab 1' page. The Document Tabs feature cannot be disabled as of now.
If possible, I'd rather not use a 3rd party lib to allow for editing pdfs in Apps Script but so far that's the only solution I can think of. Here is the function which exports the google doc as a pdf. Any suggestions are appreciated.
function exportGoogleDocAsPdf(fileId, fileName) { const exportUrl = `https://www.googleapis.com/drive/v3/files/${fileId}/export?mimeType=application/pdf`; const token = ScriptApp.getOAuthToken(); const response = UrlFetchApp.fetch(exportUrl, { headers: { Authorization: `Bearer ${token}` } }); const pdfBlob = response.getBlob().setName(fileName); return pdfBlob; }