How to merge PDF files into one PDF
in C# and VB.Net.
Complete code
using System;
using System.IO;
using System.Collections;
namespace Sample
{
class Test
{
static void Main(string[] args)
{
// Merge PDF files.
SautinSoft.PdfVision v = new SautinSoft.PdfVision();
//v.Serial = "XXXXXXXXXXXXXXX";
// Let's merge several PDF files.
string[] inpFiles = new string[] { @"..\..\simple text.pdf", @"..\..\table.pdf" };
FileInfo outFile = new FileInfo(@"Result.pdf");
int ret = v.MergePDFFileArrayToPDFFile(inpFiles, outFile.FullName);
// 0 - Merged successfully.
// 1 - Error, can't merge PDF documents.
// 2 - Error, can't create the output file, probably it used by another application.
// 3 - Merging failed.
// 4 - Merged successfully, but some files were not merged.
if (ret == 0)
{
// Open the resulting PDF document in a default PDF Viewer.
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile.FullName) { UseShellExecute = true });
}
}
}
}
Imports System
Imports System.IO
Imports System.Collections
Namespace Sample
Friend Class Test
Shared Sub Main(ByVal args() As String)
' Merge PDF files.
Dim v As New SautinSoft.PdfVision()
'v.Serial = "XXXXXXXXXXXXXXX"
' Let's merge several PDF files.
Dim inpFiles() As String = {"..\..\simple text.pdf", "..\..\table.pdf"}
Dim outFile As New FileInfo("Result.pdf")
Dim ret As Integer = v.MergePDFFileArrayToPDFFile(inpFiles, outFile.FullName)
' 0 - Merged successfully.
' 1 - Error, can't merge PDF documents.
' 2 - Error, can't create the output file, probably it used by another application.
' 3 - Merging failed.
' 4 - Merged successfully, but some files were not merged.
If ret = 0 Then
' Open the resulting PDF document in a default PDF Viewer.
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile.FullName) With {.UseShellExecute = True})
End If
End Sub
End Class
End Namespace
If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below: