Image loaded from the Xcode project with relative path:
16 |
17 |
Image loaded from the Xcode project with absolute path:
18 |
19 |
Image loaded from a Base64-encoded string:
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | BSD 3-Clause License
2 |
3 | Copyright (c) 2017,
4 | All rights reserved.
5 |
6 | Redistribution and use in source and binary forms, with or without
7 | modification, are permitted provided that the following conditions are met:
8 |
9 | * Redistributions of source code must retain the above copyright notice, this
10 | list of conditions and the following disclaimer.
11 |
12 | * Redistributions in binary form must reproduce the above copyright notice,
13 | this list of conditions and the following disclaimer in the documentation
14 | and/or other materials provided with the distribution.
15 |
16 | * Neither the name of the copyright holder nor the names of its
17 | contributors may be used to endorse or promote products derived from
18 | this software without specific prior written permission.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # HTMLWithImagesToPDF
2 |
3 | ## Description
4 |
5 | This app showcases the following:
6 |
7 | 1. Loading an HTML file into a web view (actually both a `WKWebView` and `UIWebView`),
8 | 2. Generating a PDF using either
9 | 1. the web views' `viewPrintFormatter()` or
10 | 2. a `UIMarkupTextPrintFormatter`,
11 | 3. Printing a PDF using either
12 | 1. one of the web views' `viewPrintFormatter()` or
13 | 2. a `UIMarkupTextPrintFormatter`
14 |
15 |
16 | ## Bug
17 |
18 | Generating a PDF using a `UIMarkupTextPrintFormatter` will not render the images of the HTML file. Unless the HTML code has been loaded into a web view beforehand.
19 |
20 | 1. Run the application.
21 | 2. Tap `Create PDF` and then `UIMarkupTextPrintFormatter`: a PDF is generated from the `index.html` file and loaded into both a `WKWebView` and a `UIWebView`. Images are not rendered.
22 | 3. Tap `Load HTML` and then `index-img.html`: the HTML code is loaded into both web views and the images are displayed. The HTML code is not the same as the one we used to generate our PDF (**but the `img` tags are the same**).
23 | 7. Re-do step 1: tap `Create PDF` and then `UIMarkupTextPrintFormatter`: another PDF is generated and loaded into the web views. And this time **with** images.
24 |
25 | This behavior tells me that `UIMarkupTextPrintFormatter` does support `img` tags. Also confirmed by the fact that `Print PDF` > `UIMarkupTextPrintFormatter` shows a PDF with images (actually only one image is displayed).
26 |
27 | ## Note
28 |
29 | 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.
30 |
31 | The `Create PDF` > `UIMarkupTextPrintFormatter` action always creates the PDF from the `index.html` file.
--------------------------------------------------------------------------------