C # merges the PDF file under the developed folder into one and outputs it to the specified path

Source: Internet
Author: User

<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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.