Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
610 views
in Technique[技术] by (71.8m points)

ios - Generate PDF with images from HTML in Swift without displaying print interface

I generate a PDF in my Swift application from some HTML. I use a UIMarkupTextPrintFormatter and have code similar to this gist. I get the PDF as NSData and attach it to an email. The app does not show the PDF to the user before attaching it.

I'd now like to include some images. Adding their NSURL in HTML with my current PDF generating strategy doesn't work. How can I get NSData of a PDF corresponding to my HTML with images added? Here are some things I've tried:

  1. This answer suggests embedding the base64 image in the HTML and using UIPrintInteractionController. This does give me a print preview with correctly-embedded images but how do I go from there to NSData corresponding to the PDF output?

  2. I've seen some similar suggestions going through UIWebView but those lead to the same issue -- I don't want to show a preview to the user.

question from:https://stackoverflow.com/questions/40368144/generate-pdf-with-images-from-html-in-swift-without-displaying-print-interface

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...