This project has two goals:
- Showing how to convert an HTML page with images into a PDF document, using one of these three methods:
UIMarkupTextPrintFormatterviewPrintFormatter()of eitherWKWebVieworUIWebViewUIPrintInteractionController, the PDF can then be obtain by pinching in the preview presenter by the print controller, it opens up the PDF and it can then be saved by the user. That's a UI only solution...
- Showing that there is clearly a bug (iOS 10) when using
UIMarkupTextPrintFormatterto convert an HTML containing images.
- Run the application.
- Click the
Create PDFbutton, and then choose theUIMarkupTextPrintFormatteroption. - A PDF is generated from the
index.htmlfile and loaded into both aWKWebView(recommended by Apple with iOS 8+) and aUIWebView. - No images show up. Why? Is this a problem with my code?
- Click on
Load HTMLand chooseindex-img.html. The HTML code is loaded into both web views. The HTML code is not the same as the one we used to generate our PDF (but theimgtags are the same). - All images show up, good. At least there's no problem with the HTML code.
- Click on
Create PDFand thenUIMarkupTextPrintFormatteronce more. - Yep, the PDF, created with
UIMarkupTextPrintFormattershows up with images.
This tells me two things:
UIMarkupTextPrintFormattersupportsimgtags. This can also be confirmed by the fact thatPrint PDF>UIMarkupTextPrintFormattershows a PDF with images.- It somehow relies on the web view (or another WebKit class, the cache maybe) to render these images.
The Create PDF > WebView.viewPrintFormatter() action creates a PDF from what each web view is currently displaying, that can either be nothing, one of the HTML loaded beforehand or a PDF loaded from a previous execution.
The Create PDF > UIMarkupTextPrintFormatter action always creates the PDF from the index.html file.
This bug may have been corrected with iOS 11...
A non-UI, macOS & iOS solution would be perfect but I haven't found anything of the sort...