<summary>
Merging PDFs under the source path to the target path
</summary>
<param name= "SourcePath" > Source path </param>
<param name= "TargetPath" > Target path </param>
<param name= "NewFileName" > New file name </param>
private void Mergepdf (string sourcepath,string targetpath,string newfilename)
{
string[] filenames = Directory.GetFiles (SourcePath, "*.pdf", searchoption.alldirectories);
int filenum = filenames. Number of Length;//pdf
Dictionary<int, string> mydictionary = new Dictionary<int, string> ();
if (FileNum < 2)
{
return;//only one PDF file under the source path, then do not merge
}
Aspose.Pdf.Document a = new Document ();
foreach (var file in filenames)//traverse the source path to get path for all PDF files under that path
{
Document B = new document (file);
foreach (Page item in b.pages)
{
A.pages.add (item);
}
A.save (TargetPath + "\" + NewFileName);
}
}
Called, Aspose.Pdf.dll is used here.
Using Aspose.pdf;
Using System.IO;
private void Button1_Click (object sender, EventArgs e)
{
string [email protected] "C:\Users\Evan\Documents\PDF file \autosave";
String Path_target=environment.getfolderpath (Environment.SpecialFolder.DesktopDirectory);//path of the computer desktop
Mergepdf (Path_source, Path_target, "666666.pdf");
}
C # merges the PDF file under the developed folder into one and outputs it to the specified path