title: How to set wkhtmltopdf options in ASP.NET Core 3.1 MVC?
body: <p>I am trying to generate a custom PDF using wkhtmltopdf with ASP.NET Core 3.1, here are the docs: <a href="https://wkhtmltopdf.org/usage/wkhtmltopdf.txt" rel="nofollow noreferrer">https://wkhtmltopdf.org/usage/wkhtmltopdf.txt</a></p>
  <p>My main problem is: how and where should I put those options? Inside cshtml? Inside a controller? Where?</p>
  <p>I cannot find documentation over the internet how to use it in ASP.NET Core MVC.</p>
  <p>This is my code that is working ok:</p>
  <pre><code>public async Task&lt;IActionResult&gt; PDF(int? id)
  {
          if(id == null)
          {
              return StatusCode(400);
          }
  
          var comanda = _comandasRepository.Get((int)id);
  
          if(comanda == null)
          {
              return StatusCode(404);
          }
  
          return await _generatePdf.GetPdf(&quot;Views/Comandas/PDF.cshtml&quot;, comanda);
  }
  </code></pre>
  <p>This generates a PDF:</p>
  <p><a href="https://i.stack.imgur.com/hwssp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hwssp.png" alt="enter image description here" /></a></p>
  <p>But if you notice that PDF has margins, I want to remove these margins. I found in the docs that I have to use <code>--margin-top 0</code> but I do not know where to put it to make it work.</p>
  <p>I tried:</p>
  <pre><code>public async Task&lt;IActionResult&gt; PDF(int? id)
  {
      if(id == null)
      {
          return StatusCode(400);
      }
  
      var comanda = _comandasRepository.Get((int)id);
  
      if(comanda == null)
      {
          return StatusCode(404);
      }
  
      return await _generatePdf.GetPdf(&quot;--margin-top 0 Views/Comandas/PDF.cshtml&quot;, comanda);
  }
  </code></pre>
  <p>but does not work, and I tried to put it in a plain html inside cshtml code and didn't work either. My issue looks so simple but I cannot make this work, how do I solve this?</p>