Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate PDF from HTML in WKWebView with images

I'm trying to generate a invoice PDF in my app. The idea is that invoice can be printed and than generate a PDF to send by email later.

All is working, including the print format, but when i export to PDF the logo image in PDF disappear.

This my original HTML in WKWebView

enter image description here This is my printable version

But when i export to PDF it looks like this: enter image description here The logo is missing.

My HTML is this:

        <tr>
            <td>
                <table class="headerTable">
                    <tr>
                        <td width="33%"><img src="logo.png" style="width:80%; max-width:250px"></td>
                        <td width="1%"></td>
                        <td width="33%"><b>Realengo</b><br>Avenida Santa Cruz 1251<br>Realengo - Rio de Janeiro<br>Telefone: (21) 2401-0271</td>
                        <td width="33%"><b>Centro</b><br>Rua Buenos Aires 111<br>Centro - Rio de Janeiro<br>Telefone: (21) 2151-1189</td>
                    </tr>
                </table>
            </td>
        </tr>

Does anyone figure out why my image is not in PDF?

like image 412
Vinícius Barcelos Avatar asked Apr 13 '18 20:04

Vinícius Barcelos


1 Answers

WKWebView has supported export PDF in iOS14

import PDFKit

let config = WKPDFConfiguration()
 webView.createPDF(configuration: config) { result in
   switch result {
     case .success(let data):
       print("create pdf success: \(data)")
     case .failure(let error):
       print("create pdf failure: \(error)")
     }
  }

https://developer.apple.com/documentation/webkit/wkwebview/3650490-createpdf

like image 168
Jam Avatar answered Oct 17 '22 19:10

Jam