Looking for how to use UIGraphicsSetPDFContextURLForRect on iOS or Cocoa

I play to manipulate PDF on iOS (display, but also mostly generation).

I want to embed rectangular areas that act as "external" links (URLs such as http: //host.tld/path/file ).

Do you know where I can find example (s) how to use the UIGraphicsSetPDFContextURLForRect function? I find absolutely nothing on the Internet.

If I understand well, the only requirement is that the current graphic context should be a “type” of PDF, and I think I respect it, because, as I stream, I call UIGraphicsPushContext, why is my PDF context as a parameter (this is in anyway required for methods like drawAtPoint: which I use with success as well).

I do not think this is important, but just in case, I point out that this is NOT done in the drawRect: subclass of View.

You are absolutely right to tell me unconditionally that I have "everything is wrong." The graphics environment is so sophisticated and rich in iOS that I assume that it has not yet assimilated more than 1 or 2%.

Thanks in advance.

+5
source share
2 answers

, , PDF. (UIGraphicsPushContext), , :

UIGraphicsBeginPDFContextToFile(path, CGRectMake(0, 0, 612, 792), nil);
UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);
// ...
UIGraphicsSetPDFContextURLForRect(url, rect);
// ... 
UIGraphicsEndPDFContext(); 

UIGraphicsSetPDFContextURLForRect 2 : -, URL-, , , - , . , url , 72 * 72 :

UIGraphicsSetPDFContextURLForRect(url, CGRectMake(0, 0, 72, 72));

PDF. , , , , PDF . - / - (, ), .

- :

- (void) makePdf {
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pdfFile = [documentsDirectory stringByAppendingPathComponent:@"uigraphics.pdf"];

    UIGraphicsBeginPDFContextToFile(pdfFile, CGRectMake(0, 0, 612, 792), nil);
    UIGraphicsBeginPDFPageWithInfo(CGRectMake(0, 0, 612, 792), nil);

    NSURL* url = [NSURL URLWithString: @"http://www.ipdfdev.com/"];
    UIGraphicsSetPDFContextURLForRect(url, CGRectMake(0, 0, 50, 50));

    UIGraphicsEndPDFContext();
}
+5

, .

UIGraphicsBeginPDFContextToFile( pdfFilePath, CGRectZero, nil );

CGRect windowFrame = CGRectMake( 0, 0, 596, 842 );
UIGraphicsBeginPDFPageWithInfo( windowFrame, nil );

NSURL *url = [NSURL URLWithString:@"http://www.google.com"];

CGRect textFrame = CGRectMake( 10, 10, 200, 20 );
CGRect linkFrame = textFrame;
linkFrame.origin.y = windowFrame.size.height - linkFrame.origin.y - linkFrame.size.height;
UIGraphicsSetPDFContextURLForRect( url, linkFrame );

NSDictionary *attributesDict;
NSMutableAttributedString *attString;

NSNumber *underline = [NSNumber numberWithInt:NSUnderlineStyleSingle];
attributesDict = @{NSUnderlineStyleAttributeName : underline, NSForegroundColorAttributeName : [UIColor blueColor]};
attString = [[NSMutableAttributedString alloc] initWithString:url.absoluteString attributes:attributesDict];

[attString drawInRect:textFrame];

UIGraphicsEndPDFContext();
+4

All Articles