J-F-Liu / lopdf

A Rust library for PDF document manipulation.
MIT License
1.67k stars 176 forks source link

An invalid pdf is produced when there are many xref tables #331

Closed ardurin closed 2 months ago

ardurin commented 2 months ago

Crate version: 0.34.0

When reading and saving a pdf with two xref tables, the tables are merged into one but /Prev is not removed from the trailer.

Use this code to replicate:

fn main() {
    let mut document = lopdf::Document::load("in.pdf").unwrap();
    document.save("out.pdf").unwrap();
}

Use this as in.pdf

qpdf --check out.pdf and exiftool out.pdf report the resulting file as malformed.