Merges pages from multiple PDF files into one output PDF file.
public void MergeFiles(
PDFPageRange[] srcPages,
string destinationFileName
)
public void MergeFiles(
Leadtools.Pdf.PDFPageRange pages[],
java.lang.String destinationFileName
);
public:
void MergeFiles(
Leadtools.Pdf.PDFPageRange[]^ pages[],
String^ destinationFileName
)
def MergeFiles(self,] srcPages,destinationFileName):
srcPages
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.
Each element of the
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:
using Leadtools.WinForms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.Controls;
using Leadtools.Drawing;
using Leadtools.ImageProcessing;
using Leadtools.Pdf;
using Leadtools.Svg;
public void 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.
string srcFile = Path.Combine(LEAD_VARS.ImagesDir, "leadtools.pdf");
string dstFile = Path.Combine(LEAD_VARS.ImagesDir, "leadtools 4-5 1.pdf");
PDFFile pdfFile = new PDFFile(srcFile);
PDFPageRange[] srcPages = new PDFPageRange[2];
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);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";
}
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import org.junit.*;
import org.junit.runner.JUnitCore;
import org.junit.runner.Result;
import org.junit.runner.notification.Failure;
import static org.junit.Assert.*;
import leadtools.*;
import leadtools.codecs.*;
import leadtools.pdf.*;
public void pdfFileMergeFilesExample() {
final String LEAD_VARS_IMAGES_DIR = "C:\\LEADTOOLS23\\Resources\\Images";
// 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.
String srcFile = combine(LEAD_VARS_IMAGES_DIR, "leadtools.pdf");
String dstFile = combine(LEAD_VARS_IMAGES_DIR, "leadtools 4-5 1.pdf");
PDFFile pdfFile = new PDFFile(srcFile);
PDFPageRange[] srcPages = new PDFPageRange[2];
srcPages[0] = new PDFPageRange();
srcPages[1] = new PDFPageRange();
srcPages[0].setFirstPageNumber(4);
srcPages[0].setLastPageNumber(5);
// // // Leave srcPages[0] set to null, so pages 4 and 5 are extracted from
// leadtools.pdf //
srcPages[1].setFileName(combine(LEAD_VARS_IMAGES_DIR, "BusinessForm.pdf")); // Encrypted.pdf file must exist. If
// none exists, provide one).
srcPages[1].setPassword("LEAD");
srcPages[1].setFirstPageNumber(1);
srcPages[1].setLastPageNumber(1);
pdfFile.mergeFiles(srcPages, dstFile);
assertTrue("Error in PDF Merge", new PDFFile(dstFile).getPageCount() == 3);
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document