Working with Multiframe TIFF and PDFΒΆ

The following code snippet shows how to assemble a multi-frame TIFF document from individual image files:

C_LONGINT($imageCount)   // The number of source images
ARRAY TEXT($imagePaths;$imageCount)   // Array holding the source file paths
C_TEXT($destPath)   // Where to save the destination file

   // ...

C_TEXT($destDocRef)
$destDocRef:=ImgDoc_CreateNew    // Defaults to TIFF format
If ($destDocRef#"")

   C_LONGINT($imageIdx;$frameIdx)
   $frameIdx:=0

   For ($imageIdx;1;$imageCount)

      C_TEXT($srcDocRef)
      $srcDocRef:=ImgDoc_CreateWithFile ($imagePaths{$imageIdx})
      If ($srcDocRef#"")

         C_LONGINT($srcFrameCount;$srcFrameIdx)
         $srcFrameCount:=ImgDoc_GetFrameCount ($srcDocRef)
         For ($srcFrameIdx;1;$srcFrameCount)

            $frameIdx:=$frameIdx+1
            ImgDoc_InsertFrame ($destDocRef;$frameIdx;$srcDocRef;$srcFrameIdx)

         End for

         ImgObj_Release ($srcDocRef)
      End if

   End for

   C_LONGINT($success)
   $success:=ImgDoc_SaveInFile ($destDocRef;$destPath)

   ImgObj_Release ($destDocRef)

End if

To create a PDF document from individual images, the only change to the above code snippet is the creation of the destination document:

C_LONGINT($imageCount)   // The number of source images
ARRAY TEXT($imagePaths;$imageCount)   // Array holding the source file paths
C_TEXT($destPath)   // Where to save the destination file

   // ...

C_OBJECT($formatOptions)
OB SET($formatOptions;"Format";"PDF")

C_TEXT($destDocRef)
$destDocRef:=ImgDoc_CreateNew(formatOptions)
If ($destDocRef#"")

   C_LONGINT($imageIdx;$frameIdx)
   $frameIdx:=0

   For ($imageIdx;1;$imageCount)

      C_TEXT($srcDocRef)
      $srcDocRef:=ImgDoc_CreateWithFile ($imagePaths{$imageIdx})
      If ($srcDocRef#"")

         C_LONGINT($srcFrameCount;$srcFrameIdx)
         $srcFrameCount:=ImgDoc_GetFrameCount ($srcDocRef)
         For ($srcFrameIdx;1;$srcFrameCount)

            $frameIdx:=$frameIdx+1
            ImgDoc_InsertFrame ($destDocRef;$frameIdx;$srcDocRef;$srcFrameIdx)

         End for

         ImgObj_Release ($srcDocRef)
      End if

   End for

   C_LONGINT($success)
   $success:=ImgDoc_SaveInFile ($destDocRef;$destPath)

   ImgObj_Release ($destDocRef)

End if

Saving any supported file to PDF (including multiframe TIFFs and PDFs) is as simple as:

C_TEXT($docRef)   // The image document reference
C_TEXT($dstPath)    // The destination PDF path

    // ...

C_OBJECT($options)
OB SET($options;"Format";"PDF")

C_LONGINT($success)
$success:=ImgDoc_SaveInFile ($docRef;$dstPath;$options)