Newbies stratlake Posted February 10, 2014 Newbies Posted February 10, 2014 Hi All, Just wondering if anyone has created a ScriptMaster module using the iText library before? I'm needing to create a PDF Splitter and Merger in filemaker, so if you have any advice too, shoot!
clemhoff Posted February 11, 2014 Posted February 11, 2014 Hi, here is a PDF Spliter // iText_SplitPDF ( pathToSrc ; pathToDest ) // 2012-07-05 by clem // // NOTE: To be properly numbered, the output file name must contain the format string %d // ex: pathToDest = C:/Path/To/mySplittedPortableDoc_page%d.pdf // result => C:/Path/To/mySplittedPortableDoc_page1.pdf etc… import com.itextpdf.text.Document import com.itextpdf.text.DocumentException import com.itextpdf.text.pdf.PdfCopy import com.itextpdf.text.pdf.PdfReader try{ def reader = new PdfReader(pathToSrc) def document def copy int n = reader.numberOfPages n.times{ document = new Document() copy = new PdfCopy(document, new FileOutputStream(String.format( pathToDest, it + 1))) document.open() copy.addPage copy.getImportedPage(reader, it + 1) document.close() } reader.close() return true } catch (IOException ioe){ return "ERROR: $ioe.message" } catch (DocumentException de){ return "ERROR: $de.message" } and you'll find a PDF Merger here : fmforums.com/forum/topic/73597-itext-scripts/
john renfrew Posted February 12, 2014 Posted February 12, 2014 Clem you now need to explicitly close the reader so document.close() reader.close() also this uses the simpler but less useful class from their docs.>> PdfSmartCopy has the same functionality as PdfCopy, but when resources (such as fonts, images,...) are encountered, a reference to these resources is saved in a cache, so that they can be reused. This requires more memory, but reduces the file size of the resulting PDF document.
clemhoff Posted February 13, 2014 Posted February 13, 2014 hi John, ... my bad ... I just forgot to copy the "finally" clause. also this uses the simpler but less useful class from their docs.>> PdfSmartCopy has the same functionality as PdfCopy, but when resources (such as fonts, images,...) are encountered, a reference to these resources is saved in a cache, so that they can be reused. This requires more memory, but reduces the file size of the resulting PDF document. ... Sir, yes Sir !! …I totally agree with you as long as we're dealing with concatenating PDFs, but in current case we're splitting them and all resources are needed.
Recommended Posts
This topic is 4205 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