August 30, 201015 yr I am trying to get iText working and from some reason my code is generating an error. // The following code is groovy code to be used with the ScriptMaster plugin // The code requires the iText jar library and will merge any number of PDF files // into one PDF file // @param files = return separated list of absolute paths to PDF files // @param output = absolute path for new pdf file (including file name) import java.io.FileOutputStream; import java.util.ArrayList; import java.util.List; import com.itextpdf.text.Document; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfCopy; import com.itextpdf.text.pdf.PdfImportedPage; try { String[] inFiles = files.split( "n" ); int f = 0; int pageOffset = 0; String outFile = output; Document document = null; PdfCopy writer = null; while (f
August 30, 201015 yr Author after trial & error and reloading the latest version of iText 5.0.4 it seems to be working with this code. // The following code is groovy code to be used with the ScriptMaster plugin // The code requires the iText jar library and will merge any number of PDF files // into one PDF file // @param files = return separated list of absolute paths to PDF files // @param output = absolute path for new pdf file (including file name) RegisterGroovy( "MergePDF( files ; output )" ; "import java.io.FileOutputStream;¶ import java.util.ArrayList;¶ import java.util.List;¶ ¶ import com.itextpdf.text.Document;¶ import com.itextpdf.text.pdf.PdfReader;¶ import com.itextpdf.text.pdf.PdfCopy;¶ import com.itextpdf.text.pdf.PdfImportedPage;¶ ¶ try {¶ String[] inFiles = files.split("n");¶ int f = 0;¶ int pageOffset = 0;¶ String outFile = output;¶ Document document = null;¶ PdfCopy writer = null;¶ ¶ while (f
September 2, 201015 yr Same thing but a bit simpler and more Groovy // PDFadd( filelist ; fm_FileOut ) // JR 05_03_10 // v2 // concatenate PDf files import com.itextpdf.text.Document import com.itextpdf.text.pdf.PdfCopy import com.itextpdf.text.pdf.PdfReader files = filelist.split("n") // step 1 document = new Document() // step 2 copy = new PdfCopy(document, new FileOutputStream( fm_FileOut )) // step 3 document.open() // step 4 PdfReader reader int n // loop over the documents you want to concatenate files.each { item -> reader = new PdfReader("${item}") n = reader.getNumberOfPages() for (int page = 0; page < n; ) { copy.addPage(copy.getImportedPage(reader, ++page)) } } // step 5 document.close() return true
December 22, 201015 yr Newbies Hi, I am looking to incorporate this with a run-time I have built. I can get this to work with one file, but am not sure how to ensure that it works with multiple files. How do I list the files (with path) so that the process merges all files into one? This step appears to be where the process works with the multiple files. files = filelist.split("n") When I provide a list separated by a carriage return or ";" the function errors: java.io.IOException: /Users/mike/Desktop/VBBEUPLOAD/PDF/Test_AP1.pdf /Users/mike/Desktop/VBBEUPLOAD/PDF/Test_AP2.pdf /Users/mike/Desktop/VBBEUPLOAD/PDF/Test_AP3.pdf not found as file or resource. How do I provide a list of files so the function can process them without an error? Looking forward to a response. Mike
December 22, 201015 yr That will be my mistake OR the formatting gets stripped should be filelist.split(" backslash n " )
February 19, 201312 yr Newbies Hello, I am trying to use the PDFadd function. Until last night i managed to do so, but now I keep getting an error :"java.io.FileNotFoundException: file:C:UsersBeckyDesktopLogiciel SoloreaFichiers base SoloreaContrat Global Solorea du client laksalksalkslk tututu.pdf (The filename, directory name, or volume label syntax is incorrect)" I am using two calculated paths as input variables. I checked the paths and corrected all the mistakes I think. I really don t know what to do anymore. Maybe smn could help me?
February 20, 201312 yr Hello, SM/Groovy is expecting a System path, not a path "à la FileMaker". Just get rid of the "file:/" prefix. Note also that in your path you can use slashes instead of backslashes. Windows knows how to interpret them since Win98.
February 12, 201411 yr Have made the function a little more Groovy and updated best practice of closing reader // PDFadd( filelist ; fm_FileOut ) // JR 14_02_12 // v2.1 // concatenate PDF files import com.itextpdf.text.Document import com.itextpdf.text.pdf.PdfCopy import com.itextpdf.text.pdf.PdfReader files = filelist.split('n') // step 1 document = new Document() // step 2 copy = new PdfCopy(document, new FileOutputStream( fm_FileOut )) // step 3 document.open() // step 4 PdfReader reader int n // loop over the documents you want to concatenate files.each { item -> reader = new PdfReader("${item}") n = reader.getNumberOfPages() for (page in 0.<n ) { copy.addPage(copy.getImportedPage(reader, page)) } reader.close() } // step 5 document.close() return true
May 28, 201411 yr Hi John, Hope you are well and busy. Think you have missed a '.' and a '++' as below // PDFadd( filelist ; fm_FileOut ) // JR 14_02_12 // v2.1 // concatenate PDF files import com.itextpdf.text.Document import com.itextpdf.text.pdf.PdfCopy import com.itextpdf.text.pdf.PdfReader files = filelist.split('n') // step 1 document = new Document() // step 2 copy = new PdfCopy(document, new FileOutputStream( fm_FileOut )) // step 3 document.open() // step 4 PdfReader reader int n // loop over the documents you want to concatenate files.each { item -> reader = new PdfReader("${item}") n = reader.getNumberOfPages() for (page in 0..<n ) { copy.addPage(copy.getImportedPage(reader, ++page)) } reader.close() } // step 5 document.close() return true Cheers Tim
May 28, 201411 yr Tim... right about the '.' but oddly the '++' makes no difference - as there is no page '0' it should in fact be for ( page in 1..n ) with copy.addPage(copy.getImportedPage(reader, page)) john
Create an account or sign in to comment