ExcelToPdfMergePDFFileArrayToPDFFile Method |
Merges different PDF files into single PDF file
Namespace: SautinSoftAssembly: SautinSoft.ExcelToPdf (in SautinSoft.ExcelToPdf.dll) Version: 5.6.11.14
Syntaxpublic void MergePDFFileArrayToPDFFile(
string[] Files,
string DestFile
)
Public Sub MergePDFFileArrayToPDFFile (
Files As String(),
DestFile As String
)
Parameters
- Files String
- Array with paths to PDF documents
- DestFile String
- Path to a new single PDF, it will be created by the component or overwritten in case of PDF is already exist
Return Value
0 - merged successfully
1 - error, can't merge PDF documents
2 - error, can't create output file, probably it used by another application
ExampleMerge two PDF files using C#
using System;
using System.IO;
using SautinSoft;
namespace Sample
{
class Sample
{
static void Main(string[] args)
{
ExcelToPdf x = new ExcelToPdf();
x.PageStyle.PageSize.Letter();
x.PageStyle.PageMarginTop.mm(5);
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf;
x.Sheets.Custom(new int[]{3});
string excelFile = Path.GetFullPath(@"..\..\test.xlsx");
FileInfo pdfFile = new FileInfo(Path.ChangeExtension(excelFile, ".pdf"));
string singlePdf = Path.Combine(pdfFile.Directory.FullName, "Single.pdf");
try
{
x.ConvertFile(excelFile, pdfFile.FullName);
x.MergePDFFileArrayToPDFFile(new string[] { pdfFile.FullName, pdfFile.FullName },
singlePdf);
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(singlePdf) { UseShellExecute = true });
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
}
Merge two PDF files using VB.Net
Imports System
Imports System.IO
Imports SautinSoft
Module Sample
Sub Main()
Dim x As New ExcelToPdf()
x.PageStyle.PageSize.Letter()
x.PageStyle.PageMarginTop.mm(5)
x.OutputFormat = SautinSoft.ExcelToPdf.eOutputFormat.Pdf
x.Sheets.Custom(New Integer() {3})
Dim excelFile As String = Path.GetFullPath("..\test.xlsx")
Dim pdfFile As New FileInfo(Path.ChangeExtension(excelFile, ".pdf"))
Dim singlePdf As String = Path.Combine(pdfFile.Directory.FullName, "Single.pdf")
Try
x.ConvertFile(excelFile, pdfFile.FullName)
x.MergePDFFileArrayToPDFFile(New String() {pdfFile.FullName, pdfFile.FullName}, singlePdf)
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(singlePdf) With {.UseShellExecute = True})
Catch ex As Exception
Console.WriteLine(ex.Message)
Console.ReadLine()
End Try
End Sub
End Module
See Also