Skip to main content
Inspiring
October 28, 2024
Question

ESTK - Adding a blank page at the end of the document

  • October 28, 2024
  • 1 reply
  • 2464 views
For previous documents, there was a requirement for the document to end with Page X/(Y Blank).
 
I have a script that @Russ Ward helped me with to accomplish this. The script:
  • Goes through Pages 2 to the end of the document and removes any custom master pages.
  • Checks the last page of the document and determines if it is odd or even. If it is odd, it applies an X/Y Blank Master page and updates the page numbers in the footer.
 
The script works fine, but I have a new requirement to add a blank page after the X/Y Blank page. (A totally blank page, not an empty page with the header, footer, and page number.)
 
So I need two things added to the script:
 
  • If the doc ends on an odd page, I need to add the blank page. To do that, I thought I needed to add a paragraph at the end of the document, have it start that on an right-hand page, and set the page background to none. I added this code, but it doesn't seem to be working (doc is previously defined as app.ActiveDoc):

 

		var pgf = doc.FirstPgfInDoc;
 		while (pgf.ObjectValid()) {
			pgf = pgf.NextPgfInDoc;
		}
		// Add New Paragraph
		var pgf2 = doc.NewSeriesObject(Constants.FO_Pgf, pgf);
		pgf = doc.LastPgfInDoc;
		var props = pgf2.GetProps();
	                pgf2.SetProps(props);
		pgf2.Start = Constants.FV_PGF_TOP_OF_RIGHT_PAGE;
		var bodyPage = doc.LastBodyPageInDoc;
		bodyPage.PageBackground = Constants.FV_BGD_NONE;

 

There is an anchored frame at the end of the document with "THE END" inside it, so I need the last paragraph in Flow A - which might be why my script doesn't seem to be working.

 

  • At the start of the script, I need to check for and remove empty paragraphs at the end of the document (From times the script was previously run). I'm not sure how to do this. I have a function that checks for disconnected flow pages, but this is not a disconnected flow page, nor technically an empty page - it has a paragraph on it, just no text in the paragraph.

 

Thanks in advance!

This topic has been closed for replies.

1 reply

frameexpert
Community Expert
Community Expert
October 28, 2024

The script isn't working because this code

 

var pgf = doc.FirstPgfInDoc;
while (pgf.ObjectValid()) {
    pgf = pgf.NextPgfInDoc;
}

 

processes all of the paragraphs in the document, including those on master and reference pages (and in table cells). And the paragraph list is not necessarily in document order. Here is the first video in a series of 4 (they are short):

https://youtu.be/-kkiVfOi2zs?si=wyi-UVOwQjW0UnuY

 

 

Inspiring
October 28, 2024

Thanks - Nicely done - reviewing and working on it now!

Inspiring
October 28, 2024

Okay - I probably made a typo somewhere ...

If it's not okay to post YOUR code here, let me know:

 

 

main();
// FrameExpert -  https://www.youtube.com/watch?v=-kkiVfOi2zs
// will not find paragraphs in tables
function main(){
    var doc;
    doc=app.ActiveDoc;
    if (doc.ObjectValid() === 1) {
            processDoc(doc);
            }
        }
    
    function processDoc(doc){
        var pgf
        // Turn off document display to speed the script and prevent flicker.
        if (app.Displaying ===1) {
            app.Displaying ===1;
            }
        // Loop through the paragraphs in the document's main flow.
        pgf = doc.MainFlowInDoc.FirstTextFrameInFlow.FirstPgf;
        while (pgf.ObjectValid() === 1){
            text = getPgfText(pgf);
            Console (text);
            pgf=pgf.NextPgfInFlow;
            
            }

            
            // Restore the document display and refresh the screen.
            if (app.Displaying === 0) {
                app.Displaying = 1;
                doc.Redisplay();
                }
            }
    function getPgfText(pgf){
            var text, textList, count, i;
            textList = pgf.GetText (Constants.FTI_String);
            
            count = textList.length;
            for (i = 0; i < count; i += 1) {
                text += (textList[i].sdata);
             }
         alert(text);
         return text;
         }

 

 

When I run the code, in the console, I just get "Result: undefined", but in the alert statement that I added before the end, I get "Undefined.Main1", "Undefined.Main2", etc ...