Skip to content

Commit

Permalink
feat(outlines): delete outlines
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-Sky committed Jul 4, 2024
1 parent 4cca7dc commit e4ba5be
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/pdf/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,34 @@ impl PdfDocument {
}
Ok(())
}

/// Delete `/Outlines` in document catalog and all the **outline items** it points to.
///
/// Do nothing if document has no outlines.
pub fn delete_outlines(&mut self) -> Result<(), Error> {
if let Some(outlines) = self.catalog()?.get_dict("Outlines")? {
if let Some(outline) = outlines.get_dict("First")? {
self.walk_outlines_del(outline)?;
}
self.delete_object(outlines.as_indirect()?)?;
}

Ok(())
}

fn walk_outlines_del(&mut self, outline: PdfObject) -> Result<(), Error> {
let mut cur = Some(outline);

while let Some(item) = cur.take() {
if let Some(down) = item.get_dict("First")? {
self.walk_outlines_del(down)?;
}
cur = item.get_dict("Next")?;
self.delete_object(item.as_indirect()?)?;
}

Ok(())
}
}

impl Deref for PdfDocument {
Expand Down

0 comments on commit e4ba5be

Please sign in to comment.