Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 9 "Save PDF to iBooks" with HTML

Tags:

html

ios

pdf

iOS 9 has a new built-in UIActivity of UIActivityTypeOpenInIBooks. It's in the default list of activities in the UI and in header file but I've not been able to find any API documentation for it (yet).

It appears that UIActivityTypeOpenInIBooks will create a PDF in iBooks just fine if you include UIImages in your UIActivityViewController items or return them in your UIActivityItemProvider.

However I'd like to create a PDF with an HTML page containing text and images like Safari does. But I can't seem to find a way to pass the HTML to UIActivityTypeOpenInIBooks in an acceptable way.

I've tried passing the HTML as a String, NSData and NSURL of a file. I've also tried returning an UIMarkupTextPrintFormatter which works fine for printing but not for UIActivityTypeOpenInIBooks.

Providing an HTML string or the UIMarkupTextPrintFormatter both result in the following errors:

2015-09-08 11:35:46.392 MyApp[4599:1492484] ERROR: attempting to save to URL with no printing source (formatter/renderer) set
2015-09-08 11:35:46.393 MyApp[4599:1492484] FAILED! due to error in domain UIPrintErrorDomain with error code 4

Has anyone gotten this working?

like image 837
LenK Avatar asked Sep 08 '15 18:09

LenK


1 Answers

You can convert the html to pdf before saving it to ibooks.

like image 85
Gxp Avatar answered Nov 03 '22 00:11

Gxp