The script below creates a PDF from the active document dab without the page with the document tab title. Please note the use of the parameter tab=${tab.getId()}.
function createPDFActiveTab() {
const doc = DocumentApp.getActiveDocument();
const tab = doc.getActiveTab();
const url = `https://docs.google.com/document/d/${doc.getId()}/export?format=pdf&tab=${tab.getId()}`;
const params = {
headers: {
"Authorization": 'Bearer ' + ScriptApp.getOAuthToken()
}
};
const response = UrlFetchApp.fetch(url, params);
const blob = response.getBlob();
DriveApp.createFile(blob);
}
Please remember that the document structure has changed due to Document Tabs and the methods used to handle them. The details are explained in Work with tabs.
The above script uses UrlFetchApp because Class DocumentApp and the Advanced Documents Service don't include a method to retrieve a blob from a document tab. It's worth mentioning that there have been reports that this method might fail on some documents for no apparent reason. The first thing to do is to check that the authorization value was correctly set. A common pitfall is to omit the space between Bearer and the token. If you are sure that the script doesn't have any errors, something to try is to make a copy of the document and run the script on the copy.
without using the Documents tab, can you specify which of its innate functions do you want to get removed through a script along with more information about the file you are using like patterns and how long does each page have?