iclems / iOS-htmltopdf

MIT License
305 stars 79 forks source link

Images not come in generated pdf #32

Open gauravthummar opened 8 years ago

gauravthummar commented 8 years ago

i create html and put it my bundle. this html contain image that i also put i my application bundle. the image also display in my simulator webview. but when i try to make pdf then generated pdf dose not contain my images. please let me know any thing i need to modify to get pdf with my images.

MattFedo commented 8 years ago

Try something like this:

NSData *imageData = UIImageJPEGRepresentation([UIImage imageNamed:@"IMAGENAME.jpg"], 1); NSString *stringBase64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];

NSString *html = @""; html = [html stringByAppendingString:[NSString stringWithFormat:@"<div align=\"left\"><img src=\"data:image/jpg;base64,%@\" align=\"absmiddle\" style=\"width:100%% \" /> </div>", stringBase64]];

PDFCreator = [NDHTMLtoPDF createPDFWithHTML:html pathForPDF:[@"~/Documents/manualDemo.pdf" stringByExpandingTildeInPath] delegate:self pageSize:kPaperSizeA4 margins:UIEdgeInsetsMake(10, 5, 10, 5)];

pankaj002 commented 2 years ago

i tried that also but still not working for me

if let img = UIImage(data: imgData), let newImgData = img.jpegData(compressionQuality: 0.2) { arrImages.append(newImgData) } let base64String = arrImages[0].base64EncodedString(options: .lineLength64Characters) <img style=\"margin-top:10px\" src='data:image/png;base64,\(String(describing: base64String) )>

it's not working in 3/10 times, means when run PDF generate then 3 times approx nor working, don't know why it happen