MergeEx

The MergeEx method merges two PDF documents by combining the contents of every page of the first document with a page from the second document.

 

ActiveX

Syntax:

System.Boolean MergeEx(System.Object Document, System.Int32 Options)

Parameters:

Document

Object reference of the second PDF file to merge with the current one.

Options

Options for merging files. The list of options is in the remarks section.

 

Option

Name

Description

0

No Repeat

The source file merges without repetition.

1

Repeat

Option 1

The contents of the current document are repeated on all pages.

2

Above

The contents of the current document are above the document specified.

4

Layered

Place each merged document on a separate layer. The layer name will be the same as the document title.

64

Repeat Option 2

The first N-1 pages of an N page document will be merged over the right-side document's pages, the Nth (last page of left-side document) will repeat over all remaining pages of right-side document.

 

Return Value

The return value is True if the file was merged. If the MergeEx method fails, an exception is raised and there is no return value.

 

Remarks

MergeEx is used when the second file was opened using the CDIntf.Document class.

 

If the documents do not have the same number of pages, say doc1 has N1 pages and doc2 has N2 pages where N1 < N2, then the developer can choose to:

 

E.g.: if doc1 contains the company’s letterhead in PDF format as one page, doc2 is a two page invoice in PDF format generated with the accounting package, one can call:

doc1.MergeEx(doc2, 1)  // repeat the company’s 
 letterhead on all the invoice pages

or

doc1.MergeEx(doc2, 0)  // to insert the company’s 
 letterhead on the first page only.

 

The two Repeat Options are mutually exclusive. If both are specified, the Repeat Option 1 only will be used.

 

 

Member of CDIntfEx.Document.

 

Example

<Flags()>

Public Enum MERGEOPTIONS As Integer

    No_Repeat = 0

    Repeat = 1

    Above = 2

    Layered = 4

    Repeat2 = 64

End Enum

 

Private Sub Sample()

    ' Constants for Activation codes

    Const strLicenseTo As String = "Amyuni PDF Converter Evaluation"

    Const strActivationCode As String = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

    ' Declare a new cdintfex document if it does not exist in the form.

    Dim pdfDoc As New CDIntfEx.Document

    Dim pdfDoc1 As New CDIntfEx.Document

 

    ' The SetLicenseKey method should be called after creating an object of type 

    ' CDIntfEx.Document to activate the advanced methods that require the object 

    ' activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode)

    pdfDoc1.SetLicenseKey(strLicenseTo, strActivationCode)

 

    ' Open the document

    pdfDoc.Open("c:\temp\LetterHead.pdf")

    pdfDoc1.Open("c:\temp\test.pdf")

 

    ' Merge LetterHead to test document

    pdfDoc.MergeEx(pdfDoc1, MERGEOPTIONS.Repeat)

 

    ' Save the document

    pdfDoc.Save("c:\temp\Merged.pdf")  

End Sub

[Flags]

public enum MERGEOPTIONS

{

    No_Repeat = 0,

    Repeat = 1,

    Above = 2,

    Layered = 4,

    Repeat2 = 64

}

private void Sample()

{

    // Constants for Activation codes

    const string strLicenseTo = "Amyuni PDF Converter Evaluation";

    const string strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

    // Declare a new cdintfex document if it does not exist in the form.

    CDIntfEx.Document pdfDoc = new CDIntfEx.Document();

    CDIntfEx.Document pdfDoc1 = new CDIntfEx.Document();

 

    // The SetLicenseKey method should be called after creating an object of type 

    // CDIntfEx.Document to activate the advanced methods that require the object 

    // activation code to work properly

    pdfDoc.SetLicenseKey(strLicenseTo, strActivationCode);

    pdfDoc1.SetLicenseKey(strLicenseTo, strActivationCode);

 

    // Open the document

    pdfDoc.Open(@"c:\temp\LetterHead.pdf");

    pdfDoc1.Open(@"c:\temp\test.pdf");

 

    // Merge LetterHead to test document

    pdfDoc.MergeEx(pdfDoc1, (int)MERGEOPTIONS.Repeat);

 

    // Save the document

    pdfDoc.Save("c:\\temp\\Merged.pdf");

 

}

package Example;

 

import com.jacob.activeX.ActiveXComponent;

import com.jacob.com.Dispatch;

import com.jacob.com.Variant;

 

public class Merge {

    public enum MERGEOPTIONS 

    {

        No_Repeat (0),

        Repeat (1),

        Above (2),

        Layered (4),

        Repeat2 (64);

