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

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

Recommended Posts

  • Newbies
Posted

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!

Posted

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/

Posted

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.

Posted

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.

This topic is 3948 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.