bcooney Posted December 9, 2009 Posted December 9, 2009 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.
Valentin Posted December 10, 2009 Posted December 10, 2009 I could probably give an estimate for such a module, if you're interested.
Tim Anderson Posted December 10, 2009 Posted December 10, 2009 How about have a blank, 1 page pdf stored somewhere and add that to your pdf? Matt Petrowsky describes how Here - using ScriptMaster
bcooney Posted December 11, 2009 Author Posted December 11, 2009 @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
andries Posted December 16, 2009 Posted December 16, 2009 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.
bcooney Posted December 16, 2009 Author Posted December 16, 2009 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.
andries Posted December 17, 2009 Posted December 17, 2009 (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 December 19, 2009 by Guest changed code
bcooney Posted December 17, 2009 Author Posted December 17, 2009 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?
andries Posted December 17, 2009 Posted December 17, 2009 (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 December 17, 2009 by Guest
bcooney Posted December 17, 2009 Author Posted December 17, 2009 Andries, thank you. Unix paths? Are they at all similar to OS paths?
andries Posted December 18, 2009 Posted December 18, 2009 well I can explain this for a mac -). "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?
bcooney Posted December 18, 2009 Author Posted December 18, 2009 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.
andries Posted December 18, 2009 Posted December 18, 2009 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".
andries Posted December 18, 2009 Posted December 18, 2009 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... -) ) 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
bcooney Posted December 18, 2009 Author Posted December 18, 2009 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
andries Posted December 18, 2009 Posted December 18, 2009 thanks for the custom function! Nice to have -) Glad I could help you.
bcooney Posted December 18, 2009 Author Posted December 18, 2009 Have you ventured into adding bookmarks or footers? (She says, getting greedy).
andries Posted December 19, 2009 Posted December 19, 2009 I am a weekend at the seaside, so it will be for next week.
john renfrew Posted December 19, 2009 Posted December 19, 2009 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
john renfrew Posted May 3, 2010 Posted May 3, 2010 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();" )
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now