Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

pdf merge ok with 4.32 release but ko with 4.42

Featured Replies

Hi,

I face something very weird. When I use a groovy pdf merge function, it works perfectly well with scriptMaster 4.32 release but fails with 4.42 one.

Returned error is "ERROR: the document has no pages".

The script : you can find it on french forum : https://www.fmsource.com/topic/45116-scriptmaster-manipulation-de-documents-pdf/#comment-262760

// iText_ConcatenatePDF ( fm_fileList ; fm_outputPath ; fm_setCompression )
// 20150130 Clem
// v1.0
// Concatène une liste de documents pdf.
//
// ***** PARAMETERS *****
// fm_fileList			: Une liste de chemins menant à des documents PDF.
// fm_outputPath		: Le chemin de sortie du document final.
// fm_setCompression    : Active la compression du flux de données. Valeurs acceptées :
//                        Pour activer la compression    : 1, TRUE, true, True, "1", "true", "TRUE".
//				          Pour désactiver la compression : toute autre valeur y compris "". 
// Remarque: Activer la compression génèrera automatiquement un PDF de version 1.5 //
// ***** DEPENDENCIES ***** // iText.jar // http://sourceforge.net/projects/itext/files/iText//// ********************************************************************************************************************

import com.itextpdf.text.Document
import com.itextpdf.text.pdf.PdfReader
import com.itextpdf.text.pdf.PdfSmartCopy
import com.itextpdf.text.pdf.PdfWriter

try {
    def fileArray = fm_fileList.tokenize("\n")
    if (fileArray.empty) throw new Exception("Empty file list.")

    // check for pdf document
    fileArray.each {
        f =  new File(it)
        if ( ! (f.exists() && f.getName().toLowerCase().endsWith(".pdf"))) throw new IOException ("File \"${f}\" not found as file or resource or is not a PDF document.")
    }

    // compression
    try {
        setCompression = fm_setCompression.toBoolean()
    } catch (Exception e) {
        setCompression = false
    }

    // merge pdf documents
    try {
        // Document implements DocListener, IAccessibleElement
        new Document().with { doc ->
            // PdfSmartCopy extends PdfCopy extends PdfWriter extends DocWriter implements PdfViewerPreferences, PdfEncryptionSettings, PdfVersion, PdfDocumentActions, PdfPageActions, PdfRunDirection, PdfAnnotations
            copy = new PdfSmartCopy(doc, new FileOutputStream(fm_outputPath))

            if ( setCompression) {
                // PdfWriter extends DocWriter implements PdfViewerPreferences, PdfEncryptionSettings, PdfVersion, PdfDocumentActions, PdfPageActions, PdfRunDirection, PdfAnnotations
                copy.pdfVersion = PdfWriter.VERSION_1_7
                copy.setFullCompression() // throws DocumentException
            }
            open() // Document
            fileArray.each { f ->
                new PdfReader(f).with {
                    for (page in 1..getNumberOfPages()) {
                        copy.addPage(copy.getImportedPage(it, page))
                    }
                    copy.freeReader(it) // throws IOException
                    close() // PdfReader close
                }
            }
            //copy.close() // PdfCopy close
            close() // Document close
        }
        return 1
    } catch (Exception e){
        return("ERROR: $e.message")
    } finally{
        copy.close()
    }
} catch (Exception e) {
    return ("ERROR: $e.message")
}
  • 4 weeks later...

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.