Combine two (or more) PDF's

后端 未结 17 1474
梦毁少年i
梦毁少年i 2020-12-04 07:26

Background: I need to provide a weekly report package for my sales staff. This package contains several (5-10) crystal reports.

Problem:

17条回答
  •  隐瞒了意图╮
    2020-12-04 07:49

    To solve a similar problem i used iTextSharp like this:

    //Create the document which will contain the combined PDF's
    Document document = new Document();
    
    //Create a writer for de document
    PdfCopy writer = new PdfCopy(document, new FileStream(OutPutFilePath, FileMode.Create));
    if (writer == null)
    {
         return;
    }
    
    //Open the document
    document.Open();
    
    //Get the files you want to combine
    string[] filePaths = Directory.GetFiles(DirectoryPathWhereYouHaveYourFiles);
    foreach (string filePath in filePaths)
    {
         //Read the PDF file
         using (PdfReader reader = new PdfReader(vls_FilePath))
         {
             //Add the file to the combined one
             writer.AddDocument(reader);
         }
    }
    
    //Finally close the document and writer
    writer.Close();
    document.Close();
    

提交回复
热议问题