Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

idelovski

macrumors regular
Original poster
Sep 11, 2008
235
0
I have trouble using UIGraphicsSetPDFContextURLForRect() function. In what coordinate system is this rect positioned. I have tried to play with the context and its ctm but nothing seem to work.

This code produces text at the bottom of the page and the url link at the very top of the pdf document page.

Code:
- (NSData *)pdfDataByDrawingDocument
{
    CGRect  docFrame = CGRectMake (0., 0., 512., 740.);
    CGRect  fldFrame = CGRectMake (0., docFrame.size.height-30., docFrame.size.width, 30.);
    
    // set up PDF rendering context
    NSMutableData  *pdfData = [NSMutableData data];
    
    UIGraphicsBeginPDFContextToData (pdfData, docFrame, nil);
    
    UIGraphicsBeginPDFPage ();
        
    UIGraphicsSetPDFContextURLForRect ([NSURL URLWithString:@"https://www.macrumors.com"], fldFrame);
        
    [@"Hello macrumors!" drawInRect:fldFrame
                           withFont:[UIFont systemFontOfSize:20.]
                      lineBreakMode:UILineBreakModeWordWrap
                          alignment:NSTextAlignmentCenter];
    
    UIGraphicsEndPDFContext ();  // remove PDF rendering context
    
    return (pdfData);
}

What should I do to have the text and the url at the same place?
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.