Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating Multipage PDF File using CoreGraphics shows error on console

I am having a problem in creating the multi page PDF. I am using NSMutableData for storing the PDF data. When I am drawing a new page using the following code

CGContextSetRGBFillColor(context, 0.0, 0.0, 0.0, 1.0);
**    Error Line   **

UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 595, 841), nil);

[self drawPageAtIndex:self.numberOfPages+1 inRect:CGRectMake(0, 0, pageWidth, pageHeight)];
[self drawBorder];//draws Border to the page

It shows me following error on console

<Error>: replacing +/-infinity with -2147483648.
<Error>: replacing +/-infinity with 2147483647.
<Error>: replacing +/-infinity with -2147483648.
<Error>: replacing +/-infinity with 2147483647.
<Error>: replacing +/-infinity with -2147483648.
<Error>: replacing +/-infinity with 2147483647.
<Error>: replacing +/-infinity with -2147483648.
<Error>: replacing +/-infinity with 2147483647.

Please can someone help me to resolve the error.

Here is the link which i reffered previously for the same error

it says that core graphics logs are getting confusing values but i am not getting a resolution on the error Thank You.

like image 859
Shaniraaj Avatar asked Sep 26 '16 05:09

Shaniraaj


1 Answers

I could reproduce the error and apparently fix it. I have an app on the App Store since 2013. The app creates some PDF files and the error showed for the first time in iOS 10.

I traced it to this snippet


    NSString* pgStr = [some text];        
    UIFont* theFont = [some font];

    NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
    paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping;
    paragraphStyle.alignment = NSTextAlignmentCenter;

    NSDictionary * attributes = @{NSFontAttributeName:theFont, NSParagraphStyleAttributeName:paragraphStyle
                                          };

    // ERROR        
    [pgStr drawInRect:[some frame] withAttributes:attributes];

To fix it, introduce line heights to the paragraph style:


    paragraphStyle.minimumLineHeight = theFont.pointSize;
    paragraphStyle.maximumLineHeight = theFont.pointSize;

like image 125
SuanMei Avatar answered Nov 14 '22 23:11

SuanMei