title: C# - Pdftk - How can i make it so that whenever a pdf has an odd number of pages, a blank page is added?
body: <p>I want to merge many pdf to a single one with Pdftk.</p>
  <p>How can i make it so that whenever a pdf has an odd number of pages, a blank page is added?</p>
  <p>I need this function for a cmd tool which i need to write in c#.</p>
  <p>The PDF should be printed double-sided.</p>
  <pre><code>using System.Diagnostics;
  using System.IO;
  using MergePdf.Properties;
  using System.Linq;
  using System.Collections;
  using System.Runtime.InteropServices;
  using System.Collections.Generic;
  
  namespace System.Configuration
  {
      class Program
      {
            static void Main(string[] args)
      {
          Console.Title = &quot;MergePDF&quot;;
  
          // Folder from which the PDF will be pulled
          string altDirIn = Settings.Default.AlternativeInputDir;
  
          // Folder in which the merged PDF will be placed
          string altDirOut = Settings.Default.AlternativeOutputDir;
  
          // sort the files by the first name before the &quot;_&quot;
          var rchg = new DirectoryInfo(altDirIn);
          var files1 = rchg.EnumerateFiles(&quot;*.pdf&quot;).OrderBy(fi =&gt; Convert.ToInt32(fi.Name.Split('_')[0]));
          var cmd1 = $&quot;{string.Join(&quot; &quot;, files1.Select(fi =&gt; fi.FullName))} cat output {altDirOut}&quot;;
  
  
  
          var evn = new DirectoryInfo(altDirIn);
          var files2 = evn.EnumerateFiles(&quot;*.pdf&quot;).OrderBy(fi =&gt; Convert.ToInt32(fi.Name.Split('_')[0]));
          var cmd2 = $&quot;{string.Join(&quot; &quot;, files2.Select(fi =&gt; fi.FullName))} cat output {altDirOut}&quot;;
  
          Process p = new Process();
          p.StartInfo.WorkingDirectory = Environment.CurrentDirectory;
          p.StartInfo.FileName = &quot;pdftk.exe&quot;;
          p.StartInfo.Arguments = cmd1;
          p.StartInfo.Arguments = cmd2;
          p.StartInfo.UseShellExecute = false;
          p.StartInfo.RedirectStandardOutput = true;
          p.StartInfo.RedirectStandardError = true;
          p.Start();
  
          Console.WriteLine(p.StandardError.ReadToEnd());
  
          Console.WriteLine(&quot;Bitte drücken Sie eine beliebige Taste, um das Programm zu beenden...&quot;);
  
          Console.ReadKey();
  
          p.WaitForExit();
      }
  }
  }
  </code></pre>
  <p>When I do it this way, I have the problem that if, for example, a pdf has an odd number of pages, then on the back of the last page of the first pdf is the first page of the next pdf.</p>
  <p>How can I proceed so that each pdf gets an even number of pages?</p>
  <p>best regards and thanks in advance</p>