title: Generate PDF with images from HTML in Swift without displaying print interface
body: <p>I generate a PDF in my <code>Swift</code> application from some HTML. I use a <code>UIMarkupTextPrintFormatter</code> and have code similar to <a href="https://gist.github.com/nyg/b8cd742250826cb1471f" rel="noreferrer">this gist</a>. I get the PDF as <code>NSData</code> and attach it to an email. The app does not show the PDF to the user before attaching it.</p>
  
  <p>I'd now like to include some images. Adding their <code>NSURL</code> in HTML with my current PDF generating strategy doesn't work. How can I get <code>NSData</code> of a PDF corresponding to my HTML with images added? Here are some things I've tried:</p>
  
  <ol>
  <li><p><a href="https://stackoverflow.com/a/7072089/137744">This answer</a> suggests embedding the base64 image in the HTML and using <a href="https://developer.apple.com/reference/uikit/uiprintinteractioncontroller" rel="noreferrer"><code>UIPrintInteractionController</code></a>. This does give me a print preview with correctly-embedded images but how do I go from there to <code>NSData</code> corresponding to the PDF output?</p></li>
  <li><p>I've seen some similar suggestions going through <code>UIWebView</code> but those lead to the same issue -- I don't want to show a preview to the user.</p></li>
  </ol>