UIGraphicsSetPDFContextURLForRect does not create an interactive region in Core Graphics PDF format

I am trying to create a rectangular region in my PDF file that will display in the url. A PDF file is created in an iOS application using Core Graphics routines.

In a search to find anyone with a similar problem, I found this question:

Paste hyperlink to PDF using Core Graphics on iOS

If I use the code provided in the answer to the question above, this works for me. The text is displayed and is a clickable link, but if I specify a rectangle that is much larger than the text, only the text can be clicked. Also, I changed the code a bit so that I could provide the shortcut and URL separately, and when I did this and provided an empty line, there was nothing in the rectangle that could be clicked.

However, if I use UIKit routines to create PDFs (mostly UIGraphicsBeginPDFContextToFile and descendants), then calling UIGraphicsSetPDFContextURLForRect creates a region in the resulting PDF file that can be clicked even if I don't provide any text.

Here is the method I use to create a link to a rectangle:

+ (void)rectLink:(NSString *)urlString frame:(CGRect)frameRect cropBox:(CGRect)cropBoxRect sourceContext:(CGContextRef)context
{
    UIGraphicsPushContext(context);

#ifdef OUTPUT_TEXT_LINK_OUTLINE
    CGContextSetLineWidth(context, 5.0);
    CGContextSetStrokeColorWithColor(context, [UIColor purpleColor].CGColor);
    CGContextStrokeRect(context, frameRect);
#endif

    NSURL *url = [NSURL URLWithString:urlString];
    UIGraphicsSetPDFContextURLForRect(url, frameRect);

    UIGraphicsPopContext();
}

( OUTPUT_TEXT_LINK_OUTLINE - , , , , , , .)

, PDF:

[self rectLink:@"http://stackoverflow.com" frame:CGRectMake(474,22,28,28) cropBox:cropBoxRect sourceContext:context];

cropBoxRect , - , CGPDFContextCreateWithURL .

+4
1

pdf API-, Apple PDFKit cocoa -touch,
- " " pdf, PDF 1.7.
- pdf, / Annots , /Annots
- / xref .
- ..
PDF.

+2

All Articles