mupdf-rs icon indicating copy to clipboard operation
mupdf-rs copied to clipboard

[Bug] Page number is always `0` in `Document`'s `outlines()` method

Open LazyGeniusMan opened this issue 2 years ago • 1 comments
trafficstars

I'm trying to get table of content data of epub files with this code:

fn main() {
    use mupdf::{Document, Outline};

    let doc: Document = Document::open("C:\\Users\\LazyGeniusMan\\Downloads\\mupdf\\test.epub").unwrap();
    let toc: Vec<Outline> = doc.outlines().unwrap();
    for i in toc {
        println!("{:#?}", i)
    }
}

but the output of the page is always 0 like this:

Outline {
    title: "Cover",     
    uri: None,
    page: Some(
        0,
    ),
    down: [],
    x: 0.0,
    y: 0.0,
},
...
Outline {
    title: "5 Centimeters per Second",
    uri: None,
    page: Some(
        0,
    ),
    down: [
        Outline {
            title: "Chapter One: Tale of Cherry Blossoms",
            uri: None,
            page: Some(
                0,
            ),
            down: [],
            x: 0.0,
            y: 0.0,
        }
        ...
...
}

But when I try using PyMuPDF in python with this code:

import fitz

doc = fitz.Document('C:\\Users\\LazyGeniusMan\\Downloads\\mupdf\\test.epub')
toc = doc.get_toc()
for i in toc:
    print(i)

it can show the correct page number index with format [level, title, page number] like this:

[1, 'Cover', 1]
[1, 'Title Page', 2]
[1, 'Copyright', 3]
[1, 'Table of Contents', 5]
[1, '5 Centimeters per Second', 7]
[2, 'Chapter One: Tale of Cherry Blossoms', 8]
[2, 'Chapter Two: Cosmonaut', 28]
[2, 'Chapter Three: 5 Centimeters per Second', 50]
[2, 'Afterword', 79]
[2, 'Essay', 81]
[1, 'Children Who Chase Lost Voices', 84]
[2, 'Chapter One', 85]
[2, 'Chapter Two', 91]
[2, 'Chapter Three', 98]
[2, 'Chapter Four', 101]
[2, 'Chapter Five', 116]
[2, 'Chapter Six', 124]
[2, 'Chapter Seven', 131]
[2, 'Chapter Eight', 140]
[2, 'Chapter Nine', 144]
[2, 'Chapter Ten', 150]
[2, 'Chapter Eleven', 157]
[2, 'Chapter Twelve', 160]
[2, 'Chapter Thirteen', 169]
[2, 'Afterword', 172]
[1, 'Yen Newsletter', 174]

LazyGeniusMan avatar May 19 '23 00:05 LazyGeniusMan

Sorry, this project is not actively maintained at the moment, but I'm happy to accept pull requests to fix this if anyone is up for it.

messense avatar May 19 '23 02:05 messense