Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×

This topic is 5329 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

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.

Posted

@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

Posted

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.

Posted

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.

Posted (edited)

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
Posted

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?

Posted (edited)

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
Posted

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?

Posted

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.

Posted

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".

Posted

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

Posted

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

Posted

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...
Posted

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();" )

This topic is 5329 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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