Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Script to Add Blank Page

Featured Replies

I'm dizzy after reading java forum posts. I just need a new ScriptMaster script that adds a blank pdf page to an existing pdf. If anyone has such a ScriptMaster script, I would be very grateful if you'd share.

I could probably give an estimate for such a module, if you're interested.

How about have a blank, 1 page pdf stored somewhere and add that to your pdf? Matt Petrowsky describes how Here - using ScriptMaster

  • Author

@Tim - Yes, that's my fallback position.

@Valentin - Can you provide an estimate for two things:

1. A running footer with text from field and Page X of Y.

2. The function to add a blank page.

You can PT me with the estimate. Thanks, Barbara

why don't you give the iText library a shot?

There are functions to add blank pages, footers, headers, ...

Thanks to this post I started to look for PDF manipulation, and found this nice library. I think it is worth a try. However I didn't find the exact solution yet, but I know there exists a function addPage(), so this should do the trick no.

  • Author

No, it won't do the trick if you can't write java scripts!

Yes, it's all possible with iText and Scriptmaster. I'm hoping someone out there has built these ScriptMaster modules.

this does the trick... (however very primitive as I am also a Java noob) but I hope it helps !

This function takes three arguments:

OrginalPDF: Path to Original pdf

newPDF: Path where to save the new PDF with the blank page (I did not find a way to overwrite the current file...)

PageNumber: where you want the blank page to be inserted


RegisterGroovy( "AddBlankPageExistingPDF( OriginalPDF ; newPDF ; PNumber )" ; "import java.io.FileOutputStream;¶

import java.io.IOException;¶

import com.itextpdf.text.Rectangle;¶

¶

¶

import com.itextpdf.text.pdf.PdfReader;¶

import com.itextpdf.text.pdf.PdfStamper;  ¶

¶

//Create reader and stamper¶

PdfReader reader = new PdfReader(OriginalPDF);¶

PdfStamper stamper = new PdfStamper(reader,new FileOutputStream(newPDF));¶

¶

//Grab the page size of the first page of the original document¶

reader.getPageSize(1);¶

¶

//Convert the location to integer¶

int PageNumber = Integer.parseInt(PNumber);¶

¶

//Create new page¶

Rectangle newPage = reader.getPageSize(1);¶

¶

//Insert new page¶

stamper.insertPage(PageNumber,newPage);¶

¶

//Close document¶

stamper.close();" )

Good luck !

Edited by Guest
changed code

  • Author

Thanks for this. However, I can't get this to work. If I try to create a custom function with it, FM won't allow a parameter named PageNumber.

Do you have a sample demo file?

You are right, I changed the parameter name to pNumber.

This is a demo for Mac. It creates two PDFs on your dekstop:

pdfFM.pdf -> the pdf created by FileMaker

pdfSM.pdf -> the pdf with a blank page between page one and three.

I think you have to work on the Unix paths in the PrintPDF script to make it work on a Windows machine. The function only accepts Unix paths.

AddBlankPage_SM.fp7.zip

Edited by Guest

  • Author

Andries, thank you. Unix paths? Are they at all similar to OS paths?

well I can explain this for a mac B)-).

"file:/Macintosh HD/Users/User/test.pdf" is a valid FileMaker path. The equivalent Unix path is: "/../Users/User/test.pdf" (I do this just before I execute the AddBlankPage function).

On a PC I think it is sufficient to replace all the "" with "/" and remove the "file:", which is typically FileMaker. But I am not sure (at all).

Does the example file work on your mac?

  • Author

No, the example file doesn't work on my iMac.

I use Petrowsky's CF to convert FM paths to OS paths, since his catPDF function also requires OS paths (all iText functions do, afaik).

I see that you have converted FM paths to OS paths in your scripts. I even tried modifying the scripts to use Matt's CFs, but I still get an error at the AddBlank step.

You know, I have this love/hate relationship with iText at this point. When it works, it's a thing of beauty, but not knowing Java is so frustrating. The code is very approachable, but given our immediate need to "get this done" it is so frustrating!

I appreciate you help very much.

ok you are right... this is not working 100%, actually only on on my machine...

I will do some testing next week and come back to you...

But actually everything works, it are just those two paths that are blocking the whole thing... if you find a solution please let me know ( and if it also works on Windows machines that would be even better ).

I found out that if I send /../Users/User/Desktop/test.pdf it works... but of course that is because my user account is called "User".

now I create the following path ( I am really struggling with those paths... I would like someone to explain me all the different filepaths that exist... B)-) )

I was trying to substitute "Macintosh HD", which I thought was the same for every Mac, which is obviously not... but I found out by adding "/Volumes/" it actually works without any modification to the path... this is of course only on a Mac.

/Volumes/SystemDrive/Rest of path

here is another example file...

AddBlankPage_SM.fp7.zip

  • Author

OK. Got it working. I've used Matt's CF to convert the FM paths to OS paths.

This is terrific, thank you!

See attachment.

AddBlankPage_SM2.fp7.zip

thanks for the custom function! Nice to have B)-)

Glad I could help you.

  • Author

Have you ventured into adding bookmarks or footers? (She says, getting greedy).

I am a weekend at the seaside, so it will be for next week.

That is because you can not save the file over the one that is still open in the reader...

See iText documentation for further details

  • 4 months later...

Updated the example to add a blank page at the end of the PDF.

RegisterGroovy( "AddBlankPageEndExistingPDF( OriginalPDF ; newPDF )" ; "import java.io.FileOutputStream;¶

import java.io.IOException;¶

import com.itextpdf.text.Rectangle;¶

¶

¶

import com.itextpdf.text.pdf.PdfReader;¶

import com.itextpdf.text.pdf.PdfStamper;  ¶

¶

//Create reader and stamper¶

PdfReader reader = new PdfReader(OriginalPDF);¶

PdfStamper stamper = new PdfStamper(reader,new FileOutputStream(newPDF));¶

¶

//Grab the page size of the first page of the original document¶

reader.getPageSize(1);¶

¶

//Finds total page numbers, then adds 1¶

int PageNumber = reader.getNumberOfPages() + 1;¶

¶

//Create new page¶

Rectangle newPage = reader.getPageSize(1);¶

¶

//Insert new page¶

stamper.insertPage(PageNumber,newPage);¶

¶

//Close document¶

stamper.close();" )

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.