Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
Get Total Pages Count and Current Page QuickLook

I'm using 'QLPreviewController' to show document file (pdf/doc). Is there any way to get Total number of pages and also current page number?

Or any other way to view pdf/doc and also get page counts. enter image description here

Like "9 of 9"- How to get that

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

QuickLook only for look mate. You could get metadata from CGPDFDocument

if let url = Bundle.main.url(forResource: "yourFileNameHere", withExtension: "pdf"),
        let pdf = CGPDFDocument(url as CFURL) {
        let count = pdf.numberOfPages
        print(count)
    }

For docx, try install ZipZap with carthage: github "pixelglow/ZipZap" "8.1"

    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))];
    }
}

Here the source for metadata of docx: https://www.forensicswiki.org/wiki/Word_Document_(DOCX)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda