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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:37:17+00:00 2026-05-14T15:37:17+00:00

Has anyone already created a PDF document in an iPad app? I see that

  • 0

Has anyone already created a PDF document in an iPad app? I see that there are new functions in the UIKit to do this, but I can’t find any code example for it.

BOOL UIGraphicsBeginPDFContextToFile (
   NSString *path,
   CGRect bounds,
   NSDictionary *documentInfo
);

void UIGraphicsBeginPDFPage (
   void
);

I found an example that is supposed to work on the iPhone, but this gives me errors:

Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: CGFont/Freetype: The function `create_subset' is currently unimplemented.
Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: invalid Type1 font: unable to stream font.
Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: FT_Load_Glyph failed: error 6.
Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: FT_Load_Glyph failed: error 6.
Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: FT_Load_Glyph failed: error 6.
Fri Apr 30 11:55:32 wks104.hs.local PDF[1963] <Error>: FT_Load_Glyph failed: error 6.
  • 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-14T15:37:17+00:00Added an answer on May 14, 2026 at 3:37 pm

    This is a better solution as it uses the correct coordinate transform to get the text to print from the top down.

    #define LEFT_MARGIN 25
    #define RIGHT_MARGIN 25
    #define TOP_MARGIN 35
    #define BOTTOM_MARGIN 50
    #define BOTTOM_FOOTER_MARGIN 32
    #define DOC_WIDTH 595
    #define DOC_HEIGHT 842
    
    - (void) createPDF:(NSString *)fileName withContent:(NSString *)content forSize:(int)fontSize andFont:(NSString *)font andColor:(UIColor *)color
    {
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *newFilePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:fileName];
    
        CGRect a4Page = CGRectMake(0, 0, DOC_WIDTH, DOC_HEIGHT);
    
        NSDictionary *fileMetaData = [[NSDictionary alloc] init];
    
        if (!UIGraphicsBeginPDFContextToFile(newFilePath, a4Page, fileMetaData )) {
            NSLog(@"error creating PDF context");
            return;
        }
    
        CGContextRef context = UIGraphicsGetCurrentContext();
        UIGraphicsBeginPDFPage();
    
        CGContextSetTextDrawingMode (context, kCGTextFill);
        CGContextSelectFont (context, [font cStringUsingEncoding:NSUTF8StringEncoding], fontSize, kCGEncodingMacRoman);                                                 
        CGContextSetFillColorWithColor(context, [color CGColor]);
    
        CGMutablePathRef path = CGPathCreateMutable();
    
        CGRect bounds = CGRectMake(LEFT_MARGIN, 
                                   TOP_MARGIN, 
                                   DOC_WIDTH - RIGHT_MARGIN - LEFT_MARGIN, 
                                   DOC_HEIGHT - TOP_MARGIN - BOTTOM_MARGIN
                                   );
    
        CGPathAddRect(path, NULL, bounds);
    
        // Initialize an attributed string.
        CFMutableAttributedStringRef attrString =
        CFAttributedStringCreateMutable(kCFAllocatorDefault, 0);
        CFAttributedStringReplaceString (attrString, CFRangeMake(0, 0), (CFStringRef)content);
    
        // Create the framesetter with the attributed string.
        CTFramesetterRef framesetter =
        CTFramesetterCreateWithAttributedString(attrString);
    
        // Create the frame and draw it into the graphics context
        CTFrameRef frame = CTFramesetterCreateFrame(framesetter, CFRangeMake(0, 0), path, NULL);
        CFRange visibleRange = CTFrameGetVisibleStringRange(frame);
    
        if (visibleRange.length < [content length] ) {
            NSLog(@"WARNING: Not all displayed on a single page");
        }
    
        CFRelease(attrString);
        CFRelease(framesetter);
    
        if(frame) {
            CGContextSaveGState(context);
            CGContextTranslateCTM(context, 0, bounds.origin.y); 
            CGContextScaleCTM(context, 1, -1); 
            CGContextTranslateCTM(context, 0, -(bounds.origin.y + bounds.size.height)); 
            CTFrameDraw(frame, context);
            CGContextRestoreGState(context); 
            CFRelease(frame);       
        }
    
        UIGraphicsEndPDFContext();
    
        [fileMetaData release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Has anyone already tried this, anything particulair that I need to be aware of?
Has anyone tried installing SQL Server 2008 Developer on a machine that already has
Has anyone run into this error message before when using a timer on an
Has anyone encountered this oddity? I'm checking for the existence of a number of
Has anyone used the lockfile utility that ships with procmail in conjunction with NFS
Has anyone ever set up Cruise Control to build an OS X Cocoa/Objective-C project?
Has anyone looked at Yahoo's ASTRA ? It's fairly nifty, but I had some
Has anyone been able to get an NHibernate-based project up and running on a
Has anyone built a website with IronPython and ASP.NET. What were your experiences and
Has anyone had any success running two different web servers -- such as Apache

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.