iclems / iOS-htmltopdf

MIT License
305 stars 79 forks source link

createPDFWithHTML and images #23

Closed Sun3 closed 10 years ago

Sun3 commented 10 years ago

I am having issues to have images show up with the createPDFWithHTML. In the PDF File that is created I see the image tag but not the actual image.

Since the images are stored as external binary files in Core Data, how would you pass each image as an HTML tag?

<img src="file:ImageFromCoreData">
or 
<img src="ImageFromCoreData">

Any ideas?

Sun3 commented 10 years ago

If anyone else is having the same issue below is what I did.

NSString *stringImageBase64 = [UIImageJPEGRepresentation([[UIImage imageWithData:[imagesNamesArray objectAtIndex:0], 0.5) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

htmlString = [htmlString stringByAppendingString:[NSString stringWithFormat:@"<div align=\"left\"><img src=\"data:image/png;base64,%@\" align=\"absmiddle\" /> </div>", stringImageBase64]];
iclems commented 10 years ago

Thanks for the quick tip!