The Merge method merges two PDF documents by combining the contents of every page of the first document with a page from the second document.
System.Boolean Merge(System.String FileName, System.Int32 Options)
FileName
Full path 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. |
The return value is True if the file was merged. If the Merge method fails, an exception is raised and there is no return value.
Merge is used when the file to be merged is referenced by its full path. Check MergeEx Method to use Document instead.
If the documents do not have the same number of pages, say file1 has N1 pages and file2 has N2 pages where N1 < N2, then the developer can choose to:
Either merge file1 with the N1 pages of file2 and keep the remaining N2-N1 pages of file2 unchanged, in this case the Repeat option should be set to 0.
Or merge the first block of N1 pages of file2 with the N1 pages of file1, merge the second block of N1 pages of file1 with the N1 pages of file1 and so on, in this case Repeat should be set to 1.
E.g.: if file1 contains the company’s letterhead in PDF format as one page, file2 is a two page invoice in PDF format generated with the accounting package, one can call:
pdfDoc.Merge("file2.pdf", 1) // repeat the company’s letterhead on all the invoice pages
or
pdfDoc.Merge("file2.pdf", 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.
<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
' 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)
' Open the document
pdfDoc.Open("c:\temp\LetterHead.pdf")
' Merge LetterHead to test document
pdfDoc.Merge("c:\temp\test.pdf", 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();
// 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);
// Merge LetterHead to test document
pdfDoc.Merge("c:\\temp\\test.pdf", (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");
// 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);
// Open the document
Dispatch.call(pdfDoc, "Open", "c:\\temp\\LetterHead.pdf");
// Merge LetterHead to test document
Dispatch.call(pdfDoc, "Merge", "c:\\temp\\test.pdf", MERGEOPTIONS.Repeat.value);
// Save the document
Dispatch.call(pdfDoc, "Save", "c:\\temp\\Merged.pdf");
// Destroy pdfDoc object
pdfDoc = 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
#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))
#Open the documents
[System.__ComObject].InvokeMember('Open', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\letterhead.pdf")
#Merge letterhead to test document
[System.__ComObject].InvokeMember('Merge', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc, @("c:\temp\test.pdf", $MERGEOPTIONS::Repeat))
#Save the document
[System.__ComObject].InvokeMember('Save', [System.Reflection.BindingFlags]::InvokeMethod,$null,$pdfDoc,"c:\temp\Merged.pdf")
#Destroy pdfDoc object
$pdfDoc = $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")
' 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
' Open the document
pdfDoc.Open "c:\temp\LetterHead.pdf"
' Merge LetterHead to test document
pdfDoc.Merge "c:\temp\test.pdf", Repeat
' Save the document
pdfDoc.Save "c:\temp\Merged.pdf"
' Destroy pdfDoc object
Set pdfDoc = Nothing