Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS: Generate PDF from UIView makes text blurry
    text
    copied!<h1>Generate PDF from UIView by rendering looses quality iOS</h1> <p>I have a custom UIView called <code>TTT_WantsToBeRazorSharpView</code>. This view does nothing, but draw a text with</p> <pre><code>NSString*txtPleaseHelp = NSLocalizedString(@"Hello, am I blurry again?",@""); CGContextShowTextAtPoint(ctx, 10, 50, [txtPleaseHelp cStringUsingEncoding:NSMacOSRomanStringEncoding], [txtPleaseHelp length]); </code></pre> <p>Now the View is drawn three times to an <code>UIViewController</code> (one time in <code>IB</code>) and two times in code with these lines (compare to image below):</p> <pre><code> TTT_WantsToBeRazorSharpView *customViewSharp = [[TTT_WantsToBeRazorSharpView alloc] initWithFrame:CGRectMake(10,250, 300, 80)]; [self.view addSubview:customViewSharp]; TTT_WantsToBeRazorSharpView *customViewBlurryButIKnowWhy = [[TTT_WantsToBeRazorSharpView alloc] initWithFrame:CGRectMake(361.5, 251.5, 301.5, 80.5)]; [self.view addSubview:customViewBlurryButIKnowWhy]; </code></pre> <p>the first code drawn view is razorsharp, while the second isn't, but that is ok, because of rect's comma values (361.5, 251.5, 301.5, 80.5).</p> <p>See this picture: <img src="https://i.stack.imgur.com/amisq.png" alt="See this picture"></p> <p>But my problem is now, if I render the view into an pdf document it is blurry! And don't know why, see here: <img src="https://i.stack.imgur.com/cwS95.png" alt="blurry pdf"></p> <p>and the PDF file itself Test.pdf <a href="https://raw.github.com/florianbachmann/GeneratePDFfromUIViewButDontWantToLooseQuality/master/Test.pdf" rel="nofollow noreferrer">https://raw.github.com/florianbachmann/GeneratePDFfromUIViewButDontWantToLooseQuality/master/Test.pdf</a></p> <p>and the lines to render the view into the pdf:</p> <pre><code>//this is blurry, but why? it can't be the comma coordinates CGRect customFrame1 = CGRectMake(10,50, 300, 80); TTT_WantsToBeRazorSharpView *customViewSharp = [[TTT_WantsToBeRazorSharpView alloc] initWithFrame:customFrame1]; CGContextSaveGState(context); CGContextSetTextMatrix(context, CGAffineTransformIdentity); CGContextTranslateCTM(context, (int)customFrame1.origin.x, (int)customFrame1.origin.y); [customViewSharp.layer renderInContext:context]; CGContextRestoreGState(context); </code></pre> <p><strong>So why is the <code>renderInContext:context</code> text blurry?</strong></p> <p>I appreciate all your hints and help, I even made an GitHub project for the brave of you (with source): <a href="https://github.com/florianbachmann/GeneratePDFfromUIViewButDontWantToLooseQuality" rel="nofollow noreferrer">https://github.com/florianbachmann/GeneratePDFfromUIViewButDontWantToLooseQuality</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload