Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images not come in generated pdf #32

Open
gauravthummar opened this issue Nov 4, 2015 · 2 comments
Open

Images not come in generated pdf #32

gauravthummar opened this issue Nov 4, 2015 · 2 comments

Comments

@gauravthummar
Copy link

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
Copy link

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
Copy link

pankaj002 commented Dec 8, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants