In This Topic
    Merge single pages PDFs
    In This Topic

    Introduction

    The following example demonstrates how to merge two single page PDF documents together. 

    Merge two single page PDF documents
    Copy Code
    public static void MergeSinglePageDocuments()
    {
      Console.WriteLine( "=== MERGE SINGLE PAGES DOCUMENTS ===" );
    
      var file1 = "Animals_Page_1.pdf";
      var file2 = "Animals_Page_2.pdf";
      var outputFileName = "Merged_Animals_1_and_2.pdf";
      var outputPath = MergeSample.MergeOutputDirectory + outputFileName;
    
      // 1. Load the first document (base)
      using( var doc1 = PdfDocument.Load( MergeSample.MergeSampleResourceDirectory + file1 ) )
      {
        // 2. Load the second document to merge
        using( var doc2 = PdfDocument.Load( MergeSample.MergeSampleResourceDirectory + file2 ) )
        {
          // Merge doc2 at the end of doc1
          doc1.Merge( new MergeOptions( doc2 ) );
    
          // Save the output document.
          doc1.SaveAs( outputPath );
          Console.WriteLine( "Merged document saved to: " + outputPath );
        }
      }
    }

    See Also