Ios 获取总页数和当前页面QuickLook

Ios 获取总页数和当前页面QuickLook,ios,swift,quicklook,qlpreviewcontroller,Ios,Swift,Quicklook,Qlpreviewcontroller,我正在使用“QLPreviewController”显示文档文件(pdf/doc)。 有没有办法获得总页数和当前页数 或者以任何其他方式查看pdf/doc并获取页面计数。 比如“9/9”-如何只为look mate获得快速外观。您可以从CGPDFDocument获取元数据 if let url = Bundle.main.url(forResource: "yourFileNameHere", withExtension: "pdf"), let pdf = CGPDFDocu

我正在使用“QLPreviewController”显示文档文件(pdf/doc)。 有没有办法获得总页数和当前页数

或者以任何其他方式查看pdf/doc并获取页面计数。


比如“9/9”-如何只为look mate获得快速外观。您可以从CGPDFDocument获取元数据

if let url = Bundle.main.url(forResource: "yourFileNameHere", withExtension: "pdf"),
        let pdf = CGPDFDocument(url as CFURL) {
        let count = pdf.numberOfPages
        print(count)
    }
对于docx,请尝试使用迦太基安装ZipZap:
github“pixelglow/ZipZap”“8.1”

NSURL*url=[[NSBundle mainBundle]URLForResource:@“demo”带扩展名:@“docx”];
ZZArchive*archive=[ZZArchive archiveWithURL:url错误:nil];
NSString*页面计数;
用于(ZZArchiveEntry*archive.entries中的条目){
if([entry.fileName IsequalString:@“docProps/app.xml”]){
NSString*responseString=[[NSString alloc]initWithData:
[entry newDataWithError:nil]编码:NSUTF8StringEncoding];
//获取标记和之间的值
NSRange tag1=[responseString rangeOfString:@”“;
NSRange tag2=[responseString rangeOfString:@”“;
pageCount=[responseString substringWithRange:
NSMakeRange((tag1.location+tag1.length),(tag2.location-tag1.length-tag1.location));
}
}

这里是docx元数据的来源:

“HP Smart”应用程序确实如此。它们显示页面计数。必须有某种方法来获取.docx页面计数。只需使用docx更新即可。Objc中的代码,因为不确定为什么SwiftThank中缺少一些API。但通过这种方式,我不知道用户当前在哪个页面上。就像在QuickLook中,它如何显示在左上角“9个中的2个”。@Nitesh-它如何显示在左上角“9个中的2个”。答:苹果没有提供任何与此相关的公共api,如果您想要“9中的2”,请使用UIwebview而不是QuickLook@Anbu.Karthik在UIWebview中,我可以获取它吗?现在quicklook只支持PDF页面突出显示,对于其他类型,如doc或docx,它不支持分页和当前页面计数应用程序。@CodeChanger On“docx”文件太多,我得到页面突出显示。此外,我打开docx/pdf n的任何其他方式也可以获得页面突出显示。当我在iPhone上的最新操作系统上检查它时,您使用的是哪个IOS版本,而它没有显示当前页面“Heighleer”。@CodeChanger是的,您是正确的。那我还有别的办法吗?除了在“QuickLook”中查看文件外,您还想在文档文件中仅显示计数和当前页面,还是显示当前页面和总页面?
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"demo" withExtension:@"docx"];
    ZZArchive* archive = [ZZArchive archiveWithURL:url error:nil];
    NSString *pageCount;
    for (ZZArchiveEntry* entry in archive.entries) {
    if([entry.fileName isEqualToString:@"docProps/app.xml"]) {
        NSString *responseString = [[NSString alloc] initWithData: 
        [entry newDataWithError:nil] encoding:NSUTF8StringEncoding];
        //Get the value between tag <Pages> and </Pages>
        NSRange tag1 = [responseString rangeOfString:@"<Pages>"];
        NSRange tag2 = [responseString rangeOfString:@"</Pages>"];
        pageCount = [responseString substringWithRange: 
        NSMakeRange((tag1.location + tag1.length), (tag2.location - tag1.length - tag1.location))];
    }
}