UIMarkupTextPrintFormatter PDF creation with custom background and transparent HTML content UIMarkupTextPrintFormatter PDF creation with custom background and transparent HTML content swift swift

UIMarkupTextPrintFormatter PDF creation with custom background and transparent HTML content


This isn't a guarantee, but as Yvonne mentioned, it's possible that your PDF renderer just doesn't support transparent as a color value.

Possible Solution A

Try creating a 1px by 1px PNG image with just one 100% transparent pixel, then set that as a repeating background image on your element.

Possible Solution B

It's possible that the HTML element itself is white when this library renders it. You can apply CSS to the html tag the same way you did with body.

Possible Solution C

If I understand your case correctly, you're trying to overlay a rendered PDF which is inside of a UIWebView on top of other in-app content. I can't speak to whether a PDF can really support transparency. The UIWebView may have its own properties required (not to mention there may be a PDF viewer with a default background of white in play). If you have control of the UIWebView's styles, take a look at this: How to make a transparent UIWebView

Possible Solution D

Maybe it would be better to use a Canvas (either HTML or Switft) to render an image instead of a PDF. If this works for your use case, it may be a much better option long-term.


Solved the problem by switching to a different UIPrintFormatter. Switched from UIMarkupTextPrintFormatter to UIViewPrintFormatter which honoured the transparency.