title: Create PDF from HTML and set page size and margin
body: <p>I am trying to create PDF from an HTML page through google-apps-script and set page size to "<strong>Letter</strong>" not "<strong>A4</strong>" (8.26 X 11.69).  I have checked many related posts and have actually figured out background colors, images, etc...  Related <a href="https://stackoverflow.com/questions/55540003/creating-pdf-from-html-background-color-in-the-pdf">Creating PDF from HTML background color in the PDF</a> but I am unable to make any changes to the <strong>page size</strong>.</p>
  
  <pre><code>function htmlToPDF() {
  
    var html = "&lt;h1&gt;Hello world&lt;/h1&gt;"
         + "&lt;p&gt;This is just a paragraph"
         + "&lt;p style='color:red;'&gt;I am red&lt;/p&gt;"
         + "&lt;p style='color:blue;'&gt;I am blue&lt;/p&gt;"
         + "&lt;p style='font-size:50px;'&gt;I am big&lt;/p&gt;"
         + "&lt;table style='border-collapse: collapse; width: 698px; height: 115px; background-color: #C5D9F1;' border='0' cellpadding='10'&gt;"
         + "&lt;tbody&gt;"
         + "&lt;tr&gt;"
         + "&lt;td style='padding: 5px;background-color:powderblue;' nowrap='nowrap'&gt;&lt;strong&gt;Bold with background-color:&lt;/strong&gt;&lt;/td&gt;"
         + "&lt;/tr&gt;"
         + "&lt;/tbody&gt;"
         + "&lt;/table&gt;";
  
    var blob = Utilities.newBlob(html, "text/html", "text.html");
    var pdf = blob.getAs("application/pdf");
  
    DriveApp.createFile(pdf).setName("text.pdf");
  
    MailApp.sendEmail("[your email here ]", "PDF File", "", 
       {htmlBody: html, attachments: pdf});
  }
  </code></pre>
  
  <p>I have tried several approaches to setting the size</p>
  
  <p>1) Adding the following adjusts the margin to zero</p>
  
  <pre><code>&lt;style&gt; @page { margin: 0; }
  </code></pre>
  
  <p>But adding Width &amp; Height as follows, does nothing.</p>
  
  <pre><code>@page { margin: 0; width: 216mm; height: 279mm }
  </code></pre>
  
  <p>and/or</p>
  
  <pre><code>@media print { margin: 0; width: 600px; height: 800px }
  </code></pre>
  
  <p>2) I have even tried to adjust the Width &amp; Height when creating the HTML Output as follows</p>
  
  <pre><code>  var h = HtmlService.createHtmlOutput(myHTML);
    h.setWidth(2550);
    h.setHeight(3300);
  </code></pre>
  
  <p>Thank you...</p>