title: Get HTML String from NSAttributedString
body: <p>There is a feature in my project where I have to bold the text and save it. Next time when I revisit the screen the bold text should appear.   </p>
  
  <p>I am getting bold text with help of <code>NSAttributedString</code>. Below is the code for the same:  </p>
  
  <pre><code>- (void)makeBoldText1:(UITextField *)txtText {
      UIFont *regularFont = [UIFont fontWithName:@"PFIsotextPro-Regular" size:18];
      UIFont *boldFont = [UIFont fontWithName:@"PFIsotextPro-Bold" size:18];
      UIFont *italicFont = [UIFont fontWithName:@"PFIsotextPro-Italic" size:18];
      UIFont *boldItalicFont = [UIFont fontWithName:@"PFIsotextPro-BoldItalic" size:18];
  
      NSString *selectedText = [txtText textInRange:txtText.selectedTextRange];
      CGRect someRect = CGRectMake(0.0, 0.0, 100.0, 30.0);
      UITextField* textfield = [[UITextField alloc] initWithFrame:someRect];
  
      NSString *text1 = txtText.text;
      NSRange range = [text1 rangeOfString:selectedText];
  
      NSAttributedString *text = txtText.attributedText;
      NSMutableAttributedString *mutable = [[NSMutableAttributedString alloc] initWithAttributedString:text];
  
      NSAttributedString *str = [mutable attributedSubstringFromRange:range];
      textfield.attributedText = str;
      if(textfield.font.fontName == regularFont.fontName) {
          textfield.font = boldFont;
      } else if(textfield.font.fontName == boldFont.fontName) {
          textfield.font = regularFont;
      } else if(textfield.font.fontName == italicFont.fontName) {
          textfield.font = boldItalicFont;
      } else if(textfield.font.fontName == boldItalicFont.fontName) {
          textfield.font = italicFont;
      }
      [mutable addAttribute: NSFontAttributeName value:textfield.font range:range];
      txtText.attributedText = mutable;
  }
  </code></pre>
  
  <p>Now above code works fine but I want to convert it to HTML string with  and all appropriate tags. Once I get the HTML string with all tags, I will save it in Core Data and next time when I revisit screen I will convert HTML to <code>NSAttributedString</code>.   </p>
  
  <p>The problem is when I try to get the HTML string, it doesn't work. It returns some weird CSS. Is there a way to convert the mutable string to HTML string?</p>
  
  <p>I have tried something like below code but it doesn't work:  </p>
  
  <pre><code>NSAttributedString *s = _txtCompany.attributedText;
  NSDictionary *documentAttributes = [NSDictionary dictionaryWithObjectsAndKeys:NSHTMLTextDocumentType, NSDocumentTypeDocumentAttribute, nil];
  NSData *htmlData = [s dataFromRange:NSMakeRange(0, s.length) documentAttributes:documentAttributes error:NULL];
  NSString *htmlString = [[NSString alloc] initWithData:htmlData encoding:NSUTF8StringEncoding];
  UIWebView *webView = [[UIWebView alloc]init];
  
  [webView loadHTMLString:htmlString baseURL:nil];
  NSString *BodyHTML =  [webView stringByEvaluatingJavaScriptFromString:htmlString];
   NSLog(@"%@:",BodyHTML);
  </code></pre>
  
  <p>Thanks in advance.</p>