←Select platform

MergeFiles Method

Summary

Merges pages from multiple PDF files into one output PDF file.

Syntax

C#
VB
C++
Java
public void MergeFiles( 
   PDFPageRange[] pages, 
   string destinationFileName 
) 
Public Sub MergeFiles( _ 
   ByVal pages() As PDFPageRange, _ 
   ByVal destinationFileName As String _ 
)  
public void MergeFiles( 
   Leadtools.Pdf.PDFPageRange pages[],  
   java.lang.String destinationFileName 
); 
public: 
void MergeFiles(  
   Leadtools.Pdf.PDFPageRange[]^ pages[], 
   String^ destinationFileName 
)  

Parameters

pages

The array indicating which page range should be merged. The array cannot be null. Each item in the array contains the source file (optional), password (optional), first and last page.

destinationFileName

Name of the destination PDF file to be created. If the value of this parameter is null then the filename set in FileName will be updated.

Remarks

Each element of the pages array specifies a page interval (first and last page) and an optional source file.

If the source file from the pages array item is null, then the source file and password is taken from the current PDFFile object. In this case, the current PDFFile object must be associated with a valid PDF file and optional password. You can achieve this by either using the PDFFile(string fileName) or PDFFile(string fileName, string password) constructors or set the filename and optional password directly into the FileName and Password properties. You do not need to call Load before using this method.

If all items in the pages array specify a valid source file, then the PDFFile array does not need to be associated with a file. And even if it is associated with a file, that file will be ignored.

This method will use the following properties of this PDFFile object:

This method is the most generic of all the PDFFile.ExtractPages and PDFFile.MergeWith methods and can be used to replace any of them.

In other words:

  1. PDFFile.ExtractPages is just like calling PDFFile.MergeFiles and setting all the source files to the same value.
  2. PDFFile.MergeWith is just like calling PDFFile.MergeFiles but converting all the pages in each source file (so setting PDFPageRange.FirstPageNumber = 1 and PDFPageRange.LastPageNumber = -1).

Example

VB
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.Pdf 
Imports Leadtools.WinForms 
Imports Leadtools.Svg 
Imports Leadtools.ImageProcessing 
Imports LeadtoolsPdfExamples.Leadtools.Examples 
 
Public Sub MergeFiles() 
 
   ' This example will extract two pages from the current file and one page from another (encrypted) file into a single output file. 
   ' All the pages in the output file will be unencrypted. 
   Dim srcFile As String = Path.Combine(LEAD_VARS.ImagesDir, "leadtools.pdf") 
   Dim dstFile As String = Path.Combine(LEAD_VARS.ImagesDir, "leadtools 4-5 1.pdf") 
   Dim pdfFile As PDFFile = New PDFFile(srcFile) 
   Dim srcPages As PDFPageRange() = New PDFPageRange(1) {} 
 
   srcPages(0).FirstPageNumber = 4 
   srcPages(0).LastPageNumber = 5 
   ' Leave srcPages[0] set to null, so pages 4 and 5 are extracted from leadtools.pdf  
 
   srcPages(1).FileName = Path.Combine(LEAD_VARS.ImagesDir, "Encrypted.pdf") ' Encrypted.pdf file must exist. If none exists, provide one. 
   srcPages(1).Password = "LEAD" 
   srcPages(1).FirstPageNumber = 1 
   srcPages(1).LastPageNumber = 1 
 
   pdfFile.MergeFiles(srcPages, dstFile) 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\LEADTOOLS22\Resources\Images" 
End Class 

Requirements

Target Platforms

See Also

Help Version 22.0.2021.10.28
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Pdf Assembly
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.