Giter Site home page Giter Site logo

Comments (3)

GManShen avatar GManShen commented on July 18, 2024

i am also facing this issue , any luck?
This happens randomly for me

from ios-htmltopdf.

sorinmiroiu97 avatar sorinmiroiu97 commented on July 18, 2024

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.

chkpnt avatar chkpnt commented on July 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.