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 8075937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:09:30+00:00 2026-06-05T15:09:30+00:00

I have a RTF file which I can view on iphone , Now I

  • 0

I have a RTF file which I can view on iphone , Now I need to edit the file programmatically , please let me know how can I do it.
Example
RTF file content
“I am new to StackOverflow”
Now I need to change to below line programmatically.
“I regularly visit StackOverflow” and save as PDF file.
Please do help me 🙂

Thanks in advance 🙂

  • 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-06-05T15:09:31+00:00Added an answer on June 5, 2026 at 3:09 pm

    In your .h file add some objects and defines

    #define kBorderInset            20.0
    #define kBorderWidth            1.0
    #define kMarginInset            10.0
    
    @interface ViewController : UIViewController
    {
        CGSize pageSize;
        NSString *pdfFileName;
        NSString *contents_for_pdf;
    }
    
    - (void)generatePdfWithFilePath:(NSString *)thefilePath;
    

    in .m file add this lines some where on button click to get contents of rtf file in string

    NSString *rtf_path = [[NSBundle mainBundle] pathForResource:@"example" ofType:@"rtf"];
    contents_for_pdf = [[NSString alloc] initWithContentsOfFile:rtf_path encoding:NSUTF8StringEncoding error:nil];
    NSLog(@"%@",contents_for_pdf);
    contents_for_pdf = [contents_for_pdf stringByReplacingOccurrencesOfString:@"I am new to StackOverflow" withString:@"I regularly visit StackOverflow"];
    
    pageSize = CGSizeMake(612, 792);
    NSString *fileName = @"Demo.pdf";
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    pdfFileName = [documentsDirectory stringByAppendingPathComponent:fileName];
    
    [self generatePdfWithFilePath:pdfFileName];
    

    I didnt modify the text of rtf file,I just used same text in rtf file.you should do as you want(I noticed some encoding characters in text) and function that will generate pdf is here.

    - (void) generatePdfWithFilePath: (NSString *)thefilePath
    {
        UIGraphicsBeginPDFContextToFile(thefilePath, CGRectZero, nil);
        //Start a new page.
        UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, pageSize.width, pageSize.height), nil);
    
        //Draw text fo our header.
    
        CGContextRef    currentContext = UIGraphicsGetCurrentContext();
        CGContextSetRGBFillColor(currentContext, 0.0, 0.0, 0.0, 1.0);
    
        UIFont *font = [UIFont systemFontOfSize:14.0];
    
        CGSize stringSize = [contents_for_pdf sizeWithFont:font
                                         constrainedToSize:CGSizeMake(pageSize.width - 2*kBorderInset-2*kMarginInset, pageSize.height - 2*kBorderInset - 2*kMarginInset) 
                                             lineBreakMode:UILineBreakModeWordWrap];
    
        CGRect renderingRect = CGRectMake(kBorderInset + kMarginInset, kBorderInset + kMarginInset + 50.0, pageSize.width - 2*kBorderInset - 2*kMarginInset, stringSize.height);
    
        [contents_for_pdf drawInRect:renderingRect 
                            withFont:font
                       lineBreakMode:UILineBreakModeWordWrap
                           alignment:UITextAlignmentLeft];
    
        UIGraphicsEndPDFContext();
    
        UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:@"PDF Created" message:@"Sucessfull" delegate:self cancelButtonTitle:@"ok" otherButtonTitles:nil, nil];
        [Alert show];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have deployed numerous report parts which reference the same view however one of them
All,In my requirement need to send a mail with attached text file, which is
In my app I have a UIWebView which loads different rtf files. I use
I have a .rtf file and want to put it in a richtextbox in
We have some code which produces an RTF document from a RTF template. It
I have an VB.Net/C# application that programmatically: Creates an RTF document Open it up
Question I want to programmatically open a RTF file in Microsoft Word using C#.
I'm trying Perl on Mac. I have to read an RTF text file. the
I have an Agree And Conditions file ( rtf document ) and/or a disclaimer
I have a rtf file. I want to open that file using Ruby for

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.