        private int value;

        private MERGEOPTIONS(int value)

        {

            this.value = value;

        }

        public Object value(){

            return value;

        }

    }

    public static void main(String[] args)

    {

        // Constants for Activation codes

        String strLicenseTo  = "Amyuni PDF Converter Evaluation";

        String strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA";

 

        // Declare a new cdintfex document if it does not exist in the form.

        ActiveXComponent pdfDoc = new ActiveXComponent("CDIntfEx.Document.6.5"); 

        ActiveXComponent pdfDoc1 = new ActiveXComponent("CDIntfEx.Document.6.5"); 

 

        // The SetLicenseKey method should be called after creating an object of type 

        // CDIntfEx.Document to activate the advanced methods that require the object 

        // activation code to work properly

        Dispatch.call(pdfDoc, "SetLicenseKey", strLicenseTo, strActivationCode);

        Dispatch.call(pdfDoc1, "SetLicenseKey", strLicenseTo, strActivationCode);

 

        // Open the document

        Dispatch.call(pdfDoc, "Open", "c:\\temp\\LetterHead.pdf");

        Dispatch.call(pdfDoc1, "Open", "c:\\temp\\test.pdf");

 

        // Merge LetterHead to test document

        Dispatch.call(pdfDoc, "MergeEx", pdfDoc1, MERGEOPTIONS.Repeat.value);

 

        // Save the document

        Dispatch.call(pdfDoc, "Save", "c:\\temp\\Merged.pdf");

 

        // Destroy pdfDoc object

        pdfDoc = null;

        pdfDoc1 = null;

 

    }

}

$MERGEOPTIONS = @{

    No_Repeat = 0

    Repeat = 1

    Above = 2

    Layered = 4

    Repeat2 = 64

}

# Constants for Activation codes

$strLicenseTo  =  "Amyuni PDF Converter Evaluation"

$strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

#Declare a new cdintfex document if it does not exist in the form.

$pdfDoc = New-Object -ComObject CDIntfEx.Document.6.5

$pdfDoc1 = New-Object -ComObject CDIntfEx.Document.6.5

 

#The SetLicenseKey method should be called after creating an object of type 

#CDIntfEx.Document to activate the advanced methods that require the object 

#activation code to work properly

[System.__ComObject].InvokeMember('SetLicenseKey', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($strLicenseTo, $strActivationCode))

[System.__ComObject].InvokeMember('SetLicenseKey', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc1, @($strLicenseTo, $strActivationCode))

 

#Open the documents

[System.__ComObject].InvokeMember('Open', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\letterhead.pdf") 

[System.__ComObject].InvokeMember('Open', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc1,"c:\temp\test.pdf") 

 

#Merge letterhead to test document

[System.__ComObject].InvokeMember('Merge', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @($pdfDoc1, $MERGEOPTIONS::Repeat))

 

#Save the document

[System.__ComObject].InvokeMember('Save', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\Merged.pdf")

 

#Destroy pdfDoc object

$pdfDoc = $null

$pdfDoc1 = $null

Const No_Repeat = 0

Const Repeat = 1

Const Above = 2

Const Layered = 4

Const Repeat2 = 64

 

' Constants for Activation codes

Const strLicenseTo = "Amyuni PDF Converter Evaluation"

Const strActivationCode = "07EFCDAB0100010025AFF1801CB9441306C5739F7D452154D8833B9CECBA2ADE79E3762A69FFC354528A5F4A5811BE3204A0A439F5BA"

 

' Declare a new cdintfex document if it does not exist in the form.

Dim pdfDoc 

Set pdfDoc = CreateObject("CDIntfEx.Document.6.5")

Dim pdfDoc1 

Set pdfDoc1 = CreateObject("CDIntfEx.Document.6.5")

 

' The SetLicenseKey method should be called after creating an object of type 

' CDIntfEx.Document to activate the advanced methods that require the object 

' activation code to work properly

pdfDoc.SetLicenseKey strLicenseTo, strActivationCode

pdfDoc1.SetLicenseKey strLicenseTo, strActivationCode

 

' Open the document

pdfDoc.Open "c:\temp\LetterHead.pdf"

pdfDoc1.Open "c:\temp\test.pdf"

 

' Merge LetterHead to test document

pdfDoc.Merge pdfDoc1, Repeat

 

' Save the document

pdfDoc.Save "c:\temp\Merged.pdf"

 

' Destroy pdfDoc object

Set pdfDoc = Nothing

Set pdfDoc1 = Nothing