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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:54:15+00:00 2026-05-28T17:54:15+00:00

I have an iPad app and I’m trying to generate a PDF from a

  • 0

I have an iPad app and I’m trying to generate a PDF from a UIView and it’s almost working perfectly.

The code is really simple as follows:

UIGraphicsBeginPDFContextToFile( filename, bounds, nil );
UIGraphicsBeginPDFPage();
CGContextRef pdfContext = UIGraphicsGetCurrentContext();
[view.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();

This works really well with one weird exception. If the view has been on screen before being rendered to PDF then the UILabels on the view are rendered to the PDF as wonderful vectors. If the view has not yet been on the screen (IE the controller was initWithNib etc but hasn’t been pushed into a navigation controller or anything) then the text is rendered as a bitmap at ‘ipad’ resolution.

It’s like the act of getting rendered to the screen sets up the view to be rendered as vectors when I subsequently render it to a pdf context.

Is there some method I can call or property I can set on the view or the layer or elsewhere to mimic this behaviour without having to show the view on screen?

Is it something to do with UIViewPrintFormatter?

  • 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-28T17:54:16+00:00Added an answer on May 28, 2026 at 5:54 pm

    The only way I found to make it so labels are rendered vectorized is to use a subclass of UILabel with the following method:

    /** Overriding this CALayer delegate method is the magic that allows us to draw a vector version of the label into the layer instead of the default unscalable ugly bitmap */
    - (void)drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx {
        BOOL isPDF = !CGRectIsEmpty(UIGraphicsGetPDFContextBounds());
        if (!layer.shouldRasterize && isPDF)
            [self drawRect:self.bounds]; // draw unrasterized
        else
            [super drawLayer:layer inContext:ctx];
    }
    

    Swift 5.x:

    override func draw(_ layer: CALayer, in ctx: CGContext) {
        let isPDF = !UIGraphicsGetPDFContextBounds().isEmpty
    
        if !self.layer.shouldRasterize && isPDF {
            self.draw(self.bounds)
        } else {
            super.draw(layer, in: ctx)
        }
    }
    

    That does the trick for me: labels are unrasterized and selectable in the resulting PDF view, and behave normally when rendered to the screen.

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

Sidebar

Related Questions

I have set my iPad app to Landscape mode using following code.. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Ok I have a basic iPad app that asks for 5 search/filter criteria from
I have an iPad app and I'm trying to call a stored procedure in
Possible Duplicate: iPhone/iPad App Code Obfuscation - Is it Possible? Worth it? I have
I have an ipad app which takes images from Photos application using ALAssetsLibrary and
I have an iPad app that is doing really well, zero crashed reported by
I have an iPad app which loads a plist from a server fine on
I have an iPad app that outputs a PDF file that needs to be
I have got an iPad app with this as part of my code: if
I have an ipad app, which displays a powerpoint presentation from an NSData, within

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.