Comments (3)
i am also facing this issue , any luck?
This happens randomly for me
from ios-htmltopdf.
From what i've found so far it seems some internal stuff got changed from UIWebView to WKWebView. There were some private apis at play that were facilitating the pdf export process with images in UIWebView, even though you might have been using UIMarkupTextPrintFormatter alongside UIGraphicsBeginPDFContextToData. Now by only changing the webview from UI... to WK... it seems those private apis got changed intentionally or got lost.
Unfortunately I haven't found another way yet on how to generate a pdf by using UIMarkupTextPrintFormatter so you can generate it without previewing it first.
Although I have found a solution that works, but implies rendering the html in a WKWebView first and then instead of using UIMarkupTextPrintFormatter you grab the webview's viewPrintFormatter() and by using this one you can generate the pdf with images just fine.
Here's a helpful link: https://stackoverflow.com/questions/49824797/generate-pdf-from-html-in-wkwebview-with-images
EDIT:
Using a UIMarkupTextPrintFormatter does actually work. I tested it myself and it actually works.
For a full explanation and more info please check on this link the comment to this answer: "SWIFT 3: It took me a while to figure this out, but if you use the prefix "file://" in front of your URL, then it'll work. Like so:". The comment is like this: "Actually, you will also need to wait some time after calling UIMarkupTextPrintFormatter(). Rendering takes some time, so if you export to pdf right away, your images have not finished rendering and will not show in the pdf document. More on this here: https://stackoverflow.com/questions/40239515/uimarkuptextprintformatter-never-renders-base64-images - Quoc Anh Tran".
Safe travels, brave adventurers.
from ios-htmltopdf.
I had no issues with images until iOS 16.4 SDK: If the app is build with Xcode 14.2, the images are present on all devices, but since Xcode 14.3, the images are only present in the PDF when not running on a device with iOS 16.4 or later.
I just compared my NDHTMLtoPDF.m
with the one in this repository. I've
[webview.configuration.preferences setValue:@"TRUE" forKey:@"allowFileAccessFromFileURLs"];
in the viewDidLoad
method. It seems, that this is no longer sufficient.
EDIT: It is still working when using img
-tags. It just doesn't work using the background-image
property. It doesn't seem to be related to allowFileAccessFromFileURLs
, as even if a data-url is used, it doesn't work with background-image
. In this case, the WKWebView itself renders the image, but it's not in the exported PDF.
from ios-htmltopdf.
Related Issues (20)
- Content is cropped if too wide HOT 5
- Multiple HTML files to one PDF HOT 1
- Balnk page because of page-break trough CSS HOT 3
- Crashes on iOS8.1 HOT 5
- page breaks HOT 4
- PDF coming in two pages HOT 4
- Images not come in generated pdf HOT 2
- How to get page number display on header HOT 2
- not recognising href tag HOT 1
- Unwanted scale factor when rendering pages
- Swift compatible?
- Carthage support HOT 1
- iPad pdf generate issue HOT 1
- HTMLtoPDF did fail error HOT 1
- increase margin for first page
- Hyperlink not working HOT 1
- Convert multiple HTML to multiple pdf using a for loop.
- Footer for pdf
- pod update not getting latest version
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ios-htmltopdf.