gpt4 book ai didi

objective-c - 以编程方式在 PDF 文件中创建链接

转载 作者:行者123 更新时间:2023-12-04 18:23:55 25 4
gpt4 key购买 nike

虽然我认为这是一个基本问题,但我还没有找到有效的答案。我正在通过抚摸 PDF 上下文的路径来创建 PDF 文件,并且我希望绘图上的不同区域成为外部内容的超链接 (http://bla.bla)。即使是不相交的矩形区域,我也会很高兴。有谁知道该怎么做?

最佳答案

检查这个问题的答案是否有效:Embed hyperlink in PDF using Core Graphics on iOS .

- (void) drawTextLink:(NSString *) text inFrame:(CGRect) frameRect {
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform ctm = CGContextGetCTM(context);

// Translate the origin to the bottom left.
// Notice that 842 is the size of the PDF page.
CGAffineTransformTranslate(ctm, 0.0, 842);

// Flip the handedness of the coordinate system back to right handed.
CGAffineTransformScale(ctm, 1.0, -1.0);

// Convert the update rectangle to the new coordiante system.
CGRect xformRect = CGRectApplyAffineTransform(frameRect, ctm);

NSURL *url = [NSURL URLWithString:text];
UIGraphicsSetPDFContextURLForRect( url, xformRect );

CGContextSaveGState(context);
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:frameRect];

CGContextRestoreGState(context);
}

关于objective-c - 以编程方式在 PDF 文件中创建链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10132238/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com