Skip to content

Provide memory-safe options for moving PdfPageObjects from one PdfPage to another. #60

@N3xed

Description

@N3xed

Hi there.

I've been trying hard to get moving objects from one page to another to work, without success.

On the one hand, using PdfPageObjects::remove_object gives borrow checker errors because getting a PdfPage object borrows PdfPageObjectsimmutable and then you can't borrow the samePdfPageObjectsmutably to call theremove_object` function.

I've also tried it with good old index access and with that I can remove them fine, but re-adding them to another PdfPage produces segfaults.

For example:

        let mut objs = page.objects();
        let new_objs = new_page.objects_mut();
        let mut i = 0;
        while i < objs.len() {
            let obj = objs.get(i).map_err(PdfiumErr)?;
            let Ok(bounds) = obj.bounds() else {continue};
            if bounds.bottom >= y {
                log::debug!("item = {:?}", obj.object_type());
                new_objs.take_object_from_page(&mut page, I); // <-- segfault here
                objs = page.objects();
            } else {
                i += 1;
            }
        }

produces segfaults.

There is also the PdfPageGroupObject, but this doesn't help since calling remove_objects_from_page also deletes the objects (and somehow mirrors the source page horizontally).

So, am I doing this wrong? Is it even possible?

Either way, many thanks for your great work.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions