title: Getting flextable to knit to PDF
body: <p>I feel like I've gone down a rabbit hole when all I want is some nice tables in my pdf.  Long story, here goes:</p>
  <p>I want to print some tables to a PDF from r markdown.  I usually use Kable and it works fine.  That being said, this table is going to have some really long values, and an unknown number of columns that get generated, and I was having a hard time specifying which column would be what width when I didn't know yet in kable.  Anyhow, that led me to flextable.</p>
  <p>When I knit to html, the table looks great, like so:
  <a href="https://i.stack.imgur.com/8gBQX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8gBQX.png" alt="enter image description here" /></a></p>
  <p>But I'm having trouble knitting to pdf.  I understand, via other stack answers, that flextable's need to be saved as images to be plotted to pdf. So I have code like this:</p>
  <pre><code>ft &lt;- flextable(x)
  ft &lt;- autofit(ft)
  tf &lt;- tempfile(fileext = &quot;.png&quot;)
  ## Not run: 
  if( require(&quot;webshot2&quot;) ){
   save_as_image(x = ft, path = &quot;myimage.png&quot;)
  }
  
  plot(tf)
  </code></pre>
  <p>But at first it gave me the error that I didn't have the webshot2 package, so after some trouble I installed that (it didn't line up with my version of R (I'm on rstudio.cloud) and then when I try to run it now, it says <a href="https://i.stack.imgur.com/JYhr8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JYhr8.png" alt="enter image description here" /></a></p>
  <p>Am I missing something obvious?  How do I save a flextable as an image and then plot it in my pdf?</p>
  <p>I've also tried Joanna's solution here: <a href="https://stackoverflow.com/questions/40516169/is-it-possible-to-generate-the-rtable-flextable-in-pdf-with-rmarkdown">Is it possible to generate the RTable (FlexTable) in pdf with RMarkdown?</a>  and r tells me could not find function &quot;as.html&quot;. Even though both flextable and htmltools have been loaded.</p>
  <p>P.s. providing reproducible data would be very long given all the code that generates the tables and the fact I need it to knit into a pdf, will provide rstudio.cloud link if anyone is interested</p>