messense / mupdf-rs

Rust binding to mupdf
GNU Affero General Public License v3.0
96 stars 21 forks source link

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

Open LazyGeniusMan opened 1 year ago

LazyGeniusMan commented 1 year ago

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]
messense commented 1 year ago

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.