【问题标题】:How to stop a PDFNet Action from executing?如何阻止 PDFNet 操作执行?
【发布时间】:2014-08-25 14:31:45
【问题描述】:

基本上,我正在尝试拦截对远程文件链接的点击,而是打开我已经存储的本地版本。

我能够在点击链接后执行该链接的操作,但我不知道如何在保持 URL 不变的同时阻止它执行默认行为。

以下是相关代码:

- (void)pdfScrollViewTap:(UITapGestureRecognizer *)gestureRecognizer
{

Annot *annotation;

@try {
    // If they are clicking an annotation, we don't want to process this
    [self.pdfView DocLockRead];
    CGPoint down = [gestureRecognizer locationInView:self.pdfView];
    annotation = [self.pdfView GetAnnotationAt:down.x y:down.y];
}
@catch (NSException *exception) {
    // something is wrong with the annotation, it may not be selected properly
}
@finally {
    [self.pdfView DocUnlockRead];
}

// This is how we find out a Link was tapped
if ([annotation IsValid]) {
    if (annotation.GetType == e_Link) { // Its a link
        Link *link = [[Link alloc] initWithAnn:annotation]; // here's the link
        Action *action = link.GetAction; // links have an action, heres that
        if ([action IsValid]) { // hopefully its valid
            if (action.GetType == e_URI) { // URI is the URL the link points to
                if ([self.delegate respondsToSelector:@selector(shouldOpenURLforLinkAnnotation:withViewController:)]) { // Check if the delegate implements this
                    NSString *origURL = [action.GetSDFObj FindObj:@"URI"].GetAsPDFText;
                    if (![self.delegate shouldOpenURLforLinkAnnotation:origURL withViewController:self]) {
                        // The delegate handles finding and opening the local file

                        // Find a away to disable or stop the action here

                    }
                }
            }
        }
    }
    return;
}
}

我试过简单地删除操作:

[link RemoveAction];

这是第一次工作,但正如预期的那样,该操作在删除后再也不会被调用。

【问题讨论】:

    标签: ios objective-c pdftron pdfnet


    【解决方案1】:

    链接操作由工具代码执行,它实现了所有用户交互功能,例如文本选择、表单填充、注释创建/编辑和链接跟踪。要自定义链接处理行为,您应该在 /Lib/src/PDFViewCtrlTools/Tools 中修改 AnnotEditTool.m 的源代码并编译 libTools.a 的新副本,相关代码部分是

    else if( actionType == e_URI )
    {
        Obj* sdfObj = [action GetSDFObj];
        Obj* uriObj = [sdfObj FindObj:@"URI"];
    
        if( uriObj != Nil )
        {
            NSString* uriDestination = [uriObj GetAsPDFText];
    
            // appends http if no scheme is present
            uriDestination = [Link GetNormalizedUrl:uriDestination];
    
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.4 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
                [[UIApplication sharedApplication] openURL:[NSURL URLWithString: uriDestination]];
            });
    
    
    
    
            return YES;
        }
    }
    

    你会想做除openURL:以外的事情

    【讨论】:

    • 完美!我没有意识到这是实施它的地方。谢谢。
    • 我收到运行时构建错误。架构 armv7 的未定义符号:“_OBJC_CLASS_$_DraggableCollectionViewFlowLayout”,引用自:libTools.a(ThumbnailsViewController.o) ld 中的 objc-class-ref:未找到架构 armv7 的符号。为此,我竭尽全力将PDFNet 插件集成到我的phonegap 项目中。请帮助我,谢谢:)
    • 您需要将 Lib/src/PDFViewCtrlTools/ThirdParty/DraggableCollectionView/ 中的文件包含到您的项目中。
    • @James 我尝试了您的解决方案,但它不起作用。你有什么建议吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多