Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:09:50+00:00 2026-05-23T23:09:50+00:00

I am getting the text in html format in my iPhone application. I need

  • 0

I am getting the text in html format in my iPhone application. I need to take the printout of the page but I don’t want that tags are also shown in the print out in simple text.

How can this be done in my iPhone application to have the print functionality which prints the html document directly but not the html tags?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:09:51+00:00Added an answer on May 23, 2026 at 11:09 pm

    Here, you can use the following function to pring the html page in iPhone app.

    (1) This method in the controller where to print html.

    - (IBAction) btnPrint_Clicked:(id)sender
    {
        NSString *htmlData = @"Your HTML Text";        
        [appDelegate.myWebView loadHTMLString:htmlData baseURL:nil];
    
        [appDelegate printWebPage:[NSString stringWithFormat:@"Employee - %@ %@",[dicEmployeeData valueForKey:@"firstname"],[dicEmployeeData valueForKey:@"lastname"]]];
    }
    

    (2) This method in the appDelegate class and also import MyPrintPageRenderer.h

    #import "MyPrintPageRenderer.h".
    
    - (void) printWebPage:(NSString *)title
    {
        printController = [UIPrintInteractionController sharedPrintController];
        if(!printController){
            NSLog(@"Couldn't get shared UIPrintInteractionController!");
            return;
        }
    
        UIPrintInteractionCompletionHandler completionHandler = 
        ^(UIPrintInteractionController *printController, BOOL completed, NSError *error) {
            if(!completed && error){
                NSLog(@"FAILED! due to error in domain %@ with error code %u", error.domain, error.code);   
            }
        };
    
    
        // Obtain a printInfo so that we can set our printing defaults.
        UIPrintInfo *printInfo = [UIPrintInfo printInfo];
        // This application produces General content that contains color.
        printInfo.outputType = UIPrintInfoOutputGeneral;
        // We'll use the URL as the job name
        printInfo.jobName = title;
        // Set duplex so that it is available if the printer supports it. We
        // are performing portrait printing so we want to duplex along the long edge.
        printInfo.duplex = UIPrintInfoDuplexLongEdge;
        // Use this printInfo for this print job.
        printController.printInfo = printInfo;
    
        // Be sure the page range controls are present for documents of > 1 page.
        printController.showsPageRange = YES;
    
        // This code uses a custom UIPrintPageRenderer so that it can draw a header and footer.
        MyPrintPageRenderer *myRenderer = [[MyPrintPageRenderer alloc] init];
        // The MyPrintPageRenderer class provides a jobtitle that it will label each page with.
        myRenderer.jobTitle = printInfo.jobName;
        // To draw the content of each page, a UIViewPrintFormatter is used.
        UIViewPrintFormatter *viewFormatter = [myWebView viewPrintFormatter];
    
    #if SIMPLE_LAYOUT
        /*
         For the simple layout we simply set the header and footer height to the height of the
         text box containing the text content, plus some padding.
    
         To do a layout that takes into account the paper size, we need to do that 
         at a point where we know that size. The numberOfPages method of the UIPrintPageRenderer 
         gets the paper size and can perform any calculations related to deciding header and
         footer size based on the paper size. We'll do that when we aren't doing the simple 
         layout.
         */
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT]; 
        CGSize titleSize = [myRenderer.jobTitle sizeWithFont:font];
        myRenderer.headerHeight = myRenderer.footerHeight = titleSize.height + HEADER_FOOTER_MARGIN_PADDING;
    #endif
        [myRenderer addPrintFormatter:viewFormatter startingAtPageAtIndex:0];
        // Set our custom renderer as the printPageRenderer for the print job.
        printController.printPageRenderer = myRenderer;
        [myRenderer release];
    
        // The method we use presenting the printing UI depends on the type of 
        // UI idiom that is currently executing. Once we invoke one of these methods
        // to present the printing UI, our application's direct involvement in printing
        // is complete. Our custom printPageRenderer will have its methods invoked at the
        // appropriate time by UIKit.
    
        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        {
            if(orientationStyle == 1)
                [printController presentFromRect:CGRectMake(510, 150, 0, 0) inView:self.window animated:YES completionHandler:completionHandler];
            else
                [printController presentFromRect:CGRectMake(770, 165, 0, 0) inView:self.window animated:YES completionHandler:completionHandler];
        }
        else
            [printController presentAnimated:YES completionHandler:completionHandler];  // iPhone
    }
    

    (3) Here you also need to add one class file for the print functionality:

    MyPrintPageRenderer.h File

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    
    /*
      Setting SIMPLE_LAYOUT to 1 uses a layout that involves less application code and
      produces a layout where the web view content has margins that are relative to
      the imageable area of the paper.
    
      Setting SIMPLE_LAYOUT to 0 uses a layout that involves more computation and setup
      and produces a layout where the webview content is inset 1/2 from the edge of the 
      paper (assuming it can be without being clipped). See the comments in 
      MyPrintPageRenderer.m immediately after #if !SIMPLE_LAYOUT.
    */
    #define SIMPLE_LAYOUT 1
    
    // The point size to use for the height of the text in the
    // header and footer.
    #define HEADER_FOOTER_TEXT_HEIGHT     10
    
    // The left edge of text in the header will be offset from the left 
    // edge of the imageable area of the paper by HEADER_LEFT_TEXT_INSET.
    #define HEADER_LEFT_TEXT_INSET        20
    
    // The header and footer will be inset this much from the edge of the
    // imageable area just to avoid butting up right against the edge that
    // will be clipped.
    #define HEADER_FOOTER_MARGIN_PADDING  5
    
    // The right edge of text in the footer will be offset from the right 
    // edge of the imageable area of the paper by FOOTER_RIGHT_TEXT_INSET.
    #define FOOTER_RIGHT_TEXT_INSET       20
    
    #if !SIMPLE_LAYOUT
    
    // The header and footer content will be no closer than this distance
    // from the web page content on the printed page.
    #define MIN_HEADER_FOOTER_DISTANCE_FROM_CONTENT 10
    
    // Enforce a minimum 1/2 inch margin on all sides.
    #define MIN_MARGIN 36
    
    #endif
    
    @interface MyPrintPageRenderer : UIPrintPageRenderer {
      NSRange pageRange;
      NSString *jobTitle;
    }
    
    @property (readwrite, retain) NSString *jobTitle;
    
    @end
    

    MyPrintPageRenderer.m File

    #import "MyPrintPageRenderer.h"
    #import <CoreGraphics/CoreGraphics.h>
    
    @implementation MyPrintPageRenderer
    
    @synthesize jobTitle;
    
    #if !SIMPLE_LAYOUT
    /*
     For the case where we are not doing SIMPLE_LAYOUT, this code does the following:
     1) Makes the minimum margin for the content of the content portion of the printout (i.e.
        the webpage) at least 1/4" away from the edge of the paper. If the hardware margins
        of the paper are greater than that, then the hardware margins will force the content
        margins to be as large as they allow.
     2) Because this format is relative to the edge of the sheet rather than the imageable area, we
        need to compute these values once we know the paper size and printableRect. This is known
        in the numberOfPages method and that is the reason this code overrides that method.
     3) Since the header and footer heights of a UIPrintFormatter plays a part in determining height of
        of the content area, this code computes those heights, taking into account that we want
        the minimum 1/4" margin on the content.
     4) This code also enforces a minimum distance (MIN_HEADER_FOOTER_DISTANCE_FROM_CONTENT)
        between the header and footer and the content area.
     5) Note that the insets used for the contentInsets property of a UIPrintFormatter are relative
        to the imageable area of the paper being printed upon. The header and footer height are also
        imposed relative to the edge of the top and bottom hardware margin. 
    */
    
    
    // Compute an edge inset to produce the minimum margin
    // based on the imageable area margin of the edge.
    static inline CGFloat EdgeInset(CGFloat imageableAreaMargin)
    {
      /*
        Since the offsets specified to a print formatter are relative 
        to printRect and we want our edges to be at least MIN_MARGIN
        from the edge of the sheet of paper, here we compute the necessary
        offset to achieve our margin. If the imageable area margin is
        larger than our MIN_MARGIN, we return an offset of zero which means
        that the imageable area margin will be used.
      */
      CGFloat val = MIN_MARGIN - imageableAreaMargin;
      return val > 0 ? val : 0;
    }
    
    // Compute a height for the header or footer, based on the margin for the edge
    // in question and the height of the text being drawn.
    static CGFloat HeaderFooterHeight(CGFloat imageableAreaMargin, CGFloat textHeight)
    {
      /*
        Make the header and footer height provide for a minimum margin of MIN_MARGIN. We
        want the content to appear at least MIN_HEADER_FOOTER_DISTANCE_FROM_CONTENT from
        the header/footer text. If that requires a margin > MIN_MARGIN then we'll use that.
        Remember, the header/footer height returned needs to be relative to the edge of 
        the imageable area.
      */
      CGFloat headerFooterHeight = imageableAreaMargin + textHeight + 
            MIN_HEADER_FOOTER_DISTANCE_FROM_CONTENT + HEADER_FOOTER_MARGIN_PADDING;
      if(headerFooterHeight < MIN_MARGIN)
        headerFooterHeight = MIN_MARGIN - imageableAreaMargin;
      else {
        headerFooterHeight -= imageableAreaMargin;
      }
    
      return headerFooterHeight;
    }
    
    /*  Override numberOfPages so we can compute the values for our UIPrintFormatter based on the
        paper used for the print job. When this is called, self.paperRect and self.printableRect
        reflect the paper size and imageable area of the destination paper.
    */
    - (NSInteger)numberOfPages
    {
      // We only have one formatter so obtain it so we can set its paramters.
      UIPrintFormatter *myFormatter = (UIPrintFormatter *)[self.printFormatters objectAtIndex:0];
    
      // Compute insets so that margins are 1/2 inch from edge of sheet, or at
      // the edge of the imageable area if it is larger than that. The EdgeInset
      // function takes a margin for the edge being calculated.
      CGFloat leftInset = EdgeInset(self.printableRect.origin.x);
      CGFloat rightInset = EdgeInset(self.paperRect.size.width - CGRectGetMaxX(self.printableRect));
    
      // Top inset is only used if we want a different inset for the first page and we don't.
      // The bottom inset is never used by a viewFormatter.
      myFormatter.contentInsets = UIEdgeInsetsMake(0, leftInset, 0, rightInset);
    
      // Now compute what we want for the header size and footer size. These determine the
      // size and placement of the content height.
    
      // First compute the 
      UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT]; 
      // We'll use the same title height for the header and footer. This is the minimum height 
      // the footer can be. 
      CGFloat titleHeight = [self.jobTitle sizeWithFont:font].height;
    
      /*
        We want to calculate these heights so that the content top and bottom
        edges are a minimum distance from the edge of the sheet and are inset at least
        MIN_HEADER_FOOTER_DISTANCE_FROM_CONTENT from the header and footer.
      */
      self.headerHeight = HeaderFooterHeight(CGRectGetMinY(self.printableRect), titleHeight); 
      self.footerHeight = HeaderFooterHeight(self.paperRect.size.height - CGRectGetMaxY(self.printableRect), titleHeight); 
    
      // Just to be sure, never allow the content to go past our minimum margins for the content area.
      myFormatter.maximumContentWidth = self.paperRect.size.width - 2*MIN_MARGIN;
      myFormatter.maximumContentHeight = self.paperRect.size.height - 2*MIN_MARGIN;
    
    
      /*
          Let the superclass calculate the total number of pages. Since this UIPrintPageRenderer only uses a UIPrintFormatter,
          the superclass knows the number of pages based on the formatter metrics and the paper/printable rects. 
    
          Note that since this code only uses a single print formatter we could just as easily use myFormatter.pageCount 
          to obtain the total number of pages. But it would be more complex than that if we had multiple printformatters 
          for our job so we're using a more general approach here for illustration and it is correct for 1 or more formatters.
       */
      return [super numberOfPages];
    }
    
    #endif
    
    /*
     Our pages don't have any intrinsic notion of page
     number; our footer will number the pages so that users
     know the order. So for us, we will always render the first
     page printed as page 1, even if the range is n-m.
     So we track which page in the range is the first index
     as well as the total length of our range.
    */
    - (void)prepareForDrawingPages:(NSRange)range
    {
      pageRange = range;
      [super prepareForDrawingPages:range];
    }
    
    - (void)drawHeaderForPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)headerRect
    {
      if(self.jobTitle){
        UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT]; 
        // Position the title starting from the left and inset slightly from the left edge of the imageable area.
        CGFloat startX = CGRectGetMinX(headerRect) + HEADER_LEFT_TEXT_INSET;
        // The header will always be a fixed amount inset from edge of the the imageable area of the paper.
        // The point passed to drawAtPoint is at the top-left of the text that will be drawn, hence
        // the starting point is the y coordinate of the top of the imageable area rect plus any padding.
        CGFloat startY = self.printableRect.origin.y + HEADER_FOOTER_MARGIN_PADDING; 
        CGPoint startPoint = CGPointMake(startX, startY);
        [self.jobTitle drawAtPoint:startPoint withFont: font];
      }
    }
    
    
    - (void)drawFooterForPageAtIndex:(NSInteger)pageIndex inRect:(CGRect)footerRect 
    {
      NSString *localizedPageNumberString = NSLocalizedString(@"Page %d of %d", @"Localized Page Count String");
      // Compute the page numbers so that the first page in the range being 
      // printed is always page 1 of N, where N is the total number of pages.
      NSString *pageNumberString = [NSString stringWithFormat:localizedPageNumberString,
                      pageIndex+1 - pageRange.location, pageRange.length]; 
      UIFont *font = [UIFont fontWithName:@"Helvetica" size:HEADER_FOOTER_TEXT_HEIGHT];
      CGSize pageNumSize = [pageNumberString sizeWithFont:font]; 
      // Position the page number string so that it ends inset by FOOTER_RIGHT_TEXT_INSET from the right edge
      // of the imageable area.
      CGFloat startX = CGRectGetMaxX(footerRect) - pageNumSize.width - FOOTER_RIGHT_TEXT_INSET; 
      // The footer will always be a fixed amount inset from the bottom edge of the imageable area of the paper.
      // The point passed to drawAtPoint is the top-left of the text that will be drawn, hence
      // the height needs to be subtracted from the starting point.
      CGFloat startY = CGRectGetMaxY(self.printableRect) - pageNumSize.height - HEADER_FOOTER_MARGIN_PADDING; 
      CGPoint startPoint = CGPointMake(startX, startY); 
    
      [pageNumberString drawAtPoint:startPoint withFont: font];
    }
    
    @end
    

    Let me know if you need more help. It will pring the html document as you required.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want a format html using CSS so that I get the following: Image
I have a huge text that i keep getting in a json format. When
I am getting some HTML text from a remote server which I am displaying
I am getting a large text file of updated information from a customer that
I am having problems getting text within a table to appear centered in IE.
I have a case where i'm getting formatted text with <a href ...> ,
Greetings! I'm having a problem getting a text value of a captcha from a
Is there a search API for getting a short text containing the search terms
The text lables in my UITableViewCells are getting displayed differently on the device than
I am getting this error alt text http://img239.imageshack.us/img239/6936/jserror.png when the map loads. The error

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.