views:

24

answers:

1

Hello fellow coders & codetts

I was wondering, if I needed to create a rich text formatted document using html and css, which will be used inside a UIWebView, could I then insert cocoa calls inside HTML tags? I do this in ruby, and many other langs do this as well, but I do not know if possible on the iphone.

My main goal is to display a report that will pull data from coreData entities, format it to look pretty, and then create a PDF for the user to email or print.

The only reason I am using HTML is that is what someone here @ StackOverflow mentioned that was the best practice for the iphone. But I would really like to be able to just create a PDF without the HTML and UIWebVIew, so If you know how this can be done, by all means do tell, the world wants to know.

thank u for your precious time

A: 

No, you can't (easily) access your Cocoa objects and classes from HTML/JavaScript. You can, however use Cocoa to call JavaScript methods on the loaded webpage. You can use these JavaScript methods to pass data from Cocoa to the web page, and in those JavaScript methods, you can then change the content of the webpage. That would look something like this:

[webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"doSomethingWithString('%@');", stringToPass]];

And on the JavaScript side:

function doSomethingWithString(passedString) {
  // show stuff in webpage
}
Douwe Maan
Wow, thank you for the answer, I had no idea this could be done. Now my javascript, is well, not really there, but hey, I have to learn it at some point, why not now. I will first try a proof of concept before I dive right in. Again thank you.
iAm
No problem ;) If you need any help with your JavaScript, you know where to find us! ('us' meaning: the helpful people at SO)
Douwe Maan
i found this link and it is going to help me out quite a bit, so I thought that others might need it so here it is http://drnicwilliams.com/2008/11/10/to-webkit-or-not-to-webkit-within-your-iphone-app/
iAm